Thanks,
that was exactly what I was trying to do but failed in the
previewDialogClose. But now I see why ! I misread the signature of the
previewDialogClose, i.e. that it had the same parameter as the
dialogClosed and therefore misread the boolean as "modal" instead of
"result". I was trying to do a getResult() on the dialog in
previewDialogClose but that values is always false, regardless of the
result.
Now it works like a charm.
Cheers,
Tomas
On 09/26/2011 05:46 AM, Roger and Beth Whitcomb wrote:
Hi Tomas,
The right way to do this would be as follows:
- For your OK and Cancel buttons, attach a ButtonPressListener, and in
that code do this:
@Override
public void buttonPressed(Button button) {
if (button == okButton) {
dialog.close(true);
}
else if (button == cancelButton) {
dialog.close(false);
}
}
- Then implement a DialogStateListener (or extend
DialogStateListener.Adapter) and connect it to your dialog. In this
listener do the following:
@Override
public Vote previewDialogClose(Dialog dialog, boolean result) {
// Closing on Escape or "Cancel" is always okay
if (!result)
return Vote.APPROVE;
// If fields don't look right, deny the close
if (!verifyFields())
return Vote.DENY;
// Everything is kosher then approve the close
return Vote.APPROVE;
}
~Roger Whitcomb
On 9/25/11 11:53 AM, Tomas Stenlund wrote:
Hi,
I'm after a design/code pattern for handling ENTER and ESC for
dialogs (modal) as well as PushButtons performing the same function.
When I press ENTER or ESC the dialog is closed and I can find out in
the DialogStateListener which one was pressed (true,false) which I
guess is the default behaviour of pivot. I use this to see if I
should "commit" or "rollback" the changes in the dialog or not ( I
use Cayenne ORM). I also have pushbuttons in the dialog that will
yield the same functionality, i.e. close the dialog and send a
true/false result. In this way I handle both ENTER, ESC and the
pusbuttons the same way without having to listen to any keystrokes etc.
Now to my question, I was thinking of vetoing the close if the values
in controls in the dialog are not correct. But I cannot determine if
it is ENTER, ESCAPE or the pushbuttons that caused the "close" in the
"veto" method in the listener. I need to know that because if
Cancel-pushbutton or ESC was pressed I will never veto the close.
Hmm i'm a little unstructured here, but how do you go about doing
this i.e. handling the keyboard ENTER, ESC as well as pushbuttons
that does the same functionality ? Am I going about this in the wrong
way, i.e. how to handle ENTER, ESC to make them perform the same
Thanks for any help,
Tomas