CellTable:: Deselecting an already selected row

2,518 views
Skip to first unread message

Veeren

unread,
Feb 14, 2011, 6:37:26 PM2/14/11
to Google Web Toolkit
I wish to deselect an already selected row on a CellTable.

For example, a user comes and selects a row, then for him to de-select
the currently selected row, he has to click on another row, but the
problem is that, when we have ONLY 1 row available there is no way to
deselect the currently selected row.

Also, once you select a row on CellTable and you later refresh the
data, the CellTable continues holding the currently selected row, i
need it to forget about its past selection.

Anyone tinkered with such case, any solutions?

Thomas Broyer

unread,
Feb 14, 2011, 6:52:10 PM2/14/11
to google-we...@googlegroups.com


On Tuesday, February 15, 2011 12:37:26 AM UTC+1, Veeren wrote:
I wish to deselect an already selected row on a CellTable.

For example, a user comes and selects a row, then for him to de-select
the currently selected row, he has to click on another row, but the
problem is that, when we have ONLY 1 row available there is no way to
deselect the currently selected row.

Ctrl+clicking should do it (at least with GWT 2.2, not sure for 2.1)
 
Also, once you select a row on CellTable and you later refresh the
data, the CellTable continues holding the currently selected row, i
need it to forget about its past selection.
 
If you use a SingleSelectionModel, it's as easy as sm.setSelected(sm.getSelectedObject(), false), and if you're using a MultiSelectionModel: sm.clear()

Jambi

unread,
Feb 14, 2011, 8:48:42 PM2/14/11
to Google Web Toolkit
> If you use a SingleSelectionModel, it's as easy as
> sm.setSelected(sm.getSelectedObject(), false)

I am using this method on my CellTable and it works. But somehow I get
always an "com.google.gwt.event.shared.UmbrellaException: One or more
exceptions caught, see full set in UmbrellaException#getCauses"
Exception. Is this a know issue or do you think that my implementation
cout cause the problem?

My Code looks like this:

...
final SingleSelectionModel<Member> selectionModel = new
SingleSelectionModel<Member>();
Handler selectionHandler = new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
Member selection = selectionModel.getSelectedObject();
eventBus.fireEvent(new ShowMemberEvent(selection.getBarcodeID()));
selectionModel.setSelected(selection, false);
}
};
selectionModel.addSelectionChangeHandler(selectionHandler);
...

Thanks,
Michael

Thomas Broyer

unread,
Feb 15, 2011, 4:53:01 AM2/15/11
to google-we...@googlegroups.com
I think you cannot modify a SelectionModel from within a handler for a SelectionChangeEvent that it fired.

But in your case, it looks like you'd rather use a NoSelectionModel.

jona...@buvintech.com

unread,
Sep 6, 2013, 9:18:12 AM9/6/13
to google-we...@googlegroups.com
public class MyDataGrid<T> extends DataGrid<T> {
 private Set<T> priorSelectionSet_;
 ....

 /**
  * Allows User To Deselect A DataGrid Row By Clicking A Second Time On The Prior Selection
  */
 private void addDeselectMechanism(){
   /*
     NOTES:  
     1. ClickHandler() fires every time the grid is clicked. 
    2. selectionModel SelectionChangeHandler() does NOT fire when clicking
       a row that is already selected.
    3. Generally, ClickHandler() fires and then SelectionChangeHandler() fires,
       but testing showed some exceptions to this order and duplicate firings.
    4. The Current SelectedSet is Updated AFTER the ClickHandler() fires, so "natural"
       ClickHandler() timing does not permit current SelectedSet inspections. 
    5. In this case, the scheduleDeferred() code will ALWAYS fires when a grid is clicked,
       it will fire at a PREDICTABLE time, and AFTER the current SelectedSet has been updated.       
  */  
  super.addHandler(new ClickHandler(){
         @Override
         public void onClick(ClickEvent event) {
          Scheduler.get().scheduleDeferred(new ScheduledCommand() {   
           @Override
           public void execute() {
            Set<T> currentSelectedSet = selectionModel_.getSelectedSet();
            if( (currentSelectedSet.size() == 1) &&
             (priorSelectionSet_ != null) ){
             if( (currentSelectedSet.size() == priorSelectionSet_.size()) &&            
                (currentSelectedSet.containsAll( priorSelectionSet_ ) ) ){         
              selectionModel_.clear();
             }
              }
           priorSelectionSet_ = new HashSet<T>();
           priorSelectionSet_.addAll( selectionModel_.getSelectedSet() );                       
           }
          });          
          
         }
     }, ClickEvent.getType());
 }
 .....
}
 

Alicia Jones

unread,
Feb 13, 2014, 6:51:05 PM2/13/14
to google-we...@googlegroups.com
Jon, please clarify...
1. Where selectionModel_ declared and instantiated?
2. Do you have a constructor?  In the code-as-is this private method is never called.

Thanks!
Alicia
Reply all
Reply to author
Forward
0 new messages