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:
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!
Shame on me! Why keeping things simple when they can be complicated..? -.-
To answer my own question and perhaps to help others might missing the forest for the trees:
Eclipse Scout offers a built in option to add context menus to pages/nodes without the need of implementing any own mouse event handling.
You simply need to add an inner class extending AbtractMenu/AbstractExtensibleMenu to the page you want the context menu for. Scout computes this automatically to be opened as a right-click context menu to the corresponding node in the tree.
For a minimal menu implementation you only need to override the execAction() method of AbstractMenu to perform actions after click and override the getConfiguredText() method to set the desired display text for the menu in your new menu class. This way you avoid the weird behaviour I found with my first approach.
I hope this answer will save somebody the hours I wasted.