DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Programmatically Split An Editor Area To Show Two Editors Side By Side.
// Programmatically split an editor area to show two editors side by side.
/**
* Split the editor area if there is at least two editors in it.
*/
private void splitEditorArea() {
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart part = workbenchPage.getActivePart();
PartPane partPane = ((PartSite) part.getSite()).getPane();
LayoutPart layoutPart = partPane.getPart();
IEditorReference[] editorReferences = workbenchPage.getEditorReferences();
// Do it only if we have more that one editor
if (editorReferences.length > 1) {
// Get PartPane that correspond to the active editor
PartPane currentEditorPartPane = ((PartSite) workbenchPage.getActiveEditor().getSite()).getPane();
EditorSashContainer editorSashContainer = null;
ILayoutContainer rootLayoutContainer = layoutPart.getContainer();
if (rootLayoutContainer instanceof LayoutPart) {
ILayoutContainer editorSashLayoutContainer = ((LayoutPart) rootLayoutContainer).getContainer();
if (editorSashLayoutContainer instanceof EditorSashContainer) {
editorSashContainer = ((EditorSashContainer) editorSashLayoutContainer);
}
}
/*
* Create a new part stack (i.e. a workbook) to home the
* currentEditorPartPane which hold the active editor
*/
PartStack newPart = createStack(editorSashContainer);
editorSashContainer.stack(currentEditorPartPane, newPart);
if (rootLayoutContainer instanceof LayoutPart) {
ILayoutContainer cont = ((LayoutPart) rootLayoutContainer).getContainer();
if (cont instanceof PartSashContainer) {
// "Split" the editor area by adding the new part
((PartSashContainer) cont).add(newPart);
}
}
}
}
/**
* A method to create a part stack container (a new workbook)
*
* @param editorSashContainer the EditorSashContainer
to set for the returned
PartStack
* @return a new part stack container
*/
private PartStack createStack(EditorSashContainer editorSashContainer) {
WorkbenchPage workbenchPage = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
EditorStack newWorkbook = EditorStack.newEditorWorkbook(editorSashContainer, workbenchPage);
return newWorkbook;
}





