r.y = boundsMem.getInteger(IWorkbenchConstants.TAG_Y).intValue();
r.height = boundsMem.getInteger(IWorkbenchConstants.TAG_HEIGHT)
.intValue();
r.width = boundsMem.getInteger(IWorkbenchConstants.TAG_WIDTH)
.intValue();
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
if (page.getWorkbenchWindow().getPages().length == 0) {
page.getWorkbenchWindow().getShell().setBounds(r);
}
}
});
}
// Create an empty presentation..
final PerspectiveHelper [] presArray = new PerspectiveHelper[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
ViewSashContainer mainLayout = new ViewSashContainer(page, getClientComposite());
presArray[0] = new PerspectiveHelper(page, mainLayout, Perspective.this);
}});
final PerspectiveHelper pres = presArray[0];
// Read the layout.
result.merge(pres.restoreState(memento
.getChild(IWorkbenchConstants.TAG_LAYOUT)));
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
// Add the editor workbook. Do not hide it now.
pres.replacePlaceholderWithPart(editorArea);
}});
// Add the visible views.
IMemento[] views = memento.getChildren(IWorkbenchConstants.TAG_VIEW);
for (int x = 0; x < views.length; x++) {
// Get the view details.
IMemento childMem = views[x];
String id = childMem.getString(IWorkbenchConstants.TAG_ID);
String secondaryId = ViewFactory.extractSecondaryId(id);
if (secondaryId != null) {
id = ViewFactory.extractPrimaryId(id);
}
// skip the intro as it is restored higher up in workbench.
if (id.equals(IIntroConstants.INTRO_VIEW_ID)) {
continue;
}
// Create and open the view.
IViewReference viewRef = viewFactory.getView(id, secondaryId);
WorkbenchPartReference ref = (WorkbenchPartReference) viewRef;
// report error
if (ref == null) {
String key = ViewFactory.getKey(id, secondaryId);
result.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0,
NLS.bind(WorkbenchMessages.Perspective_couldNotFind, key ), null));
continue;
}
boolean willPartBeVisible = pres.willPartBeVisible(ref.getId(),
secondaryId);
if (willPartBeVisible) {
IViewPart view = (IViewPart) ref.getPart(true);
if (view != null) {
ViewSite site = (ViewSite) view.getSite();
ViewPane pane = (ViewPane) site.getPane();
pres.replacePlaceholderWithPart(pane);
}
} else {
pres.replacePlaceholderWithPart(ref.getPane());
}
}
// Load the fast views
if (fastViewManager != null)
fastViewManager.restoreState(memento, result);
// Load the view layout recs
IMemento[] recMementos = memento
.getChildren(IWorkbenchConstants.TAG_VIEW_LAYOUT_REC);
for (int i = 0; i < recMementos.length; i++) {
IMemento recMemento = recMementos[i];
String compoundId = recMemento
.getString(IWorkbenchConstants.TAG_ID);
if (compoundId != null) {
ViewLayoutRec rec = getViewLayoutRec(compoundId, true);
if (IWorkbenchConstants.FALSE.equals(recMemento
.getString(IWorkbenchConstants.TAG_CLOSEABLE))) {
rec.isCloseable = false;
}
if (IWorkbenchConstants.FALSE.equals(recMemento
.getString(IWorkbenchConstants.TAG_MOVEABLE))) {
rec.isMoveable = false;
}
if (IWorkbenchConstants.TRUE.equals(recMemento
.getString(IWorkbenchConstants.TAG_STANDALONE))) {
rec.isStandalone = true;
rec.showTitle = !IWorkbenchConstants.FALSE
.equals(recMemento
.getString(IWorkbenchConstants.TAG_SHOW_TITLE));
}
}
}
final IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class);
try { // one big try block, don't kill me here
// defer context events
if (service != null) {
service.activateContext(ContextAuthority.DEFER_EVENTS);
}
HashSet knownActionSetIds = new HashSet();
// Load the always on action sets.
IMemento[] actions = memento
.getChildren(IWorkbenchConstants.TAG_ALWAYS_ON_ACTION_SET);
for (int x = 0; x < actions.length; x++) {
String actionSetID = actions[x]
.getString(IWorkbenchConstants.TAG_ID);
final IActionSetDescriptor d = WorkbenchPlugin.getDefault()
.getActionSetRegistry().findActionSet(actionSetID);
if (d != null) {
StartupThreading
.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
addAlwaysOn(d);
}
});
knownActionSetIds.add(actionSetID);
}
}
// Load the always off action sets.
actions = memento
.getChildren(IWorkbenchConstants.TAG_ALWAYS_OFF_ACTION_SET);
for (int x = 0; x < actions.length; x++) {
String actionSetID = actions[x]
.getString(IWorkbenchConstants.TAG_ID);
final IActionSetDescriptor d = WorkbenchPlugin.getDefault()
.getActionSetRegistry().findActionSet(actionSetID);
if (d != null) {
StartupThreading
.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
addAlwaysOff(d);
}
});
knownActionSetIds.add(actionSetID);
}
}
// Load "show view actions".
actions = memento
.getChildren(IWorkbenchConstants.TAG_SHOW_VIEW_ACTION);
showViewShortcuts = new ArrayList(actions.length);
for (int x = 0; x < actions.length; x++) {
String id = actions[x].getString(IWorkbenchConstants.TAG_ID);
showViewShortcuts.add(id);
}
// Load "show in times".
actions = memento.getChildren(IWorkbenchConstants.TAG_SHOW_IN_TIME);
for (int x = 0; x < actions.length; x++) {
String id = actions[x].getString(IWorkbenchConstants.TAG_ID);
String timeStr = actions[x]
.getString(IWorkbenchConstants.TAG_TIME);
if (id != null && timeStr != null) {
try {
long time = Long.parseLong(timeStr);
showInTimes.put(id, new Long(time));
} catch (NumberFormatException e) {
// skip this one
}
}
}
// Load "show in parts" from registry, not memento
showInPartIds = getShowInIdsFromRegistry();
// Load "new wizard actions".
actions = memento
.getChildren(IWorkbenchConstants.TAG_NEW_WIZARD_ACTION);
newWizardShortcuts = new ArrayList(actions.length);
for (int x = 0; x < actions.length; x++) {
String id = actions[x].getString(IWorkbenchConstants.TAG_ID);
newWizardShortcuts.add(id);
}
// Load "perspective actions".
actions = memento
.getChildren(IWorkbenchConstants.TAG_PERSPECTIVE_ACTION);
perspectiveShortcuts = new ArrayList(actions.length);
for (int x = 0; x < actions.length; x++) {
String id = actions[x].getString(IWorkbenchConstants.TAG_ID);
perspectiveShortcuts.add(id);
}
ArrayList extActionSets = getPerspectiveExtensionActionSets();
for (int i = 0; i < extActionSets.size(); i++) {
String actionSetID = (String) extActionSets.get(i);
if (knownActionSetIds.contains(actionSetID)) {
continue;
}
final IActionSetDescriptor d = WorkbenchPlugin.getDefault()
.getActionSetRegistry().findActionSet(actionSetID);
if (d != null) {
StartupThreading
.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
addAlwaysOn(d);
}
});
knownActionSetIds.add(d.getId());
}
}
// Add the visible set of action sets to our knownActionSetIds
// Now go through the registry to ensure we pick up any new action
// sets
// that have been added but not yet considered by this perspective.
ActionSetRegistry reg = WorkbenchPlugin.getDefault()
.getActionSetRegistry();
IActionSetDescriptor[] array = reg.getActionSets();
int count = array.length;
for (int i = 0; i < count; i++) {
IActionSetDescriptor desc = array[i];
if ((!knownActionSetIds.contains(desc.getId()))
&& (desc.isInitiallyVisible())) {
addActionSet(desc);
}
}
} finally {
// restart context changes
if (service != null) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
service.activateContext(ContextAuthority.SEND_EVENTS);
}
});
}