stateMem = memento.getChild(IWorkbenchConstants.TAG_VIEW_STATE);
}
IViewDescriptor desc = factory.viewReg.find(getId());
if (desc == null) {
throw new PartInitException(
WorkbenchMessages.ViewFactory_couldNotCreate);
}
// Create the part pane
PartPane pane = getPane();
// Create the pane's top-level control
pane.createControl(factory.page.getClientComposite());
String label = desc.getLabel(); // debugging only
// Things that will need to be disposed if an exception occurs (they are
// listed here
// in the order they should be disposed)
Composite content = null;
IViewPart initializedView = null;
ViewSite site = null;
ViewActionBars actionBars = null;
// End of things that need to be explicitly disposed from the try block
try {
IViewPart view = null;
try {
UIStats.start(UIStats.CREATE_PART, label);
view = desc.createView();
} finally {
UIStats.end(UIStats.CREATE_PART, view, label);
}
if (view instanceof IWorkbenchPart3) {
createPartProperties((IWorkbenchPart3)view);
}
// Create site
site = new ViewSite(this, view, factory.page, desc);
actionBars = new ViewActionBars(factory.page.getActionBars(), site,
(ViewPane) pane);
site.setActionBars(actionBars);
try {
UIStats.start(UIStats.INIT_PART, label);
view.init(site, stateMem);
// Once we've called init, we MUST dispose the view. Remember
// the fact that
// we've initialized the view in case an exception is thrown.
initializedView = view;
} finally {
UIStats.end(UIStats.INIT_PART, view, label);
}
if (view.getSite() != site) {
throw new PartInitException(
WorkbenchMessages.ViewFactory_siteException, null);
}
int style = SWT.NONE;
if (view instanceof IWorkbenchPartOrientation) {
style = ((IWorkbenchPartOrientation) view).getOrientation();
}
// Create the top-level composite
{
Composite parent = (Composite) pane.getControl();
content = new Composite(parent, style);
content.setLayout(new FillLayout());
try {
UIStats.start(UIStats.CREATE_PART_CONTROL, label);
view.createPartControl(content);
parent.layout(true);
} finally {
UIStats.end(UIStats.CREATE_PART_CONTROL, view, label);
}
}
// Install the part's tools and menu
{
//
// 3.3 start
//
IMenuService menuService = (IMenuService) site
.getService(IMenuService.class);
menuService.populateContributionManager(
(ContributionManager) site.getActionBars()
.getMenuManager(), "menu:" //$NON-NLS-1$
+ site.getId());
menuService
.populateContributionManager((ContributionManager) site
.getActionBars().getToolBarManager(),
"toolbar:" + site.getId()); //$NON-NLS-1$
// 3.3 end
actionBuilder = new ViewActionBuilder();
actionBuilder.readActionExtensions(view);
ActionDescriptor[] actionDescriptors = actionBuilder
.getExtendedActions();
IKeyBindingService keyBindingService = view.getSite()
.getKeyBindingService();
if (actionDescriptors != null) {
for (int i = 0; i < actionDescriptors.length; i++) {
ActionDescriptor actionDescriptor = actionDescriptors[i];
if (actionDescriptor != null) {
IAction action = actionDescriptors[i].getAction();
if (action != null
&& action.getActionDefinitionId() != null) {
keyBindingService.registerAction(action);
}
}
}
}
site.getActionBars().updateActionBars();
}
// 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.testView(view);
result = view;
IConfigurationElement element = (IConfigurationElement) Util.getAdapter(desc,
IConfigurationElement.class);
if (element != null) {
factory.page.getExtensionTracker().registerObject(
element.getDeclaringExtension(), view,
IExtensionTracker.REF_WEAK);
}
} catch (Throwable e) {
if ((e instanceof Error) && !(e instanceof LinkageError)) {
throw (Error) e;
}
// An exception occurred. First deallocate anything we've allocated
// in the try block (see the top
// of the try block for a list of objects that need to be explicitly
// disposed)
if (content != null) {
try {
content.dispose();
} catch (RuntimeException re) {
StatusManager.getManager().handle(
StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
re));
}
}
if (initializedView != null) {
try {
initializedView.dispose();
} 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));
}
}
if (actionBars != null) {
try {
actionBars.dispose();
} catch (RuntimeException re) {
StatusManager.getManager().handle(
StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
re));
}
}
throw new PartInitException(WorkbenchPlugin.getStatus(e));
}
return result;
}