2016-10-10 32 views
0

我目前正在将Eclipse Helios中编写的一段非常旧的代码迁移到Eclipse Mars。代码利用org.eclipse.ui.internal包中的某些apis,如EditorSashContainer,EditorStack,PartStack,LayoutPart等。难道这些apis在e4兼容层中不再可用吗?还是我需要导入更多的插件?迁移可能涉及最少代码更改的代码的最佳方法是什么?我们正在使用这些API来基本上泄露编辑器,以便提供工作簿外观。Eclipse迁移和org.eclipse.ui.internal apis

在此先感谢!

回答

0

以下是我在E4环境中如何拆分编辑器的代码片段。

这是我如何执行:splitEditor(0.5f, 3, currentEditor, newEditor)

@Override 
public void splitEditor(float ratio, int where, IEditorPart containerEditor, IEditorPart editorToInsert) { 
    MPart container = containerEditor.getSite().getService(MPart.class); 
    if (container == null) { 
     return; 
    } 
    MPart toInsert = editorToInsert.getSite().getService(MPart.class); 
    if (toInsert == null) { 
     return; 
    } 

    insertEditor(ratio, where, container, toInsert); 
} 

/** 
* 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, relToElement, where, ratio); 
} 

@SuppressWarnings("restriction") 
private MPartStack getPartStack(MPart childPart) { 
    MStackElement stackElement = childPart; 
    MPartStack newStack = org.eclipse.e4.ui.model.application.ui.basic.impl.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; 
} 
0

你不应该使用内部API Eclipse API Rules of Engagement

日食的内部被完全重写的Eclipse 4和许多内部接口被更改或删除。现在一切都基于表示GUI中的对象的EMF模型。兼容性层提供旧式的API,但这只支持官方的API。

没有简单的方法来处理对内部API的更改。您将不得不了解Eclipse的新功能。

您可以覆盖大多数组件的“渲染器”,例如零件堆栈,这可能是您想要的方法。