Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.pde.ui.templates; |
12 |
|
13 |
import java.lang.reflect.InvocationTargetException; |
14 |
import org.eclipse.core.resources.IProject; |
15 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.jface.dialogs.IDialogSettings; |
17 |
import org.eclipse.pde.internal.ui.*; |
18 |
import org.eclipse.pde.internal.ui.wizards.*; |
19 |
import org.eclipse.pde.internal.ui.wizards.plugin.*; |
20 |
import org.eclipse.pde.ui.IPluginContentWizard; |
21 |
import org.eclipse.ui.IWorkingSet; |
22 |
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; |
23 |
|
24 |
/** |
25 |
* @since 3.5 |
26 |
* |
27 |
* |
28 |
*/ |
29 |
public abstract class NewPluginProjectFromTemplateWizard extends NewWizard implements IExecutableExtension { |
30 |
public static final String DEF_PROJECT_NAME = "project_name"; //$NON-NLS-1$ |
31 |
public static final String PLUGIN_POINT = "pluginContent"; //$NON-NLS-1$ |
32 |
public static final String TAG_WIZARD = "wizard"; //$NON-NLS-1$ |
33 |
|
34 |
private AbstractFieldData fPluginData; |
35 |
private NewProjectCreationPage fProjectPage; |
36 |
private PluginContentPage fContentPage; |
37 |
private IPluginContentWizard fTemplateWizard; |
38 |
private IProjectProvider fProjectProvider; |
39 |
private IConfigurationElement fConfig; |
40 |
|
41 |
public NewPluginProjectFromTemplateWizard() { |
42 |
setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWPPRJ_WIZ); |
43 |
setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); |
44 |
setWindowTitle(PDEUIMessages.NewProjectWizard_title); |
45 |
setNeedsProgressMonitor(true); |
46 |
fPluginData = new PluginFieldData(); |
47 |
} |
48 |
|
49 |
/* (non-Javadoc) |
50 |
* @see org.eclipse.jface.wizard.Wizard#addPages() |
51 |
*/ |
52 |
public void addPages() { |
53 |
WizardElement templateWizardElement = getTemplateWizard(); |
54 |
|
55 |
fProjectPage = new NewProjectCreationFromTemplatePage("main", fPluginData, getSelection(), templateWizardElement); //$NON-NLS-1$ |
56 |
fProjectPage.setTitle(PDEUIMessages.NewProjectWizard_MainPage_title); |
57 |
fProjectPage.setDescription(PDEUIMessages.NewProjectWizard_MainPage_desc); |
58 |
String projectName = getDefaultValue(DEF_PROJECT_NAME); |
59 |
if (projectName != null) |
60 |
fProjectPage.setInitialProjectName(projectName); |
61 |
addPage(fProjectPage); |
62 |
|
63 |
fProjectProvider = new IProjectProvider() { |
64 |
public String getProjectName() { |
65 |
return fProjectPage.getProjectName(); |
66 |
} |
67 |
|
68 |
public IProject getProject() { |
69 |
return fProjectPage.getProjectHandle(); |
70 |
} |
71 |
|
72 |
public IPath getLocationPath() { |
73 |
return fProjectPage.getLocationPath(); |
74 |
} |
75 |
}; |
76 |
|
77 |
fContentPage = new PluginContentPage("page2", fProjectProvider, fProjectPage, fPluginData); //$NON-NLS-1$ |
78 |
addPage(fContentPage); |
79 |
|
80 |
if (templateWizardElement != null) { |
81 |
// TODO When to init the data, no data at this time |
82 |
// TODO Throws an exception if failed |
83 |
try { |
84 |
fTemplateWizard = (IPluginContentWizard) templateWizardElement.createExecutableExtension(); |
85 |
fTemplateWizard.init(fPluginData); |
86 |
fTemplateWizard.addPages(); |
87 |
addPage(fTemplateWizard.getStartingPage()); |
88 |
} catch (CoreException e) { |
89 |
// TODO Deal with this |
90 |
PDEPlugin.log(e); |
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
/* (non-Javadoc) |
96 |
* @see org.eclipse.jface.wizard.Wizard#canFinish() |
97 |
*/ |
98 |
public boolean canFinish() { |
99 |
if (super.canFinish() && !getContainer().getCurrentPage().equals(fProjectPage)) { |
100 |
if (fTemplateWizard == null || fTemplateWizard.canFinish()) { |
101 |
return true; |
102 |
} |
103 |
} |
104 |
return false; |
105 |
} |
106 |
|
107 |
/* |
108 |
* (non-Javadoc) |
109 |
* |
110 |
* @see org.eclipse.pde.internal.ui.wizards.NewWizard#performFinish() |
111 |
*/ |
112 |
public boolean performFinish() { |
113 |
try { |
114 |
fProjectPage.updateData(); |
115 |
fContentPage.updateData(); |
116 |
IDialogSettings settings = getDialogSettings(); |
117 |
if (settings != null) { |
118 |
fProjectPage.saveSettings(settings); |
119 |
fContentPage.saveSettings(settings); |
120 |
} |
121 |
BasicNewProjectResourceWizard.updatePerspective(fConfig); |
122 |
getContainer().run(false, true, new NewProjectCreationOperation(fPluginData, fProjectProvider, fTemplateWizard)); |
123 |
|
124 |
IWorkingSet[] workingSets = fProjectPage.getSelectedWorkingSets(); |
125 |
if (workingSets.length > 0) |
126 |
getWorkbench().getWorkingSetManager().addToWorkingSets(fProjectProvider.getProject(), workingSets); |
127 |
|
128 |
return true; |
129 |
} catch (InvocationTargetException e) { |
130 |
PDEPlugin.logException(e); |
131 |
} catch (InterruptedException e) { |
132 |
} |
133 |
return false; |
134 |
} |
135 |
|
136 |
// TODO throw an exception if there is a problem? Provide the field data? |
137 |
protected abstract String getTemplateID(); |
138 |
|
139 |
/* (non-Javadoc) |
140 |
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) |
141 |
*/ |
142 |
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { |
143 |
fConfig = config; |
144 |
} |
145 |
|
146 |
private WizardElement getTemplateWizard() { |
147 |
String templateID = getTemplateID(); |
148 |
if (templateID == null) { |
149 |
return null; |
150 |
} |
151 |
|
152 |
IExtensionRegistry registry = Platform.getExtensionRegistry(); |
153 |
IExtensionPoint point = registry.getExtensionPoint(PDEPlugin.getPluginId(), PLUGIN_POINT); |
154 |
if (point == null) { |
155 |
return null; |
156 |
} |
157 |
IExtension[] extensions = point.getExtensions(); |
158 |
for (int i = 0; i < extensions.length; i++) { |
159 |
IConfigurationElement[] elements = extensions[i].getConfigurationElements(); |
160 |
for (int j = 0; j < elements.length; j++) { |
161 |
if (elements[j].getName().equals(TAG_WIZARD)) { |
162 |
if (templateID.equals(elements[j].getAttribute(WizardElement.ATT_ID))) { |
163 |
return WizardElement.create(elements[j]); |
164 |
} |
165 |
} |
166 |
} |
167 |
} |
168 |
return null; |
169 |
} |
170 |
|
171 |
} |