Tuesday, January 29, 2013

Re: Cancel CellList selection

I was looking something similar and your example is perfect. I am going with approach of having my custom SingleSelectionHandler i.e PromptingSelectionModel . My view is more like GWT Showcase CellList-DetailForm example. If I click on my cell, my code populates the form elements. My Form is a separate GWT custom widget FormAWidget with its own presenter FormAPresenter. 

So with that being said, I probably will be storing a variable "hasUnsavedChanged" in ClientFactory which gets updated whenever my form data is changed. How do I get that variable inside my PromptingSelectionModel class so that I can check that variable in my overridden setSelected method? Since I use GWT MVP structure my ViewA holds declaration of CellList and PromptingSelectionModel. The ActivityA has reference to ClientFactory, the only way I can think of is passing the ClientFactory to my ViewA class with setClientFactory(ClientFactory cf) and pass that ClientFactory object to PromptingSelectionModel constructor. I don't like the idea of my views now having reference of ClientFactory. 

Please advise if you can see any better way of doing this. I always follow GWT Activities and Places paradigm where my Views hold GWT widgets and getter and setter methods to talk to its Activity class based on what Ray Ryan suggested with MVP Activities and Places approach.

On Thursday, November 10, 2011 5:12:57 AM UTC-6, Thomas Broyer wrote:
It's not about cancelling the event; it's about *not* routing it to a DefaultSelectionEventManager (which changes selection depending on the event). It also means you shouldn't addCellPreviewHandler, but instead use the two-argument overload of setSelectionModel.

It's as easy as:
myCellList.setSelectionModel(mySelectionModel, CellPreviewEvent.Handler<MyObject>() {
   private final CellPreviewEvent.Handler<MyObject> defaultSelectionManager = DefaultSelectionEventManager.createDefaultManager();
   public void onCellPreview(CellPreviewEvent<MyObject> event) {
      if (hasUnsavedChanged() && !Window.prompt("There are unsaved changes, are you sure you want to continue?") {
      return defaultSelectionManager.onCellPreview(event);

Beware though, if you have a cell that "handlesSelection()", you'll have to handle the case there (so that it doesn't change selection if there are unsaved changes).

Oh, and it just occurred to me that you could also simply code that within your SelectionModel too:
class PromptingSelectionModel<T> extends SingleSelectionModel<T> {
   public void setSelected(T object, boolean selected) {
      if (hasUnsavedChanged() && !Window.prompt("There are unsaved changes, are you sure you want to continue?") {
      super.setSelected(object, selected);

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