|
|
|
|
|
|
|
Re: friends of e4.ui...? [message #975157 is a reply to message #975051] |
Wed, 07 November 2012 16:49 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Thanks, I guess I'm mostly on safe grounds
FYI, this is the current snippet that works fine in my tool:
private IEditorPart createMyEditor(IPageSite site, FileEditorInput input) {
EPartService partService = (EPartService) site.getService(EPartService.class);
EModelService modelService = (EModelService) site.getService(EModelService.class);
MApplication parent = getApplication(partService);
// create an empty model:
MPart newEditorPart = partService.createPart(CompatibilityEditor.MODEL_ELEMENT_ID);
// create a new editor:
IWorkbenchWindow activeWbWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
WorkbenchPage workbenchPage = (WorkbenchPage)activeWbWindow.getActivePage();
EditorReference ref = workbenchPage.createEditorReferenceForPart(newEditorPart, input, MyEditor.ID, null);
if (ref == null) return null; // no hope: can't find reference for our editor
// provide constructor arguments for CompatibilityEditor via context (looks FRAGILE to me!!):
IEclipseContext newContext = parent.getContext().createChild();
newEditorPart.setContext(newContext);
newContext.set(EditorReference.class, ref);
newContext.set(MPart.class, newEditorPart);
// this creates the editor:
partService.showPart(newEditorPart, PartState.CREATE);
// show it in the "bottom" stack as defined in the perspectives "Java" and "My Perspective":
MPerspective activePerspective = modelService.getActivePerspective(getWindow(parent));
MUIElement bottomElement = modelService.find("bottom", activePerspective);
if (bottomElement instanceof MPartStack) {
MPartStack bottomStack = (MPartStack) bottomElement;
bottomStack.getChildren().add(newEditorPart);
bottomStack.setSelectedElement(newEditorPart);
}
return (IEditorPart) ((CompatibilityEditor)newEditorPart.getObject()).getEditor();
}
Without @SuppressWarnings("restriction") almost every single line in this method has a warning. At a closer look one of these warnings may actually be relevant even after E4 API have been declared. That's why suppressing the warning may be a bad idea...
cheers,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.04302 seconds