【问题标题】:Open DialectEditor programmatically outside of main editor area (E3/E4 hybrid)在主编辑器区域之外以编程方式打开 DialectEditor(E3/E4 混合)
【发布时间】:2018-02-07 16:46:09
【问题描述】:

我想做的事:

在我的 E3/E4 混合 RCP 中,我有一个基于天狼星树的项目和库。用户可以将拖放项从库树拖到项目树中。这很好用,构建起来也不是什么大问题。所以现在我想让 UI 更有用。它应该看起来像这样的布局:

什么有效:

应用程序启动后,我使用 DialectUIManager 打开我的库演示文稿。

final DialectEditor editor = (DialectEditor) 
DialectUIManager.INSTANCE.openEditor(siriusSession, description, monitor);

好的,这行得通。但它在零件市场的编辑器中将其打开为 org.eclipse.ui.editorss。这不是我想要的

什么不起作用:

我想在“图书馆部分”中展示它。打开编辑器后我可以用鼠标手动移动它,但是我如何告诉 DialectUIManager 直接在那里打开它。或者我怎样才能以编程方式将它移到那里。

我做了很多谷歌研究,但我没有找到解决方案。我发现的唯一一个提示是 Pierre-Charles David https:// www. eclipse.org/forums/index.php?t=msg&th=998476&goto=1631138&#msg_1631138

如果您需要的只是在主编辑器之外显示编辑器 区域,这是可能的,因为 Eclipse 4.2(e4 并没有真正对待 主编辑器区域作为特殊的东西),所以你可以有你的编辑器 在其他视图中间“围绕”另一个编辑器。

但在这一步我卡住了。我也在 Sirius 论坛上问过,但他们说这是 Eclipse E4 问题

感谢您的帮助,编码 sn-ps 或链接到正确的手册部分。

【问题讨论】:

  • 我不知道DialectUIManager 是什么,但大概是使用 3.x API 来打开编辑器——这些 API 无法说明编辑器的打开位置。
  • DialectUIManager 是 Sirius API 的一部分,您是对的,它使用 3.x API。编辑器的类型为“IEditorPart”。如果无法直接在另一部分打开编辑器,是否可以通过编程方式将其移动到库部分中?

标签: eclipse-rcp e4 eclipse-pde pde eclipse-sirius


【解决方案1】:

我找到了解决方案。这不是很好,但它有效。编辑器打开后,我在这里执行这些代码。

代码的作用:

他正在寻找 ID 为 org 的 MPlaceholder。蚀。 ui。编辑。他在那里下降,直到他与零件在一起。这些处于兼容编辑器模式。然后他选择我们想要移出的部分并将它们附加到 MPartStack 目标。

  public static void movePart(MApplication application, 
            EModelService modelService) {

    MPart partToMove = null;
    MUIElement muiElement = 
            modelService.find("org.eclipse.ui.editorss", application);

    if (muiElement instanceof MPlaceholder) {
      MPlaceholder placeholder = (MPlaceholder) muiElement;
      MUIElement ref = placeholder.getRef();

      if (ref instanceof MArea) {
        MArea area = (MArea) ref;
        List<MPartSashContainerElement> children = area.getChildren();

        for (MPartSashContainerElement mPartSashContainerElement 
                                                       : children) {

          if (mPartSashContainerElement instanceof MPartStack) {
            MPartStack partStack = (MPartStack) mPartSashContainerElement;
            List<MStackElement> children2 = partStack.getChildren();
            for (MStackElement mStackElement : children2) {
              if (mStackElement instanceof MPart) {
                MPart part = (MPart) mStackElement;
                // Library is the Editor Name wiche I want to move
                if (part.getLabel().equals("Library")) {
                  partToMove = part;
                  break;
                }
              }
            }
          }
        }

      }
    }

    if (partToMove != null) {
      moveElement(modelService, application, partToMove);
    }
  }

  private static void moveElement(EModelService modelService, 
                    MApplication application, MPart part) {
    // target PartStack
    MUIElement find = modelService.find("de.bsg.onesps.rcp.
                               partstack.library", application);

    if (find instanceof MPartStack) {
      MPartStack mPartStack = (MPartStack) find;

      mPartStack.getChildren().add(part);
      mPartStack.setSelectedElement(part);
    }
  }

【讨论】:

    猜你喜欢
    • 2017-06-09
    • 1970-01-01
    • 2013-11-18
    • 2020-12-10
    • 1970-01-01
    • 2019-01-19
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多