Tuesday, August 12, 2014

Opening eclipse editor or view in the dialog programatically

We can open eclipse editor or view in the dialog by using the Eclipse e4 model services. This is also called detaching the editors/views from the eclipse workbench.

For this, you need to have e4 workbench plugin and it provides org.eclipse.e4.ui.workbench.modeling API services.


IWorkbench workbench = ActivatorPlugin.getDefault().getWorkbench();

//get editorpart somehow which you wanted to open it.
EditorPart openEditor = /*IDE.openEditor(workbench.getActiveWorkbenchWindow().getActivePage(), module, MyEditorID, false); */

//get editor site
IWorkbenchPartSite site = openEditor.getSite();

//get model service for editor site
EModelService modelService = (EModelService) site.getService(EModelService.class);
MPartSashContainerElement  mpartService = (MPart) site.getService(MPart.class);

//invoke detach on model service with coordinates.
modelService.detach(mpartService, 100, 100, 700, 700);


For view:

//Get view part
IViewPart view = workbench.getActiveWorkbenchWindow().getActivePage().findView(MyPerspective.ExplorerView_ID);
//get site for view
//invoke detach


Resources:
http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-7-services/
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-9l.htm
http://mcuoneclipse.com/2012/02/29/go-multiply-and-detach-multiple-screens-with-eclipse/

No comments:

Post a Comment