Skip to content

Commit 74cdc56

Browse files
committed
Add support for switching to recommended perspective
1 parent d6d3c7b commit 74cdc56

8 files changed

Lines changed: 56 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
class="com.google.cloud.tools.eclipse.util.service.ServiceContextFactory:com.google.cloud.tools.eclipse.appengine.newproject.flex.AppEngineFlexProjectWizard"
3636
icon="platform:/plugin/com.google.cloud.tools.eclipse.appengine.ui/icons/gae-16x16.png"
3737
project="true"
38+
finalPerspective="org.eclipse.jst.j2ee.J2EEPerspective"
39+
preferredPerspectives="org.eclipse.jst.j2ee.J2EEPerspective,org.eclipse.wst.web.ui.webDevPerspective"
3840
category="com.google.cloud.tools.eclipse.appengine.wizards">
3941
<description>%flexWizardDescription</description>
4042
<selection class="org.eclipse.core.resources.IResource"/>

plugins/com.google.cloud.tools.eclipse.appengine.newproject.maven/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Require-Bundle: com.google.cloud.tools.appengine;bundle-version="0.2.6",
2020
org.eclipse.core.jobs,
2121
org.eclipse.m2e.core;bundle-version="1.6.2",
2222
org.eclipse.m2e.core.ui;bundle-version="1.6.2",
23-
org.eclipse.m2e.maven.runtime
23+
org.eclipse.m2e.maven.runtime,
24+
org.eclipse.equinox.registry
2425
Bundle-ActivationPolicy: lazy
2526
Import-Package: com.google.cloud.tools.eclipse.appengine.facets,
2627
com.google.cloud.tools.eclipse.appengine.libraries.model,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class="com.google.cloud.tools.eclipse.appengine.newproject.maven.MavenArchetypeProjectWizard"
99
icon="platform:/plugin/com.google.cloud.tools.eclipse.appengine.ui/icons/gae-16x16.png"
1010
project="true"
11+
finalPerspective="org.eclipse.jst.j2ee.J2EEPerspective"
12+
preferredPerspectives="org.eclipse.jst.j2ee.J2EEPerspective,org.eclipse.wst.web.ui.webDevPerspective"
1113
category="com.google.cloud.tools.eclipse.appengine.wizards">
1214
<description>%mavenwizard.description</description>
1315
<selection class="org.eclipse.core.resources.IResource"/>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
3131
import java.io.File;
3232
import java.lang.reflect.InvocationTargetException;
33-
3433
import org.eclipse.core.resources.IFile;
34+
import org.eclipse.core.runtime.CoreException;
35+
import org.eclipse.core.runtime.IConfigurationElement;
36+
import org.eclipse.core.runtime.IExecutableExtension;
3537
import org.eclipse.core.runtime.IProgressMonitor;
3638
import org.eclipse.core.runtime.IStatus;
3739
import org.eclipse.core.runtime.Status;
@@ -40,12 +42,15 @@
4042
import org.eclipse.jface.wizard.Wizard;
4143
import org.eclipse.ui.INewWizard;
4244
import org.eclipse.ui.IWorkbench;
45+
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
4346

44-
public class MavenArchetypeProjectWizard extends Wizard implements INewWizard {
47+
public class MavenArchetypeProjectWizard extends Wizard
48+
implements INewWizard, IExecutableExtension {
4549
private MavenAppEngineStandardWizardPage page;
4650
private MavenAppEngineStandardArchetypeWizardPage archetypePage;
4751
private File cloudSdkLocation;
4852
private IWorkbench workbench;
53+
private IConfigurationElement configElement;
4954

5055
public MavenArchetypeProjectWizard() {
5156
setWindowTitle(Messages.getString("WIZARD_TITLE")); //$NON-NLS-1$
@@ -112,8 +117,12 @@ public void run(IProgressMonitor monitor)
112117
boolean cancelable = true;
113118
getContainer().run(fork, cancelable, runnable);
114119

120+
// prompt to switch to preferred perspective
121+
BasicNewProjectResourceWizard.updatePerspective(configElement);
122+
115123
// open most important file created by wizard in editor
116124
IFile file = operation.getMostImportant();
125+
BasicNewProjectResourceWizard.selectAndReveal(file, workbench.getActiveWorkbenchWindow());
117126
WorkbenchUtil.openInEditor(workbench, file);
118127

119128
} catch (InterruptedException ex) {
@@ -136,4 +145,10 @@ public void init(IWorkbench workbench, IStructuredSelection selection) {
136145
}
137146
}
138147

148+
@Override
149+
public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
150+
throws CoreException {
151+
this.configElement = config;
152+
}
153+
139154
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
<plugin>
44
<extension point="org.eclipse.ui.newWizards">
55
<wizard
6-
id="com.google.cloud.tools.eclipse.appengine.newproject.AppEngineStandard"
7-
name="%wizard.name"
8-
class="com.google.cloud.tools.eclipse.util.service.ServiceContextFactory:com.google.cloud.tools.eclipse.appengine.newproject.standard.AppEngineStandardProjectWizard"
9-
icon="platform:/plugin/com.google.cloud.tools.eclipse.appengine.ui/icons/gae-16x16.png"
10-
project="true"
11-
category="com.google.cloud.tools.eclipse.appengine.wizards">
6+
category="com.google.cloud.tools.eclipse.appengine.wizards"
7+
icon="platform:/plugin/com.google.cloud.tools.eclipse.appengine.ui/icons/gae-16x16.png"
8+
id="com.google.cloud.tools.eclipse.appengine.newproject.AppEngineStandard"
9+
name="%wizard.name"
10+
class="com.google.cloud.tools.eclipse.util.service.ServiceContextFactory:com.google.cloud.tools.eclipse.appengine.newproject.standard.AppEngineStandardProjectWizard"
11+
finalPerspective="org.eclipse.jst.j2ee.J2EEPerspective"
12+
preferredPerspectives="org.eclipse.jst.j2ee.J2EEPerspective,org.eclipse.wst.web.ui.webDevPerspective"
13+
project="true">
1214
<description>%wizard.description</description>
1315
<selection class="org.eclipse.core.resources.IResource"/>
1416
<keywordReference id="com.google.cloud.tools.eclipse.appengine.ui.GCPKeyword"/>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,33 @@
2626
import com.google.cloud.tools.eclipse.sdk.ui.preferences.CloudSdkPrompter;
2727
import com.google.cloud.tools.eclipse.ui.util.WorkbenchUtil;
2828
import com.google.cloud.tools.eclipse.usagetracker.AnalyticsEvents;
29+
import com.google.cloud.tools.eclipse.util.service.ServiceContextFactory;
2930
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
3031
import java.io.File;
3132
import java.lang.reflect.InvocationTargetException;
33+
import javax.inject.Inject;
3234
import org.eclipse.core.resources.IFile;
3335
import org.eclipse.core.runtime.IAdaptable;
36+
import org.eclipse.core.runtime.IConfigurationElement;
3437
import org.eclipse.core.runtime.IStatus;
3538
import org.eclipse.core.runtime.Status;
3639
import org.eclipse.jface.viewers.IStructuredSelection;
3740
import org.eclipse.jface.wizard.Wizard;
3841
import org.eclipse.ui.INewWizard;
3942
import org.eclipse.ui.IWorkbench;
4043
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
44+
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
4145

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

4449
private AppEngineWizardPage page = null;
4550
private AppEngineProjectConfig config = new AppEngineProjectConfig();
4651
private IWorkbench workbench;
4752

53+
@Inject
54+
protected IConfigurationElement configElement;
55+
4856
public AppEngineProjectWizard() {
4957
setNeedsProgressMonitor(true);
5058
}
@@ -107,8 +115,12 @@ public boolean performFinish() {
107115
try {
108116
getContainer().run(fork, cancelable, runnable);
109117

118+
// prompt to switch to preferred perspective
119+
BasicNewProjectResourceWizard.updatePerspective(configElement);
120+
110121
// open most important file created by wizard in editor
111122
IFile file = runnable.getMostImportant();
123+
BasicNewProjectResourceWizard.selectAndReveal(file, workbench.getActiveWorkbenchWindow());
112124
WorkbenchUtil.openInEditor(workbench, file);
113125
} catch (InterruptedException ex) {
114126
status = Status.CANCEL_STATUS;

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
@@ -47,6 +47,9 @@ public static void setUp() throws Exception {
4747
} catch (WidgetNotFoundException ex) {
4848
// may receive WNFE: "There is no active view"
4949
}
50+
51+
// switch to J2EE to avoid new-project switch-perspective prompts
52+
bot.perspectiveById("org.eclipse.jst.j2ee.J2EEPerspective").activate();
5053
}
5154

5255
@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
@@ -1,5 +1,6 @@
11
package com.google.cloud.tools.eclipse.util.service;
22

3+
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
34
import org.eclipse.core.runtime.CoreException;
45
import org.eclipse.core.runtime.IConfigurationElement;
56
import org.eclipse.core.runtime.IExecutableExtension;
@@ -12,18 +13,18 @@
1213
import org.osgi.framework.BundleContext;
1314
import org.osgi.framework.FrameworkUtil;
1415

15-
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
16-
1716
public class ServiceContextFactory implements IExecutableExtensionFactory, IExecutableExtension {
1817

1918
private Class<?> clazz;
19+
private IConfigurationElement configElement;
2020

2121
@Override
2222
public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
2323
throws CoreException {
2424
if (data == null || !(data instanceof String)) {
2525
throw new CoreException(StatusUtil.error(getClass(), "Data must be a class name"));
2626
}
27+
configElement = config;
2728
String className = (String) data;
2829
String bundleSymbolicName = config.getNamespaceIdentifier();
2930
Bundle bundle = Platform.getBundle(bundleSymbolicName);
@@ -44,6 +45,12 @@ public void setInitializationData(IConfigurationElement config, String propertyN
4445
public Object create() throws CoreException {
4546
BundleContext bundleContext = FrameworkUtil.getBundle(clazz).getBundleContext();
4647
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext);
47-
return ContextInjectionFactory.make(clazz, serviceContext);
48+
IEclipseContext staticContext = EclipseContextFactory.create();
49+
staticContext.set(IConfigurationElement.class, configElement);
50+
try {
51+
return ContextInjectionFactory.make(clazz, serviceContext, staticContext);
52+
} finally {
53+
staticContext.dispose();
54+
}
4855
}
4956
}

0 commit comments

Comments
 (0)