Skip to content

Commit 2d3138d

Browse files
committed
Add support for switching to recommended perspective
1 parent 6a6ef5d commit 2d3138d

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

plugins/com.google.cloud.tools.eclipse.appengine.newproject/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
name="%standard.wizard.name"
1010
class="com.google.cloud.tools.eclipse.util.service.ServiceContextFactory:com.google.cloud.tools.eclipse.appengine.newproject.standard.AppEngineStandardProjectWizard"
1111
icon="platform:/plugin/com.google.cloud.tools.eclipse.appengine.ui/icons/gae-16x16.png"
12+
finalPerspective="org.eclipse.jst.j2ee.J2EEPerspective"
13+
preferredPerspectives="org.eclipse.jst.j2ee.J2EEPerspective,org.eclipse.wst.web.ui.webDevPerspective"
1214
project="true"
1315
category="com.google.cloud.tools.eclipse.wizards">
1416
<description>%standard.wizard.description</description>

plugins/com.google.cloud.tools.eclipse.appengine.newproject/src/com/google/cloud/tools/eclipse/appengine/newproject/AppEngineProjectWizard.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,34 @@
2525
import com.google.cloud.tools.eclipse.appengine.ui.CloudSdkOutOfDatePage;
2626
import com.google.cloud.tools.eclipse.sdk.ui.preferences.CloudSdkPrompter;
2727
import com.google.cloud.tools.eclipse.ui.util.WorkbenchUtil;
28+
import com.google.cloud.tools.eclipse.usagetracker.AnalyticsEvents;
29+
import com.google.cloud.tools.eclipse.util.service.ServiceContextFactory;
2830
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
2931
import com.google.common.base.Preconditions;
3032
import java.io.File;
3133
import java.lang.reflect.InvocationTargetException;
34+
import javax.inject.Inject;
3235
import org.eclipse.core.resources.IFile;
3336
import org.eclipse.core.runtime.IAdaptable;
37+
import org.eclipse.core.runtime.IConfigurationElement;
3438
import org.eclipse.core.runtime.IStatus;
3539
import org.eclipse.jface.viewers.IStructuredSelection;
3640
import org.eclipse.jface.wizard.Wizard;
3741
import org.eclipse.ui.INewWizard;
3842
import org.eclipse.ui.IWorkbench;
3943
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
44+
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
4045

46+
/** Expected to be created via the {@link ServiceContextFactory}. */
4147
public abstract class AppEngineProjectWizard extends Wizard implements INewWizard {
4248

4349
protected AppEngineWizardPage page = null;
4450
protected final AppEngineProjectConfig config = new AppEngineProjectConfig();
4551
private IWorkbench workbench;
4652

53+
@Inject
54+
protected IConfigurationElement configElement;
55+
4756
public AppEngineProjectWizard() {
4857
setNeedsProgressMonitor(true);
4958
}
@@ -97,8 +106,12 @@ public boolean performFinish() {
97106
boolean cancelable = true;
98107
getContainer().run(fork, cancelable, runnable);
99108

109+
// prompt to switch to preferred perspective
110+
BasicNewProjectResourceWizard.updatePerspective(configElement);
111+
100112
// open most important file created by wizard in editor
101113
IFile file = runnable.getMostImportant();
114+
BasicNewProjectResourceWizard.selectAndReveal(file, workbench.getActiveWorkbenchWindow());
102115
WorkbenchUtil.openInEditor(workbench, file);
103116
return true;
104117
} catch (InterruptedException ex) {

plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/BaseProjectTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public static void setUp() throws Exception {
4646
} catch (WidgetNotFoundException ex) {
4747
// may receive WNFE: "There is no active view"
4848
}
49+
50+
// switch to J2EE to avoid new-project switch-perspective prompts
51+
bot.perspectiveById("org.eclipse.jst.j2ee.J2EEPerspective").activate();
4952
}
5053

5154
@After

plugins/com.google.cloud.tools.eclipse.util/src/com/google/cloud/tools/eclipse/util/service/ServiceContextFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.tools.eclipse.util.service;
1818

19+
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
1920
import org.eclipse.core.runtime.CoreException;
2021
import org.eclipse.core.runtime.IConfigurationElement;
2122
import org.eclipse.core.runtime.IExecutableExtension;
@@ -28,18 +29,18 @@
2829
import org.osgi.framework.BundleContext;
2930
import org.osgi.framework.FrameworkUtil;
3031

31-
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
32-
3332
public class ServiceContextFactory implements IExecutableExtensionFactory, IExecutableExtension {
3433

3534
private Class<?> clazz;
35+
private IConfigurationElement configElement;
3636

3737
@Override
3838
public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
3939
throws CoreException {
4040
if (data == null || !(data instanceof String)) {
4141
throw new CoreException(StatusUtil.error(getClass(), "Data must be a class name"));
4242
}
43+
configElement = config;
4344
String className = (String) data;
4445
String bundleSymbolicName = config.getNamespaceIdentifier();
4546
Bundle bundle = Platform.getBundle(bundleSymbolicName);
@@ -60,6 +61,12 @@ public void setInitializationData(IConfigurationElement config, String propertyN
6061
public Object create() throws CoreException {
6162
BundleContext bundleContext = FrameworkUtil.getBundle(clazz).getBundleContext();
6263
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext);
63-
return ContextInjectionFactory.make(clazz, serviceContext);
64+
IEclipseContext staticContext = EclipseContextFactory.create();
65+
staticContext.set(IConfigurationElement.class, configElement);
66+
try {
67+
return ContextInjectionFactory.make(clazz, serviceContext, staticContext);
68+
} finally {
69+
staticContext.dispose();
70+
}
6471
}
6572
}

0 commit comments

Comments
 (0)