【问题标题】:In Eclipse Scout Luna how to add a page in extension to outline in parent?在 Eclipse Scout Luna 中,如何在父级大纲中添加扩展页面?
【发布时间】:2015-02-24 00:45:16
【问题描述】:

由于 Scout 在项目中支持模块化,我们决定将事物模块化。问题是当我们向项目添加大纲时:如何将页面添加到该大纲,但是当页面存在于子项目中时。将页面添加到大纲的函数位于大纲内部,问题是我们不应该让父级依赖于子级,因为我们会在依赖关系中得到循环。

大纲是 AbstractExtensibleOutline 类型,可能支持基于类标题中的名称和注释的扩展/扩展,但我还没有弄清楚在哪里以及如何做到这一点。

【问题讨论】:

标签: eclipse-scout


【解决方案1】:

我不怀疑您的programmatically solution 正在工作,但我喜欢使用 Eclipse 扩展点提出另一个建议。我认为这是使用此 API 的预期方式。

在您的扩展程序中,您根本不需要DesktopExtension

mycore.client (Core Project)
  |
  \- Desktop
        |
        \- MyOutline

myext.client (Extended Project)
  |
  \- MyPage

如果MyOutline 扩展AbstractExtensibleOutline,您只需将MyPage 直接添加到MyOutline(在核心中定义)和pageContribution(使用org.eclipse.scout.rt.extension.client.pages 扩展点)。

如果显示文本,客户端扩展包 (myext.client) 文件的 plugin.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <extension
         point="org.eclipse.scout.rt.extension.client.pages">
      <pageContribution
            active="true"
            class="myext.client.pages.MyPage"
            order="1">
         <outline
               class="mycore.client.ui.desktop.outlines.MyOutline">
         </outline>
      </pageContribution>
   </extension>
</plugin>

使用 Order 字段,您可以指示页面列表中的位置(这样您可以在列表中间插入页面)。

您也可以注册:

  • pageModification
  • pageRemoval

... 取决于您的需要。

还请查看此论坛帖子,其中我描述了您如何以同样的方式贡献MenuMulti Module - Menu Extension


还请注意,对于 Mars(从 4.2 版开始),我们引入了另一种可扩展机制。查看此 wiki 页面以了解更多信息:Scout Concepts - Extensibility

这个新机制比我们在 Kepler (Scout 3.9) 中引入的机制更强大。 Mars 版本同时支持新的和旧的可扩展性模式。从长远来看,我认为只会支持新模式。

【讨论】:

    【解决方案2】:

    如果你扩展你的项目,你最终会得到桌面扩展而不是桌面。

    桌面扩展在父桌面之后初始化,因此您可以预期父桌面内的大纲已经准备好。

    假设你有这种结构:

    Core Project
            |
            -- Desktop
                   |
                   -- MyOutline
    
    Extended Project
            |
            -- Desktop Extension
            |
            -- My Page
    

    所以在桌面扩展的扩展项目中,你需要重写初始化函数

    @Override
    protected ContributionCommand execInit() throws ProcessingException {
    
        ContributionCommand command = super.execInit();
    
        for (IOutline outline : getCoreDesktop().getAvailableOutlines()) {
          List<IPage> pages = new ArrayList<IPage>();
    
          MyPage myPage = new MyPage();
          pages.add(myPage);
    
          AbstractPageWithNodes pageWithNode = (AbstractPageWithNodes) outline.getRootNode();
          pageWithNode.getTree().addChildNodes(pageWithNode, pages);
        }
    
        return command;
     }  
    

    这样,MyPage 将被添加到所有大纲中。如果你想在具体使用instanceof函数上添加。

    【讨论】:

    • 在我看来using eclipse extension points 是您使用此 API 的最佳选择。
    • 好吧,这个解决方案也可以,但是你的解决方案绝对是为了漂亮的代码和模块化而走的路。
    猜你喜欢
    • 2019-11-29
    • 2015-01-13
    • 2014-11-17
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多