I'm currently writing a data visualization application with Eclipse Scout Framework. It is based on the Scout Project Template "Outline Tree and Table Form". What confuses me is the event handling in the Outline Tree. As you might know the different pages/nodes in the tree are automatically activated/created and displayed when clicking on the nodes without any custom implementation. I want to change this behaviour to the effect that a context menu opens when right-clicking on a node to delete it in a second step. For that reason I've overwritten the "execNodeClick()" method in the StandardOutline to look like this:
@Override
protected void execNodeClick(ITreeNode node, MouseButton mouseButton) throws ProcessingException {
if (mouseButton == MouseButton.Right && node instanceof ConnectionNodePage) {
ConnectionNodePage clickedConnectionNode = (ConnectionNodePage) node;
logger.debug("Right click on ConnectionNode " + node);
List<AbstractMenu> menuList = new ArrayList<>();
menuList.add(new AbstractMenu() {
@Override
protected String getConfiguredText() {
// TODO Auto-generated method stub
return "delete";
}
@Override
protected void execAction() throws ProcessingException {
ServerConfigService serverConfigService = SERVICES.getService(ServerConfigService.class);
serverConfigService.removeServerConnection(clickedConnectionNode.getConnection());
StandardOutline.this.removeChildNode(StandardOutline.this.getRootNode(), clickedConnectionNode);
}
});
clickedConnectionNode.setMenus(menuList);
}
}
I don't know whether this is the recommended way to dynamically add a context menu to a Tree Node, but It works somehow :P However, there are serveral problems with this approach:
- For some reason the nodes must be clicked/activated before (next time clicking) the context menus are opened.
- You can see in the RAP client that empty context menus are also opened for pages that don't fulfill the condition "node instanceof ConnectionNodePage", although logging/debugging shows that condition works fine. My assumption is that the Scout engine finds the anonymous inner menu class and does something unpredictable with it. In the SWT client you don't see context menus for wrong pages.
- I suspect my Event Handling to complicate with the Scout internal event handling. I dont really know what kind of event handling Scout does by default when right-clicking on tree-nodes, but it definately does something I don't want it to do. So I'd like to disable any action on mouse right-click except my custom implementation above.
I would appreciate someone to show me how this mechanism works and where I have to place the corresponding changes or at least a hint where I have to look. Thanks in advance!