Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Detecting when a Form-in-a-View is closed
Detecting when a Form-in-a-View is closed [message #1405049] Wed, 06 August 2014 12:58 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
In our application we are using several forms that are displayed in views. Some of them have the attribute allowMultiple="true" in their view definition in the SWT plugin.xml. This means that they can be opened multiple times and also closed again (unlike the views that do not have alloMultiple=true which cannot be closed.

We are using the mechanism described in https://wiki.eclipse.org/Scout/HowTo/3.8/Open_a_Form_in_a_View#Opening_the_views to open these forms multiple times while making sure the form for a certain entity is only opened once. This works perfectly.

However, we have so far failed to detect when the user closes one of these forms using the "X" on the forms/views tab. We need to intercept this case to be able to handle the saving of unsaved changes etc. It seems the effect of closing the tab is the same as if getDesktop().removeForm() were called for this form, i.e. it is not closed but just removed from the view.

I have tried overriding just about every method of the form to see if it is called in this event but have not gotten a hit.

Is there a way to handle this case on the model (client) side? Or do I need to react to this in the SWT renderer somehow to then forward the information to the client model?
Re: Detecting when a Form-in-a-View is closed [message #1416203 is a reply to message #1405049] Thu, 04 September 2014 15:02 Go to previous messageGo to next message
Eclipse UserFriend
Hi Urs,
you have two options to get there:



  1. override AbstractForm.execOnCloseRequest in your form an call doClose().
      @Override
      protected void execOnCloseRequest(boolean kill, HashSet<Integer> enabledButtonSystemTypes) throws ProcessingException {
        doClose();
      }
    

  2. 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 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
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

Re: Detecting when a Form-in-a-View is closed [message #1419369 is a reply to message #1416232] Mon, 08 September 2014 13:57 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks, Option 1 works perfectly!
Previous Topic:Distinguish between left and right click on table row
Next Topic:Tooltips on Table rows/cells
Goto Forum:
  


Current Time: Wed Apr 24 17:05:42 GMT 2024

Powered by FUDForum. Page generated in 0.03517 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top