Search code examples
gwtgwt2

How to DeSelect a cell in CellList Gwt


I have a CellList in GWT, i need to deselect the cell when one link is clicked without using the selectionchange handler.Can someone help in this situation.

CellList<MyClass> cellList;    
SingleSelectionModel<MyClass> lSelectionModel;

final SingleSelectionModel<MyClass> lSelectionModel = 
    new SingleSelectionModel<MyClass>();
this.cellList.setSelectionModel(lSelectionModel);

public void setSelected(final MyClass pClass) {

        Anchor lLink = new Anchor();
        lLink.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent pEvent) {
        //Here i need to deselect the cell(Myclass)

            }
        });

}

Thanks in advance,

Raj


Solution

  • Using a SingleSelectionModel, is as easy as:

    lLink.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent pEvent) {
        MyClass selected = lSelectionModel.getSelectedObject();
        if (selected != null) {
          lSelectionModel.setSelected(selected, false); 
        }
    });