// Get the editor descriptor.
String editorID = getId();
EditorDescriptor desc = getDescriptor();
if (desc == null) {
throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_missing_editor_descriptor, editorID));
}
if (desc.isInternal()) {
// Create an editor instance.
try {
UIStats.start(UIStats.CREATE_PART, editorID);
part = manager.createPart(desc);
if (part != null && part instanceof MultiEditor) {
multiEditorChildren = manager.openMultiEditor(this,
(MultiEditor) part, (MultiEditorInput) editorInput);
}
if (part instanceof IWorkbenchPart3) {
createPartProperties((IWorkbenchPart3)part);
}
} finally {
UIStats.end(UIStats.CREATE_PART, this, editorID);
}
} else if (desc.getId().equals(
IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID)) {
part = ComponentSupport.getSystemInPlaceEditor();
if (part == null) {
throw new PartInitException(WorkbenchMessages.EditorManager_no_in_place_support);
}
} else {
throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_invalid_editor_descriptor, editorID));
}
// Create a pane for this part
PartPane pane = getPane();
pane.createControl((Composite) manager.page.getEditorPresentation().getLayoutPart().getControl());
// Create controls
int style = SWT.NONE;
if(part instanceof IWorkbenchPartOrientation){
style = ((IWorkbenchPartOrientation) part).getOrientation();
}
// Link everything up to the part reference (the part reference itself should not have
// been modified until this point)
site = manager.createSite(this, part, desc, editorInput);
// if there is saved state that's appropriate, pass it on
if (part instanceof IPersistableEditor && editorState != null) {
((IPersistableEditor) part).restoreState(editorState);
}
// Remember the site and the action bars (now that we've created them, we'll need to dispose
// them if an exception occurs)
actionBars = (EditorActionBars) site.getActionBars();
Composite parent = (Composite)pane.getControl();
content = new Composite(parent, style);
content.setLayout(new FillLayout());
try {
UIStats.start(UIStats.CREATE_PART_CONTROL, editorID);
part.createPartControl(content);
parent.layout(true);
} finally {
UIStats.end(UIStats.CREATE_PART_CONTROL, part, editorID);
}
// The editor should now be fully created. Exercise its public interface, and sanity-check
// it wherever possible. If it's going to throw exceptions or behave badly, it's much better
// that it does so now while we can still cancel creation of the part.
PartTester.testEditor(part);
return part;
} catch (Exception e) {
// Dispose anything which we allocated in the try block
if (content != null) {
try {
content.dispose();
} catch (RuntimeException re) {
StatusManager.getManager().handle(
StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
re));
}
}
if (part != null) {
try {
part.dispose();
} catch (RuntimeException re) {
StatusManager.getManager().handle(
StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
re));
}
}
if (actionBars != null) {
try {
manager.disposeEditorActionBars(actionBars);
} catch (RuntimeException re) {
StatusManager.getManager().handle(
StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
re));
}
}
if (site != null) {
try {
site.dispose();
} catch (RuntimeException re) {
StatusManager.getManager().handle(
StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
re));
}
}
throw new PartInitException(StatusUtil.getLocalizedMessage(e), StatusUtil.getCause(e));
}
}