PDA

View Full Version : Unable to see BaseTreeModel changes after adding it to a TreeStore



axeldxter
3 Jun 2008, 2:07 PM
Hi. I've been having a problem from some time now when trying to update the values of a BaseTreeModel that is added to a TreeStore, which in turn is binded to a TreeTable. The code looks like this:


property = new BaseTreeModel();
property.set("name", "Name");
property.set("value", "Value");

store = new TreeStore();
store.setMonitorChanges(true);
store.add(property);

binder = new TreeTableBinder(propertyGrid, store);
binder.setDisplayProperty("name");
binder.init();

Then later, I change the value of property:

property.set("value", "NewValue")
But the value in the TreeTable is never refreshed. Is it some bug? Or there's no way to change the value and inmediately see the change? It doesn't matter if it is a completely different code, but I need something that can do this.

Thanks

axeldxter
3 Jun 2008, 3:14 PM
Hi. I debugged the program and the problem seems to be in the findItem() method of the TreeTableBinder class. It seems the treeTable.getItems() of the foreach statement returns and empty list, so the item updated is never found and the update method never executed. Isn't treeTable.getAllItems() what should really be invoked?

Thanks

axeldxter
4 Jun 2008, 7:40 AM
Hey. I think I fixed the problem! After changing item.getItems() for item.getAllItems() in TreeTableBinder.findItem(), I overwrote the update method of TreeBinder in TreeTableBinder, like this:



@Override
protected void update(M model) {
TreeTableItem item = (TreeTableItem) findItem(model);
updateItemValues(item);
updateItemStyles(item);
super.update(item, model);
}


An the values seem to update perfectly! :)

darrellmeyer
4 Jun 2008, 11:56 AM
Good investigating and your fixes are correct. Thanks!