Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java EclipseRCP:打开分割屏幕编辑器_Java_Eclipse_Eclipse Rcp - Fatal编程技术网

Java EclipseRCP:打开分割屏幕编辑器

Java EclipseRCP:打开分割屏幕编辑器,java,eclipse,eclipse-rcp,Java,Eclipse,Eclipse Rcp,我正在寻找一种在EclipseRCP应用程序中以编程方式打开拆分屏幕编辑器的方法。 从打开的编辑器中,我想打开另一个编辑器。目的是比较Editor1和Editor2的内容 我所拥有的是以下内容,但这会创建一个包含Editor2内容的分屏编辑器两次: MPart editorPart = editor.getSite().getService(MPart.class); if (editorPart == null) { return; } editorPart.getTags().add

我正在寻找一种在EclipseRCP应用程序中以编程方式打开拆分屏幕编辑器的方法。 从打开的编辑器中,我想打开另一个编辑器。目的是比较Editor1和Editor2的内容

我所拥有的是以下内容,但这会创建一个包含Editor2内容的分屏编辑器两次:

MPart editorPart = editor.getSite().getService(MPart.class);
if (editorPart == null) {
    return;
}
editorPart.getTags().add(IPresentationEngine.SPLIT_HORIZONTAL);

我认为最好是在当前编辑器左侧或下方打开Editor2,这样它就有了自己的选项卡和关闭按钮。

下面的代码通过将一个编辑器插入另一个编辑器来拆分编辑器。这就是dndforeditor选项卡在Eclipse中所做的

   /**
     * Inserts the editor into the container editor.
     * 
     * @param ratio
     *            the ratio
     * @param where
     *            where to insert ({@link EModelService#LEFT_OF},
     *            {@link EModelService#RIGHT_OF}, {@link EModelService#ABOVE} or
     *            {@link EModelService#BELOW})
     * @param containerEditor
     *            the container editor
     * @param editorToInsert
     *            the editor to insert
     */
    public void insertEditor(float ratio, int where, MPart containerEditor, MPart editorToInsert) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        EModelService service = window.getService(EModelService.class);
        MPartStack toInsert = getPartStack(editorToInsert);

        MArea area = getArea(containerEditor);
        MPartSashContainerElement relToElement = area.getChildren().get(0);
        service.insert(toInsert, (MPartSashContainerElement) relToElement, where, ratio);
    }

    private MPartStack getPartStack(MPart childPart) {
        MStackElement stackElement = childPart;
        MPartStack newStack = BasicFactoryImpl.eINSTANCE.createPartStack();
        newStack.getChildren().add(stackElement);
        newStack.setSelectedElement(stackElement);
        return newStack;
    }

    private MArea getArea(MPart containerPart) {
        MUIElement targetParent = containerPart.getParent();
        while (!(targetParent instanceof MArea))
            targetParent = targetParent.getParent();
        MArea area = (MArea) targetParent;
        return area;
    }
使用插入法的示例如下:

insertEditor(0.5f, EModelService.LEFT_OF, containerPart, childPart);
insertEditor(0.5f, EModelService.BELOW, containerPart, childPart);

顺便说一句,类中的代码负责编辑器选项卡的DnD功能。

您是否在寻找类似的功能?下面发布的答案,请确定。只需在当前编辑器旁边或下方打开一个编辑器。比较编辑器将是第二选择。我不知道您的实际用例,但是如果目的是比较内容,那么使用Eclipse时比较编辑器是自然选择。我同意,但是比较编辑器有很多依赖项。org.eclipse.compare包还依赖于org.eclipse.ui.ide,这不适合我的RCP应用程序。我错误地认为你的目标是IDE。太好了,这正是我想要的。谢谢