Capturing “Cancel” selection from GWT Activity.mayStop() response

262 views
Skip to first unread message

Vincent Fazio

unread,
Jan 30, 2012, 2:31:19 PM1/30/12
to google-we...@googlegroups.com
I have a GWT two column display. The left column contains a CellTable with a list of users in the application. When the user selects an user from the list, the right column displays the selected users details - which the user can edit.

I have my Activity wired up to use the mayStop() method so that before switching users, the system will attempt to save any unsaved changes the user has made - as long as there are no validation errors.

My question is about the behavior if there are validation errors. I have it wired to ask the user to discard the unsaved edits or return to the page and correct the issues. My problem is that when the user hits cancel (to return and correct the errors), the cell table still "selects" the new user instead of keeping the user that's in the detail column selected. It appears that switching away from the user activity was canceled, but GWT is still making the CellTable selection. Is there a way to capture the "Cancel" selection, or stop cell table selection from occurring?

Jens

unread,
Jan 30, 2012, 5:11:37 PM1/30/12
to google-we...@googlegroups.com
I think you have to manage the selection in your CellTable by hand based on the place (you dont want to change the place based on SelectionModel changes).

Never done it before (and maybe it doesn't work) but I think would create a custom cell that overwrites AbstractCell.handlesSelection() to return true (by default it returns false) and listens for click events. When you click on this custom cell it should call placeController.goTo(...). So its kind of a "UserPlaceCell". Because handlesSelection() returns false now, the CellTable would not update the SelectionModel by itself when clicking on a cell, so it still contains the current selection.

The activity for your left column which displays the CellTree should now update the CellTree SelectionModel based on the current place (probably by listening to PlaceChangeEvents). Because the activity now controls the selection based on place changes, the selection will not change if the user canceled the place change. => your views should be in sync.

I hope this helps.

-- J.

Thomas Broyer

unread,
Jan 31, 2012, 7:06:59 AM1/31/12
to google-we...@googlegroups.com
With a CellTable, you can also use a CellPreviewEvent.Handler instead of a custom cell (or you can use a custom SelectionModel that won't update from methods called by the CellTable, and you'll update it "manually" using another specific method, in response to a PlaceChangeEvent).

Bong Munoz

unread,
Feb 10, 2012, 4:44:44 PM2/10/12
to google-we...@googlegroups.com
As Jens suggested overriding AbstractCell#handlesSelection to handle revoking a selection works. I used this to revoke a selection in a CellTree. Thanks Jens.

Michael Prentice

unread,
Dec 27, 2013, 3:17:22 PM12/27/13
to google-we...@googlegroups.com
I'm running into this same situation today when using a DataGrid (each row mapping to a Place). I think that I'll try out the SelectionModel approach and try to set the selection myself on place changes.

I think that Thomas was trying to refer to this StackOverflow question as the one posted doesn't seem to be related:

Michael Prentice

unread,
Dec 30, 2013, 5:24:41 PM12/30/13
to google-we...@googlegroups.com
I've detailed my solution here: http://stackoverflow.com/a/20848504/633107

It uses both the AbstractCell#handlesSelection override suggested by Jens and the CellPreviewEvent.Handler suggested by Thomas.

Thank you!

Michael Prentice
GDG Space Coast
Reply all
Reply to author
Forward
0 new messages