customize window closing event message in IE? - gwt

i am using GWT. on window close we get browser provided message" Are you sure you want to navigate away from this page?". i want to replace the message with my own message. please help me. below is my code.
Window.addWindowClosingHandler(new Window.ClosingHandler() {
#Override
public void onWindowClosing(final Window.ClosingEvent closingEvent) {
closingEvent.setMessage("some message.");
}
});

you can not modify the dialog that is opened if you provide a string in the closing event.
The dialog is handled by the browser and can not be customized.

Related

Recognize browser close in wicket

Is there a reliable way to detect the closing of the browser tab or window on the server side in a wicket application?
It must work under firefox version 68.11.0 or higher. I use wicket 8.8.0.
I tried it with websockets and catching the connection close event. But unfortunately this event is also raised when a page is refreshed (F5).
new WebSocketBehavior() {
#Override
protected void onClose(ClosedMessage message) { // invoked on tab close, window close and unfortunately on page reload
super.onClose(message);
log.info("Connection for page = '{}' closed.", message.getKey());
}
}
From browser point of view there is no difference between closing the tab and refreshing the tab. In both cases the browser fires beforeunload JavaScript event and closes all open connections (WebSocket, ServerSideEvent, Ajax).
So, you can use
page.add(new AjaxEventBehavior("beforeunload") {
#Override public void onEvent(AjaxRequestTarget target) {...}
});
but this just tell you that the user navigates away from the current page. There is no info what comes next.

how to dianmically add dialog to webpage in wicket?

I have write my own dialog and on my Index page have a AjaxLink
when AjaxLink is clicked. I will behave to open my dialog instance.
this is my code
add(new AjaxLink("open.working.date.dialog") {
#Override
public void onClick(AjaxRequestTarget target) {
WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
Index.this.add(dialog);
dialog.open(target);
}
});
of course, on my web page html markup I don't have reference component id working.date.dialog and it will throw exception.
but when I replace Index.this.add(dialog); by this.add(dialog); or by target.add(dialog); the dialog won't work.
There any other way to add dynamically dialog to page?
In jquery I can do that easily by just append dialog html to body then open it by jquery.
thanks for your all helpful!
One option is to add the dialog in the constructor of the page and hide it initially. Then later when clicking the link just mark it as visible and add it to the AjaxRequestTarget.
Another option is to add a dummy/empty WebMarkupContainer with the same component id and later replace it with the dialog in #onClick().
You are going against the wicket way of doing things here, which will cause you much pain. :-) First of all WorkingDateDialog needs to extend ModalWindow. Assuming it does, here are my suggestions.
Right above your ajax link add this code:
final WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
add(dialog);
Then your ajax link becomes:
add(new AjaxLink("open.working.date.dialog") {
#Override
public void onClick(AjaxRequestTarget target) {
dialog.show(target);
}
});
So you always add your ModalWindow instance to your page hierarchy. It' just not visible until someone clicks the link.
I hope this helps you. Please let me know if you have any questions.

How to close a dialog in code?

So I'm making a eclipse plugin and I have a made my own dialog by extending the dialog class.
My dialog basically populates a treeview with data from a server. Sometimes the data cannot be populated (because the server is down) so my treeview is empty.
I have made another dialog appear reporting the error if I am unable to connect to the server.
My problem is that I would like to close the initial dialog when I press ok in the error dialog.
I have not been able to find a good way to do this.
I have tried setting setBlockOnOpen to false.
I have tried calling cancelPressed.
Neither of them have worked.
I called them in the createDialogArea function.
Any Ideas on how I could get this to work?
It is basically user cancelling dialog. you need to invoke cancelPressed() so it will be consistent handling if you have any code that depends on returnCode
if(noDataLoaded){
Display.getDefault().asyncExec(new Runnable() {
public void run() {
cancelPressed():
}
});
}
You need to do the close call after the dialog creation has finished. You can do this by using this code:
parent.getDisplay().asyncExec(new Runnable()
{
#Override
public void run()
{
close();
}
});
in your createDialogArea method. However the dialog may appear briefly. It would be better to do your check before creating the dialog.

How can I cancel the Window.ClosingEvent?

I want to show a modal window (instead the confirm) when a user close the browser. The GWT documention remarks that (during the handler operation) no user UI may be displayed during the shutdown. Exists any way cancel the operation, from the client not from the user?
Thanks in advance,
Oscar.
You can't cancel the close event. The best you can do is to let the user press cancel. I think the reason for this is to prevent "bad" javascript from not letting you close your browser.
This displays a dialog with a cancel option.
Window.addWindowCloseListener(new WindowCloseListener()
{
public String onWindowClosing()
{
return "You are about to exit from the application. Are you sure?";
}
public void onWindowClosed()
{
//cleanup code
}
});

How do I stop an Eclipse Editor from closing in an RCP

I am working on an Eclipse based RCP. We have a need to prevent one of the opened editors from being closed by the user.
The desired behavior is:
the user clicks the X in the editor window or "CTRL+W"
a dialog pops up saying: "If you close this editor, your activity will stop. Do you want to?"
if they click yes, it closes, if no, it stays open.
Oh yeah, and is this even possible?
Thanks,
gk
You could use a org.eclipse.ui.ISaveablePart2, more specifically the method promptToSaveOnClose().
However, as said in this thread,
it will only be shown if the editor is dirty at the time it is closed.
See an example in this SaveableHelper.java source file.
See also the article Prevent that a RCP Editor is closed, which explains how this method works:
You can also cancel the saving in
#Override
public void doSave(IProgressMonitor monitor) {
by calling
monitor.setCanceled(true);
In the EditorPart implementation
Not directly related but I was looking for a way to prevent an Editor to be closed and found this little hack, hope it could help.
page.addPartListener(new IPartListener2() {
// [...]
#Override
public void partClosed(IWorkbenchPartReference partRef) {
try {
page.openEditor(input, id);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});