[英]Eclipse RCP: Open Split Screen Editor
我正在尋找一種以編程方式在 Eclipse RCP 應用程序中打開分屏編輯器的方法。
從打開的編輯器中,我想打開另一個編輯器。 目的是將 Editor1 的內容與 Editor2 的內容進行比較。
我所擁有的是以下內容,但這會創建一個分屏編輯器,其中包含兩次 Editor2 的內容:
MPart editorPart = editor.getSite().getService(MPart.class);
if (editorPart == null) {
return;
}
editorPart.getTags().add(IPresentationEngine.SPLIT_HORIZONTAL);
我認為最好在當前編輯器的左側或下方打開 Editor2,因此它有自己的選項卡和關閉按鈕。
下面的代碼通過將一個編輯器插入另一個編輯器來拆分編輯器。 這就是 Eclipse 中編輯器選項卡的 DnD 所做的。
/**
* 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;
}
使用insert
方法的示例如下:
insertEditor(0.5f, EModelService.LEFT_OF, containerPart, childPart);
insertEditor(0.5f, EModelService.BELOW, containerPart, childPart);
順便說SplitDropAgent2
,類SplitDropAgent2
代碼負責編輯器選項卡的 DnD 功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.