View Full Version : EditorTreeGrid/contextmenu getSelectedItem returns null

16 Jun 2009, 8:32 AM
I am playing with EditorTreeGrid (GXT 2.0 M3). I added a context menu to it, and when contextMenu.componentSelected is called I am trying to get a reference to an item on which it was called:

Object o=tree.getSelectionModel().getSelectedItem();but that returns null.

tree.getSelectionModel()returns object of class:


Same code works if I replace EditorTreeGrid with TreePanel.

Any sugestions how to get it to work with EditorTreeGrid ?

16 Jun 2009, 8:38 AM
Dont use a CellTreeGridSelectionModel. Use the normal TreeGridSelectionModel which selectes the hole row. Than you will have entries in it.

16 Jun 2009, 8:57 AM
Sven, thanks for your help.

Seems by default EditorTreeGrid is using CellTreeGridSelectionModel. When I manually set it to TreeGridSelectionModel per your suggestion everything is fine now.

4 Dec 2009, 6:14 AM
Changing the selection model for EditorTreeGrid to TreeGridSelectionModel doesn't seem to change any functionality - you are still able to change the values in each cell.

Switch to TreeGridSelectionModel:

tree.setSelectionModel(new TreeGridSelectionModel<ModelData>());

If you don't want to switch to TreeGridSelectionModel you can use something like this to get the information about the selected cell and its row (e.g. the model of the row):

Menu contextMenu = new Menu();
contextMenu.addListener(Events.BeforeShow, new Listener<MenuEvent>() {

public void handleEvent(MenuEvent objEvent) {

GridSelectionModel<ModelData> selectionModel = objTree.getSelectionModel();

if (selectionModel instanceof CellTreeGridSelectionModel) {
// Cast selection model to CellTreeGridSelectionModel
// to get getSelectCell...
CellTreeGridSelectionModel<ModelData> cellSelectionModel = (CellTreeGridSelectionModel<ModelData>)selectionModel;
} else {

cellSelectionModel.getSelectCell().model returns the same model for all cells - the row model.

First checking, if the current selection model of the tree is CellTreeGridSelectionModel prevents null exceptions, if someone changes the selection model for the tree without updating the code in the context menu.