Eclipse 迁移和 org.eclipse.ui.internal api
Eclipse Migration and org.eclipse.ui.internal apis
我目前正在将用 Eclipse Helios 编写的一段非常古老的代码迁移到 Eclipse Mars。该代码使用了 org.eclipse.ui.internal
包中的某些 API,例如 EditorSashContainer
、EditorStack
、PartStack
、LayoutPart
等。这些 API 是否不再可用在 e4 兼容层?或者我需要导入更多的插件吗?迁移可能涉及最少代码更改的代码的最佳方法是什么。我们正在使用这些 api 基本上溢出编辑器,使其看起来像工作簿。
提前致谢!
您不应使用内部 API Eclipse API Rules of Engagement
针对 Eclipse 4 完全重写了 Eclipse 的内部结构,并更改或删除了许多内部接口。现在一切都基于表示 GUI 中对象的 EMF 模型。兼容层提供旧式 API,但这仅支持官方 API。
没有直接的方法来处理对内部 API 的更改。您将必须了解 Eclipse 做事的新方式。
您可以覆盖大多数组件(例如零件堆栈)的 'renderers',这可能是您执行所需操作的一种方式。
这是我如何在 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;
}
我目前正在将用 Eclipse Helios 编写的一段非常古老的代码迁移到 Eclipse Mars。该代码使用了 org.eclipse.ui.internal
包中的某些 API,例如 EditorSashContainer
、EditorStack
、PartStack
、LayoutPart
等。这些 API 是否不再可用在 e4 兼容层?或者我需要导入更多的插件吗?迁移可能涉及最少代码更改的代码的最佳方法是什么。我们正在使用这些 api 基本上溢出编辑器,使其看起来像工作簿。
提前致谢!
您不应使用内部 API Eclipse API Rules of Engagement
针对 Eclipse 4 完全重写了 Eclipse 的内部结构,并更改或删除了许多内部接口。现在一切都基于表示 GUI 中对象的 EMF 模型。兼容层提供旧式 API,但这仅支持官方 API。
没有直接的方法来处理对内部 API 的更改。您将必须了解 Eclipse 做事的新方式。
您可以覆盖大多数组件(例如零件堆栈)的 'renderers',这可能是您执行所需操作的一种方式。
这是我如何在 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;
}