I am trying to use Google web toolkit (v2.5) TreeViewModel to create a tree of cells with one clickable link per cell. I have the tree displaying properly, but I have been unable to figure out how to handle events when clicking on a cell. My class NeoTreeModel implements TreeViewModel, but when I create an AbstractCell in getNodeInfo and try to override onBrowserEvent, I get the compile error "method does not override or implement a method from a supertype". I am not committed to this approach. I would be happy with ANY solution where you can click on a tree of buttons or links and be able to handle the event. I have been trying several hours to accomplish what I thought would be something easy.
public class NeoTreeModel implements TreeViewModel {
private List<NeoTreeItem> _items = null;
private Logger _logger = Logger.getLogger("NeoTreeModel ");
public NeoTreeModel(List<NeoTreeItem> items) {
_items = items;
}
public <T> NodeInfo<?> getNodeInfo(T value) {
List<NeoTreeItem> list = new ArrayList<NeoTreeItem>();
if (value == null) {
for (NeoTreeItem nti: _items) if (nti.getLevel() == 0) list.add(nti);
} else if (value instanceof NeoTreeItem) {
list = ((NeoTreeItem)value).getChildren();
} else {
_logger.log(Level.SEVERE, "Got request for unknown type: " + value);
}
ListDataProvider<NeoTreeItem> provider =
new ListDataProvider<NeoTreeItem>(list);
Cell<NeoTreeItem> cell = new AbstractCell<NeoTreeItem>() {
public void render(Cell.Context context, NeoTreeItem value,
SafeHtmlBuilder sb) {
if (value != null) {
sb.appendHtmlConstant("<a href='javascript:;'>");
sb.appendEscaped(value.getLongName());
sb.appendHtmlConstant("</a>");
}
}
@Override
public void onBrowserEvent(Cell.Context context, Element parent,
NeoTreeItem value, NativeEvent event,
ValueUpdater<NeoTreeItem> valueUpdater) {
_logger.log(Level.INFO, "HOWDY2");
}
}
};
return new DefaultNodeInfo<NeoTreeItem>(provider, cell);
}
public boolean isLeaf(Object value) {
boolean result = false;
if (value instanceof NeoTreeItem) {
result = ((NeoTreeItem) value).isLeaf();
}
return result;
}
}