Wicket 6 modal window parent page update - modal-dialog

I have two modal window scenarios that worked with Wicket 1.4 but no longer work with Wicket 6.
Case 1
Modal1 inserts an item into list on parent page, then closes.
Callback on parent page refreshes the list using target.add(container)
I can see that the callback is firing but the refresh no longer has any effect.
modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback(){
#Override
public void onClose(AjaxRequestTarget target) {
logger.info("Running Modal1 closed callback... ");
logger.info("AjaxRequestTarget: " + target.getPageClass().getName());
target.add(sampleListView);
modal.close(target);
}
});
Case 2
Parent page defines two modal windows.
Callback for Modal2 launches Modal1.
I can see that the callback is firing but Modal2 is no longer launching.
modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback(){
#Override
public void onClose(AjaxRequestTarget target) {
logger.info("Running Modal2 closed callback... ");
logger.info("AjaxRequestTarget: " + target.getPageClass().getName());
if (originalSample != null){
logger.info("originalSample is not null");
...do some stuff...
modal1.show(target);
}else{
modal.close(target);
}
}
});
I can't figure out why this no longer works. Any advice would be appreciated!

Related

JavaFX: Capture screen focused event

Is there a way to capture the event when a stage or screen gets focus? I tried to use focusedProperty but I guess that is used only when initially the stage/screen gets shown.
I am not sure if essentially I have to capture, WindowEvent.WINDOW_SHOWN event. I did try the following piece of code in my application, but there is probably a mistake.
stage.addEventFilter(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>()
{
#Override
public void handle(WindowEvent window)
{
System.out.println("EventFilter :: Window shown");
}
});
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>()
{
#Override
public void handle(WindowEvent window)
{
System.out.println("EventHandler :: Window shown");
}
});
None of the sysouts is shown when I execute the program.
Another part to the same problem is whether the event handler would get triggered if lets say I minimize and maximize the application(i.e the application again got focus) or I lock my machine and unlock it?

Hide Dialog from inside in LWUIT

I have created a Dialog with two buttons Yes, No, and then I have add action listener to them, my problem is that I want no button to hide the Dialog that I have created
the code is looks like:
dialog = new Dialog(title);
dialog.setDialogType(Dialog.TYPE_CONFIRMATION);
ta = new TextArea(text);
ta.getStyle().setBorder(Border.createEmpty());
ta.setEditable(false);
yesCommand = new Button("YES");
noCommand = new Button("NO");
yesCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
LGBMainMidlet.getLGBMidlet().notifyDestroyed();
}
});
noCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Logger.Log("Bye Bye");
dialog = null;
System.gc();
}
});
dialog.addComponent(ta);
dialog.addComponent(yesCommand);
dialog.addComponent(noCommand);
dialog.show();
the code is not working for me, can anyone told me what is the problem?
B.N. I have used dialog.dispose(), but it exit the whole application
It is better to use
dialog.setTimeout(1000); the number show the time limit the dialog box wait in milliseconds. So by doing this you can exit the dialog form automatically.
Dialog.dispose() does not exit the whole application, it just closes the dialog.
If you have nothing in your application you might see nothing if you dispose the dialog.

Block gwt DisclosurePanel on open state

How may I block a gwt DisclosurePanel on the open state ?
I mean, how can I prevent this DisclosurePanel to close if the user click the header more than once ?
(My header is a textBox, I want the user to enter a text, and the panel should remain open if the user unfocus the textBox and focus newly by clicking it. The DisclosurePanel content has a "cancel" button that closes the panel)
Thank you very much.
I edit my question after 2 first answers: I would like to avoid to reopen the DisclosurePanel once closed to avoid flashing effect. I actually want to prevent the DisclosurePanel to close. Maybe sinkEvents can help me... if so, how? Thanks.
A NativePreviewHandler receives all events before they are fired to their handlers. By registering a nativePreviewHandler the first time your disclosurePanel is opened, you can cancel the click event. You can later decide to remove this handler by preventClose.removeHandler();
HandlerRegistration preventClose = null;
....
panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (preventClose == null){
preventClose = Event.addNativePreviewHandler(new NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt()==Event.ONCLICK && event.getNativeEvent().getEventTarget() == panel.getHeader().getElement().cast())
event.cancel();
}
});
}
}
});
The obvious answer is review the javadoc here: https://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/DisclosurePanel.html
There is a setOpen() method that: Changes the visible state of this DisclosurePanel.
Set it to false from a click event to capture the user action.
The JavaDoc is right here: https://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/DisclosurePanel.html
jamesDrinkard pointed the old 1.5 javadoc.
You can use the addCloseHandler(CloseHandler<DisclosurePanel> handler) method to add a handler so when the user tries to close it you can reopen it again with setOpen().
Maybe not the best way, but it worked for me (maybe just one of both will work too):
dPanel.setOpen(true);
dPanel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});
dPanel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
#Override
public void onClose(CloseEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});

How to add a close button to the caption bar of a GWT DialogBox [duplicate]

This question already has answers here:
GWT Close button in title bar of DialogBox
(14 answers)
Closed 10 years ago.
I need to add a close button to the caption bar of my dialog box . I'm able to place a widget in the caption bar , but not been able to get the events for it .
http://zone817.blogspot.com/2010/08/close-button-in-caption-bar-of-gwt.html
seems like exactly what you want.
Here is a modification of the example given by amal. This code retains gwt-DialogBox caption style.
public class CloseButtonDialogBox extends DialogBox {
private Node closeEventTarget = null;
public CloseButtonDialogBox() {
// get the "dialogTopRight" class td
Element dialogTopRight = getCellElement(0, 2);
// close button image html
dialogTopRight.setInnerHTML(
"<div style=\"margin-left:-25px;margin-top: 7px;\">" +
"<img src=\"images/closebutton.png\" height=\"20px\"/>" +
"</div>");
// set the event target
closeEventTarget = dialogTopRight.getChild(0).getChild(0);
}
#Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
NativeEvent nativeEvent = event.getNativeEvent();
if (!event.isCanceled()
&& (event.getTypeInt() == Event.ONCLICK)
&& isCloseEvent(nativeEvent))
{
this.hide();
}
super.onPreviewNativeEvent(event);
}
// see if the click target is the close button
private boolean isCloseEvent(NativeEvent event) {
return event.getEventTarget().equals(closeEventTarget); //compares equality of the underlying DOM elements
}
See the answer posted in the linked question.
It shows the proper way to do this by implementing the DialogBox.Caption interface and then adding an event handler to your caption implementation for the included close button that hides the dialog box.
This did the trick for me.
https://stackoverflow.com/a/7960172/458426

.Net CF Prevent Overzealous, Impatient Clicking (while screen is redrawing)

.Net Compact Framework
Scenario: User is on a screen. Device can't finds a printer and asks the user if they want to try again. If they click "No", the current screen is closed and they are returned to the parent menu screen. If they click the "No" button multiple times, the first click will be used by the No button and the next click will take effect once the screen has completed redrawing. (In effect clicking a menu item which then takes the user to another screen.)
I don't see a good place to put a wait cursor...there isn't much happening when the user clicks "No" except a form closing. But the CF framework is slow to redraw the screen.
Any ideas?
you can skip pending clicks by clearing the windows message queue with
Application.DoEvents();
We use the following custom Event class to solve your problem (preventing multiple clicks and showing a wait cursor if necessary):
using System;
using System.Windows.Forms;
public sealed class Event {
bool forwarding;
public event EventHandler Action;
void Forward (object o, EventArgs a) {
if ((Action != null) && (!forwarding)) {
forwarding = true;
Cursor cursor = Cursor.Current;
try {
Cursor.Current = Cursors.WaitCursor;
Action(o, a);
} finally {
Cursor.Current = cursor;
Application.DoEvents();
forwarding = false;
}
}
}
public EventHandler Handler {
get {
return new EventHandler(Forward);
}
}
}
You can verify that it works with the following example (Console outputs click only if HandleClick has terminated):
using System;
using System.Threading;
using System.Windows.Forms;
class Program {
static void HandleClick (object o, EventArgs a) {
Console.WriteLine("Click");
Thread.Sleep(1000);
}
static void Main () {
Form f = new Form();
Button b = new Button();
//b.Click += new EventHandler(HandleClick);
Event e = new Event();
e.Action += new EventHandler(HandleClick);
b.Click += e.Handler;
f.Controls.Add(b);
Application.Run(f);
}
}
To reproduce your problem change the above code as follows (Console outputs all clicks, with a delay):
b.Click += new EventHandler(HandleClick);
//Event e = new Event();
//e.Action += new EventHandler(HandleClick);
//b.Click += e.Handler;
The Event class can be used for every control exposing EventHandler events (Button, MenuItem, ListView, ...).
Regards,
tamberg
Random thoughts:
Disable the some of the controls on the parent dialog while a modal dialog is up. I do not believe that you can disable the entire form since it is the parent of the modal dialog.
Alternatively I would suggest using a Transparent control to catch the clicks but transparency is not supported on CF.
How many controls are on the parent dialog? I have not found CF.Net that slow in updating. Is there any chance that the dialog is overloaded and could be custom drawn faster that with sub controls?
override the DialogResult property and the Dispose method of the class to handle adding/remvoing a wait cursor.