View Full Version : [FNR] Strange Behavior for TreeGrid and Selection Model

23 Sep 2010, 5:45 AM
Example, I have 2 groups, with users within them. If one of the user is in both group, when a will click on the 2nd one, the TreeGrid will selection the 1st one.

I try to re implement the key provider and the model comparer, but any of this works.

Run the below example, expand both nodes, and click on the second "User2".

This is two seprate instance, but the equals plays on the "id".
I Guess if the equals plays on the "computeId", the problem doesn't occurs.

- GXT version : 2.2.0
- Host mode / web mode / both : Both
- Browser and version : FF 3.6, Chrome 5 (all ?)
- Operating System : WinXp
- Sample code

public class TreeGridExample implements EntryPoint

* @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
public void onModuleLoad()
MyModel group1 = new MyModel();
group1.set("id", 1);
group1.set("name", "Group Admin");
group1.set("computeId", Random.nextInt());

MyModel group2 = new MyModel();
group2.set("id", 2);
group2.set("name", "Group Admin 2 ");
group2.set("computeId", Random.nextInt());

MyModel user1 = new MyModel();
user1.set("id", 3);
user1.set("name", "User Admin 1");
user1.set("computeId", Random.nextInt());

MyModel user2 = new MyModel();
user2.set("id", 4);
user2.set("name", "User Admin 2");
user2.set("computeId", Random.nextInt());

MyModel user2a = new MyModel();
user2a.set("id", 4);
user2a.set("name", "User Admin 2");
user2a.set("computeId", Random.nextInt());

MyModel user3 = new MyModel();
user3.set("id", 5);
user3.set("name", "User Admin 3");
user3.set("computeId", Random.nextInt());



TreeStore<BaseTreeModel> store = new TreeStore<BaseTreeModel>();
store.setModelComparer(new ModelComparer<BaseTreeModel>()

public boolean equals(BaseTreeModel m1, BaseTreeModel m2)
Integer o1 = m1.<Integer> get("computeId");
Integer o2 = m2.<Integer> get("computeId");

return o1.equals(o2);
store.setKeyProvider(new ModelKeyProvider<BaseTreeModel>()

public String getKey(BaseTreeModel model)
return String.valueOf(model.<Integer> get("computeId"));
store.add(group1, true);
store.add(group2, true);

ColumnConfig cc = new ColumnConfig("name", 200);
cc.setRenderer(new TreeGridCellRenderer<BaseTreeModel>());
TreeGrid<BaseTreeModel> treeGrid = new TreeGrid<BaseTreeModel>(store, new ColumnModel(Arrays.asList(cc)));

Window win3 = new Window();
win3.setSize(640, 480);
win3.setLayout(new FitLayout());

class MyModel extends BaseTreeModel

* TODO Select constructor type. Default constructor. Constructor. Full construtor. Copy constructor.
public MyModel()

* @see java.lang.Object#equals(java.lang.Object)
public boolean equals(Object obj)
return this.<Integer> get("id").equals(((MyModel) obj).<Integer> get("id"));

23 Sep 2010, 5:53 AM
I just added a change to GXT which will fix the problem for you. Your ModelComparer can throw a NPE, you should fix that.

I will reply here once the change is in SVN.

23 Sep 2010, 6:00 AM
Thx Sven for the quick reponse !

But If the changes are not too important to make, is it possible to post those too? Or a new build of GXT will comes out soon for the public ?

23 Sep 2010, 6:03 AM
There is no easy way to override it. 2.2.1 will come out early of october probably.

23 Sep 2010, 6:07 AM
Okay no problem, thx again :)

23 Sep 2010, 7:51 AM
Fixed in SVN as of revision 2246.