|
Re: Detecting when a Form-in-a-View is closed [message #1416203 is a reply to message #1405049] |
Thu, 04 September 2014 15:02 |
Eclipse User |
|
|
|
Hi Urs,
you have two options to get there:
- override AbstractForm.execOnCloseRequest in your form an call doClose().
@Override
protected void execOnCloseRequest(boolean kill, HashSet<Integer> enabledButtonSystemTypes) throws ProcessingException {
doClose();
}
- override AbstractForm.getConfiguredAskIfNeedSave() and return false. If you have a look at the default implementation of AbstractForm.execOnCloseRequest you will see, that a form calls the doClose only when either a CancelButton is available or the askIfNeedSave is false.
The option 2 is to prefer.
/andreas
|
|
|
Re: Detecting when a Form-in-a-View is closed [message #1416232 is a reply to message #1416203] |
Thu, 04 September 2014 16:28 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
Hi,
We were confronted with the exact same problem. We are in a "Single Form Application" using SWT where the Forms are opened as View with menus.
The problem described by Urs is the same when the Scout form is opened as Dialog (there is also a "X" in the Title Bar of a Dialog).
I want to add some precisions:
Scout provides 3 types of buttons:
* Ok Button
* Cancel Button
* Close Button
A/ When the Form contains modifications (some developers says "Form is dirty") (*):
User clicks on:
* Ok Button: Form is saved (Method execStore() of the Form Handler is called).
* Close Button: Form is closed.
* Cancel Button: Scout presents a confirmation Box ("Do you want to change the changes?" . Yes -> do the same as OkButton. No -> do the same as close button. Cancel -> Interruption, the user is back to the form. Nothing happened). This is only the case if the property AskIfNeedSave == true (this is the default). If AskIfNeedSave is set to false, the Cancel Button is like the Close button.
B/ When the Form doesn't contain any modification:
* Ok, Close and Cancel Buttons have the same behavior: the form is close.
--------
Now my explanation of the execOnCloseRequest method:
When the user clicks on the "X" (is a View or in a Dialog) a CloseRequest is triggered. The default implementation does this (exactly in this order):
* If the Scout Form contains an enabled Close Button, the form is closed like if the user had clicked on the close button.
* If the Form contains an enabled Cancel Button, the form is closed like if the use had clicked on the Cancel button.
* Now we are in the case without button. There is a last chance to know what to do in if the Form has the property AskIfNeedSave == false. In this case Close and Cancel Buttons would have the same behavior (closing the form without asking). This is what the framework does.
If none of these conditions are met, the framework does not know what it needs to do. It logs an INFO line: "Trying to close a form XY with no enabled close button..."
You should override execOnCloseRequest do define the behavior you want (probably doCancel() in most of the cases)
--------
@Urs:
If you want to close a form 'X', without asking for modification, you can use one of the both solutions described by Andreas. I agree with him, I would go with solution "2" (to keep the Form in sync [CancelButton, 'X' close box...] ).
If you want to close a form with the 'X' and ask the user if he wants to save his modification (what a CancelButton would do) and you do not have a Cancel button (because you display your form in a View, and CancelButton does not look good in a View).
Then I would do:
@Override
protected void execOnCloseRequest(boolean kill, HashSet<Integer> enabledButtonSystemTypes) throws ProcessingException {
doCancel();
}
--------
(*) A form is marked as modified when the user modifies a value in a Field.
Some methods will also mark the form as dirty if they are called after the load phase (for example in execPostLoad of the Form Handler):
- setValue() on a field.
- importFormData() on the form.
- touch() on the form.
see also form.doOk() does not call ModifyHandler#execStore()
.
[Updated on: Mon, 08 September 2014 17:25] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03517 seconds