pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roger and Beth Whitcomb <RogerandB...@rbwhitcomb.com>
Subject Re: Handling dialog ENTER & ESC
Date Mon, 26 Sep 2011 03:46:58 GMT
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:
     public void buttonPressed(Button button) {
	if (button == okButton) {
	else if (button == cancelButton) {
- Then implement a DialogStateListener (or extend DialogStateListener.Adapter) and connect
it to your dialog.  In this listener do the following:
     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

View raw message