Monday, February 4, 2013

Re: Implementing Custom SingleSelectionModel

Thanks for the reply. Interesting! Let me think. Well let me explain more and perhaps this should help a bit.

I have a CellList which has custom Cell which shows read only text. And I have a GWT form which has some textboxes and Listboxes displayed next to my CellList. So if Cell 1 is clicked, the data for the underlying DTO for cell 1 is shown in the form. 

Any changes in values in any of the textboxes and Listboxes, I update my formChangedFlag. 

My goal here is if the user has selected Cell 1 and form is displayed with the data of Cell 1 DTO and if the user changes any of the form data and clicks on another Cell let's say Cell 3, I want to show my confirm message and if they decide not to leave then DO NOT change the selection to Cell 3. 

I thought implementation SingleSelectionModel would be easier by overriding setSelected than FieldUpdater as I haven't used FieldUpdater. 

Any ideas?


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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
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.
 
 

No comments:

Post a Comment