简体   繁体   English

Eclipse Scout树视图事件处理

[英]Eclipse Scout Tree View Event Handling

I'm currently writing a data visualization application with Eclipse Scout Framework. 我目前正在使用Eclipse Scout Framework编写数据可视化应用程序。 It is based on the Scout Project Template "Outline Tree and Table Form". 它基于Scout项目模板“概述树和表格形式”。 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: 出于这个原因,我在StandardOutline中覆盖了“ execNodeClick()”方法,如下所示:

 @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: 我不知道这是否是向树节点动态添加上下文菜单的推荐方法,但是它可以通过某种方式起作用:P但是,这种方法存在服务器问题:

  1. For some reason the nodes must be clicked/activated before (next time clicking) the context menus are opened. 由于某些原因,必须在打开上下文菜单之前(下次单击)单击/激活节点。
  2. 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. 您可以在RAP客户端中看到,对于不满足条件“ ConnectionNodePage的节点实例”的页面,也打开了空的上下文菜单,尽管记录/调试表明该条件可以正常工作。 My assumption is that the Scout engine finds the anonymous inner menu class and does something unpredictable with it. 我的假设是,Scout引擎会找到匿名内部菜单类并对其执行某些不可预测的操作。 In the SWT client you don't see context menus for wrong pages. 在SWT客户端中,看不到错误页面的上下文菜单。
  3. I suspect my Event Handling to complicate with the Scout internal event handling. 我怀疑我的事件处理与Scout内部事件处理复杂。 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. 我真的不知道右键单击树节点时,Scout默认情况下会执行哪种事件处理,但是它确实会执行我不希望执行的操作。 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! 提前致谢!

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. Eclipse Scout提供了一个内置选项,可以将上下文菜单添加到页面/节点,而无需实现任何自己的鼠标事件处理。

You simply need to add an inner class extending AbtractMenu/AbstractExtensibleMenu to the page you want the context menu for. 您只需要添加一个内部类,即可将AbtractMenu / AbstractExtensibleMenu扩展到要为其使用上下文菜单的页面。 Scout computes this automatically to be opened as a right-click context menu to the corresponding node in the tree. Scout会自动计算该内容,以右键单击上下文菜单将其打开到树中的相应节点。

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. 对于最小的菜单实现,您只需要重写AbstractMenu的execAction()方法以在单击后执行操作,并重写getConfiguredText()方法来为新菜单类中的菜单设置所需的显示文本。 This way you avoid the weird behaviour I found with my first approach. 这样可以避免我第一种方法发现的奇怪行为。

I hope this answer will save somebody the hours I wasted. 我希望这个答案可以节省我浪费的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM