diff options
author | Daniel Rolka | 2013-08-23 15:41:59 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-09-10 18:13:21 +0000 |
commit | f03b1d292b20177a4733468f5612334f3b2dd28c (patch) | |
tree | 6cd1400b584273188046005a4df89cc0bbdce28f | |
parent | 1cf22084d9083ff7160a1d7f04e0caab09bf7af8 (diff) | |
download | eclipse.platform.ui-f03b1d292b20177a4733468f5612334f3b2dd28c.tar.gz eclipse.platform.ui-f03b1d292b20177a4733468f5612334f3b2dd28c.tar.xz eclipse.platform.ui-f03b1d292b20177a4733468f5612334f3b2dd28c.zip |
Bug 377981 - -perspective at product program arguments is not working inI20130910-2000
4.2M6
Change-Id: I8401183784538b359577ad245730045a1a47fe80
Signed-off-by: Daniel Rolka <daniel.rolka@pl.ibm.com>
6 files changed, 127 insertions, 20 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/PerspectiveStackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/PerspectiveStackRenderer.java index 5356ba2ad3d..2598dcf8f69 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/PerspectiveStackRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/PerspectiveStackRenderer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 IBM Corporation and others. + * Copyright (c) 2009, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -120,8 +120,12 @@ public class PerspectiveStackRenderer extends LazyStackRenderer { // Force a context switch if (tabElement instanceof MPerspective) { - IEclipseContext context = persp.getContext(); - context.get(EPartService.class).switchPerspective(persp); + MPerspective selected = (MPerspective) tabElement.getParent() + .getSelectedElement(); + if (selected != null) { + IEclipseContext context = selected.getContext(); + context.get(EPartService.class).switchPerspective(selected); + } } // Move any other controls to 'limbo' diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java index 52f8e5e8400..b5d165908b7 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java @@ -238,6 +238,14 @@ public class E4Application implements IApplication { PostContextCreate.class, appContext, null); } } + + String forcedPerspectiveId = getArgValue("perspective", + applicationContext, false); + if (forcedPerspectiveId != null) { + appContext.set(E4Workbench.FORCED_PERSPECTIVE_ID, + forcedPerspectiveId); + } + // Create the app model and its context MApplication appModel = loadApplicationModel(applicationContext, appContext); diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/CommandLineOptionModelProcessor.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/CommandLineOptionModelProcessor.java new file mode 100644 index 00000000000..8921e270bc9 --- /dev/null +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/CommandLineOptionModelProcessor.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2013 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.ui.internal.workbench; + +import java.util.List; +import javax.inject.Inject; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; +import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack; +import org.eclipse.e4.ui.workbench.modeling.EModelService; + +/** + * + */ +public class CommandLineOptionModelProcessor { + @Inject + private IEclipseContext context; + + @Inject + private MApplication application; + + @Inject + private EModelService modelService; + + @SuppressWarnings("javadoc") + public void process() { + selectForcedPerspective(); + } + + private void selectForcedPerspective() { + String forcedPerspectiveId = (String) context.get(E4Workbench.FORCED_PERSPECTIVE_ID); + if (forcedPerspectiveId == null) { + return; + } + + List<MPerspectiveStack> perspStackList = modelService.findElements(application, null, + MPerspectiveStack.class, null); + + if (perspStackList.isEmpty()) { + return; + } + + MPerspectiveStack perspStack = perspStackList.get(0); + MPerspective selected = perspStack.getSelectedElement(); + + if (selected != null && selected.getElementId().equals(forcedPerspectiveId)) { + return; + } + + for (MPerspective persp : perspStack.getChildren()) { + if (persp.getElementId().equals(forcedPerspectiveId)) { + perspStack.setSelectedElement(persp); + return; + } + } + } +} diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java index 5bec0c16f50..0c031aa3440 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java @@ -71,6 +71,12 @@ public class E4Workbench implements IWorkbench { * Value is: <code>dir</code> */ public static final String RTL_MODE = "dir"; //$NON-NLS-1$ + /** + * The argument for the perspective to activate <br> + * <br> + * Value is: <code>perspectiveId</code> + */ + public static final String FORCED_PERSPECTIVE_ID = "forcedPerspetiveId"; //$NON-NLS-1$ private final String id; private ServiceRegistration<?> osgiRegistration; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java index 177a9af2a14..11d200c8139 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java @@ -218,6 +218,12 @@ public class ResourceHandler implements IModelResourceHandler { context); contribProcessor.processModel(); + if (!clearPersistedState) { + CommandLineOptionModelProcessor processor = ContextInjectionFactory.make( + CommandLineOptionModelProcessor.class, context); + processor.process(); + } + return resource; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java index ccff10a7b8a..b3846c5b97f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java @@ -47,6 +47,7 @@ import org.eclipse.e4.core.di.InjectionException; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.core.services.log.Logger; +import org.eclipse.e4.ui.internal.workbench.E4Workbench; import org.eclipse.e4.ui.internal.workbench.PartServiceSaveHandler; import org.eclipse.e4.ui.internal.workbench.URIHelper; import org.eclipse.e4.ui.internal.workbench.renderers.swt.IUpdateService; @@ -121,6 +122,7 @@ import org.eclipse.ui.IPageListener; import org.eclipse.ui.IPageService; import org.eclipse.ui.IPartService; import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IPerspectiveRegistry; import org.eclipse.ui.ISaveablePart; import org.eclipse.ui.ISelectionService; import org.eclipse.ui.ISources; @@ -590,23 +592,6 @@ public class WorkbenchWindow implements IWorkbenchWindow { fillActionBars(FILL_ALL_ACTION_BARS); firePageOpened(); - List<MPerspectiveStack> ps = modelService.findElements(model, null, - MPerspectiveStack.class, null); - MPerspective curPersp = null; - boolean newWindow = true; - if (ps.size() > 0) { - MPerspectiveStack stack = ps.get(0); - if (stack.getSelectedElement() != null) { - curPersp = stack.getSelectedElement(); - IPerspectiveDescriptor thePersp = getWorkbench().getPerspectiveRegistry() - .findPerspectiveWithId(curPersp.getElementId()); - if (thePersp != null) { - perspective = thePersp; - newWindow = false; - } - } - } - populateTopTrimContributions(); populateBottomTrimContributions(); @@ -669,8 +654,10 @@ public class WorkbenchWindow implements IWorkbenchWindow { eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, windowWidgetHandler); + boolean newWindow = setupPerspectiveStack(windowContext); page.setPerspective(perspective); firePageActivated(); + if (newWindow) { page.fireInitialPartVisibilityEvents(); } else { @@ -712,6 +699,35 @@ public class WorkbenchWindow implements IWorkbenchWindow { contextService.registerShell(shell, IContextService.TYPE_WINDOW); } + private boolean setupPerspectiveStack(IEclipseContext context) { + IPerspectiveRegistry registry = getWorkbench().getPerspectiveRegistry(); + String forcedPerspectiveId = (String) context.get(E4Workbench.FORCED_PERSPECTIVE_ID); + + if (forcedPerspectiveId != null) { + perspective = registry.findPerspectiveWithId(forcedPerspectiveId); + } + + List<MPerspectiveStack> perspStackList = modelService.findElements(model, null, + MPerspectiveStack.class, null); + MPerspective selectedPersp = null; + + if (!perspStackList.isEmpty()) { + selectedPersp = perspStackList.get(0).getSelectedElement(); + } + + if (forcedPerspectiveId == null && selectedPersp != null) { + perspective = registry.findPerspectiveWithId(selectedPersp.getElementId()); + } + + if (perspective == null) { + perspective = registry.findPerspectiveWithId(registry.getDefaultPerspective()); + } + + // the perspective stack doesn't have a selected element what means that + // we have a new window + return selectedPersp == null; + } + private boolean manageChanges = true; private boolean canUpdateMenus = true; |