I have a CellTree which utilizes a MultiSelectionModel with CheckboxCells as part of a composite cell. That all seems to be working.
What I'm actually trying to do is to generate tabs in my interface for each item that can be selected in the tree. Sounds trivial, but I'm stumped as to how to get the MyData on a selectionChange. The items need to remain selected so that if I unselect them later, the tabs are then removed again.
I need to be get the MyData for the just selected item in order to know what the contents of the tab should be.
final MultiSelectionModel<TableLight> selectionModel = new MultiSelectionModel<TableLight>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
}
});
I feel like I'm totally missing the obvious. All I can do in the selectionChange event is to interrogate my selection handler to see what the selected set is. Is there a way I can attach a listener to a specific tree selection instead of a global, "something has changed" listener.
Any hints would be much appreciated.
Adding an extended selection model will get you the last selected element :
gridSelectionModel = new MultiSelectionModel<MyData>(KEY_PROVIDER){
public void setSelected(MyData myData, boolean selected) {
super.setSelected(myData, selected);
if (selected){
System.out.println("setSelected selected " + myData);
// call now some ui handler to use the last selected myData element
}
}
};
I hope this helps.
Ok, for anyone who finds this later, there is a way!
When you add the CheckboxCell to the CompositeCell you can specify a FieldUpdater to be returned which gets called when the field is changed.
hasCells.add(new HasCell<TableLight, Boolean>() {
// Cell containing checkbox
private Cell cell = new CheckboxCell(true, false);
public Cell<Boolean> getCell() {
return cell;
}
public FieldUpdater<TableLight, Boolean> getFieldUpdater() {
return new FieldUpdater<TableLight, Boolean>() {
public void update(int index, TableLight object, Boolean value) {
if (value) {
tablesTabPanel.addTable(object);
} else {
tablesTabPanel.removeTable(object);
}
}
};
}
public Boolean getValue(TableLight object) {
return selectionModel.isSelected(object);
}
});
Also, just to avoid confusion. When I was talking about MyData above, that is TableLight in the example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With