Ok, probably the best solution to this is to implement FieldUpdater and
handle click events for that cell using it. It does not matter weather your
form is in the cell or not.

So using FieldUpdater, on a clickable cell you can in update method for
FieldUpdater check to make sure that your formChangedFlag is set or not. If
set then display confirmation dialog. If user decides that he don't want to
leave you should reselect currently selected cell programaticly using
setSelected method in selection model class where you will select. On the
other hand, if user decides to discard changes he made on form, you should
just populate form with new data, as you are doing it now.

Hope it helps,
Best, Milan

On Mon, Feb 4, 2013 at 4:04 PM, BM <[email protected]> wrote:

> I don't think I can use fieldUpdater as my form is not inside the Cell.
>
>
> On Saturday, February 2, 2013 10:30:16 PM UTC-6, Milan Cvejic wrote:
>
>> Why are you not using FieldUpdater?
>>
>> So instead of preventing selection, you actually handle changes in cells?
>>
>> On Friday, February 1, 2013 11:22:56 PM UTC+1, BM wrote:
>>>
>>> So I have a custom SingleSelectionModel which I am using to catch the
>>> setSelection well before it is selected. Basically to Cancel selection of
>>> second cell if the form data of the first cell is not saved.
>>>
>>> public class PromptingSelectionModel<T> extends SingleSelectionModel<T>
>>> {
>>>
>>>     private boolean stopSelection;
>>>
>>>     public PromptingSelectionModel() {
>>>
>>>         super();
>>>
>>>     }
>>>
>>>     public PromptingSelectionModel(**ProvidesKey<T> keyProvider) {
>>>
>>>         super(keyProvider);
>>>
>>>     }
>>>
>>>     @Override
>>>
>>>     public void setSelected(T object, boolean selected) {
>>>
>>>         if (formChanged
>>>
>>>                 && !Window.confirm("There are unsaved changes, are you
>>> sure you want to continue?")) {
>>>
>>>             stopSelection = true;
>>>
>>>             return;
>>>
>>>         } else {
>>>
>>>             stopSelection = false;
>>>
>>>         }
>>>
>>>         if (!(stopSelection)) {
>>>
>>>             super.setSelected(object, selected);
>>>
>>>           }
>>>
>>>     }
>>>
>>>  The problem I see here is When I move from one Cell item to another the
>>> setSelected method here is sometimes called twice and sometimes it is
>>> called once.
>>>
>>> Cell 1 selected. Which shows form data. I changed form data. formChanged
>>> get set to True.
>>>
>>> Clicked on Cell 3. setSelected method of PromptingSelectionModel is
>>> called. I see parameters to the methods are coming as DTO of Cell 1 and
>>> false. I get the confirm dialog box. I clicked Cancel. setSelected method
>>> of PromptingSelectionModel is called again. I see parameters to the methods
>>> are coming as DTO of Cell 2 and true.  I get the confirm dialog box again.
>>> Clicking Cancel now will keep the selection of Cell 1. So I got two confirm
>>> here okay? Then I click Cell 5. setSelected method of
>>> PromptingSelectionModel is called. I see parameters to the methods are
>>> coming as DTO of Cell 5 and true.I get the confirm dialog box only once.
>>> Clicking Cancel now will keep the selection of Cell 1.
>>>
>>> Is this a know bug? It seems internally hasCellPresenter class is called
>>> or something which sets the second cell as true.
>>>
>>>
>>>
>>>
>>>
>>>  --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
LiquidBrain!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to