001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.plugin;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IProject;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExecutableExtension;
018: import org.eclipse.core.runtime.IExtension;
019: import org.eclipse.core.runtime.IExtensionPoint;
020: import org.eclipse.core.runtime.IExtensionRegistry;
021: import org.eclipse.core.runtime.IPath;
022: import org.eclipse.core.runtime.Platform;
023: import org.eclipse.jface.dialogs.IDialogSettings;
024: import org.eclipse.jface.wizard.IWizardPage;
025: import org.eclipse.pde.internal.ui.PDEPlugin;
026: import org.eclipse.pde.internal.ui.PDEPluginImages;
027: import org.eclipse.pde.internal.ui.PDEUIMessages;
028: import org.eclipse.pde.internal.ui.elements.ElementList;
029: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
030: import org.eclipse.pde.internal.ui.wizards.NewWizard;
031: import org.eclipse.pde.internal.ui.wizards.WizardElement;
032: import org.eclipse.pde.ui.IPluginContentWizard;
033: import org.eclipse.swt.graphics.Image;
034: import org.eclipse.ui.IWorkingSet;
035: import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
036:
037: public class NewPluginProjectWizard extends NewWizard implements
038: IExecutableExtension {
039: public static final String PLUGIN_POINT = "pluginContent"; //$NON-NLS-1$
040: public static final String TAG_WIZARD = "wizard"; //$NON-NLS-1$
041: public static final String DEF_PROJECT_NAME = "project_name"; //$NON-NLS-1$
042: public static final String DEF_TEMPLATE_ID = "template-id"; //$NON-NLS-1$
043:
044: private IConfigurationElement fConfig;
045: private PluginFieldData fPluginData;
046: private IProjectProvider fProjectProvider;
047: private NewProjectCreationPage fMainPage;
048: private PluginContentPage fContentPage;
049: private TemplateListSelectionPage fWizardListPage;
050: private boolean fPureOSGi;
051:
052: public NewPluginProjectWizard() {
053: setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWPPRJ_WIZ);
054: setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
055: setWindowTitle(PDEUIMessages.NewProjectWizard_title);
056: setNeedsProgressMonitor(true);
057: PDEPlugin.getDefault().getLabelProvider().connect(this );
058: fPluginData = new PluginFieldData();
059: }
060:
061: public NewPluginProjectWizard(String osgiFramework) {
062: this ();
063: fPluginData.setOSGiFramework(osgiFramework);
064: }
065:
066: /* (non-Javadoc)
067: * @see org.eclipse.jface.wizard.Wizard#addPages()
068: */
069: public void addPages() {
070: fMainPage = new NewProjectCreationPage(
071: "main", fPluginData, fPureOSGi, getSelection()); //$NON-NLS-1$
072: fMainPage
073: .setTitle(PDEUIMessages.NewProjectWizard_MainPage_title);
074: fMainPage
075: .setDescription(PDEUIMessages.NewProjectWizard_MainPage_desc);
076: String pname = getDefaultValue(DEF_PROJECT_NAME);
077: if (pname != null)
078: fMainPage.setInitialProjectName(pname);
079: addPage(fMainPage);
080:
081: fProjectProvider = new IProjectProvider() {
082: public String getProjectName() {
083: return fMainPage.getProjectName();
084: }
085:
086: public IProject getProject() {
087: return fMainPage.getProjectHandle();
088: }
089:
090: public IPath getLocationPath() {
091: return fMainPage.getLocationPath();
092: }
093: };
094:
095: fContentPage = new PluginContentPage(
096: "page2", fProjectProvider, fMainPage, fPluginData); //$NON-NLS-1$
097:
098: fWizardListPage = new TemplateListSelectionPage(
099: getAvailableCodegenWizards(), fContentPage,
100: PDEUIMessages.WizardListSelectionPage_templates);
101: String tid = getDefaultValue(DEF_TEMPLATE_ID);
102: if (tid != null)
103: fWizardListPage.setInitialTemplateId(tid);
104:
105: addPage(fContentPage);
106: addPage(fWizardListPage);
107: }
108:
109: /* (non-Javadoc)
110: * @see org.eclipse.jface.wizard.Wizard#canFinish()
111: */
112: public boolean canFinish() {
113: IWizardPage page = getContainer().getCurrentPage();
114: return super .canFinish() && page != fMainPage;
115: }
116:
117: /*
118: * (non-Javadoc)
119: *
120: * @see org.eclipse.pde.internal.ui.wizards.NewWizard#performFinish()
121: */
122: public boolean performFinish() {
123: try {
124: fMainPage.updateData();
125: fContentPage.updateData();
126: IDialogSettings settings = getDialogSettings();
127: if (settings != null) {
128: fMainPage.saveSettings(settings);
129: fContentPage.saveSettings(settings);
130: }
131: BasicNewProjectResourceWizard.updatePerspective(fConfig);
132: IPluginContentWizard contentWizard = fWizardListPage
133: .getSelectedWizard();
134: getContainer().run(
135: false,
136: true,
137: new NewProjectCreationOperation(fPluginData,
138: fProjectProvider, contentWizard));
139:
140: IWorkingSet[] workingSets = fMainPage
141: .getSelectedWorkingSets();
142: getWorkbench().getWorkingSetManager().addToWorkingSets(
143: fProjectProvider.getProject(), workingSets);
144:
145: return true;
146: } catch (InvocationTargetException e) {
147: PDEPlugin.logException(e);
148: } catch (InterruptedException e) {
149: }
150: return false;
151: }
152:
153: /* (non-Javadoc)
154: * @see org.eclipse.jface.wizard.Wizard#dispose()
155: */
156: public void dispose() {
157: super .dispose();
158: PDEPlugin.getDefault().getLabelProvider().disconnect(this );
159: }
160:
161: /* (non-Javadoc)
162: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
163: */
164: public void setInitializationData(IConfigurationElement config,
165: String propertyName, Object data) throws CoreException {
166: fConfig = config;
167: }
168:
169: protected WizardElement createWizardElement(
170: IConfigurationElement config) {
171: String name = config.getAttribute(WizardElement.ATT_NAME);
172: String id = config.getAttribute(WizardElement.ATT_ID);
173: String className = config.getAttribute(WizardElement.ATT_CLASS);
174: if (name == null || id == null || className == null)
175: return null;
176: WizardElement element = new WizardElement(config);
177: String imageName = config.getAttribute(WizardElement.ATT_ICON);
178: if (imageName != null) {
179: String pluginID = config.getNamespaceIdentifier();
180: Image image = PDEPlugin.getDefault().getLabelProvider()
181: .getImageFromPlugin(pluginID, imageName);
182: element.setImage(image);
183: }
184: return element;
185: }
186:
187: public ElementList getAvailableCodegenWizards() {
188: ElementList wizards = new ElementList("CodegenWizards"); //$NON-NLS-1$
189: IExtensionRegistry registry = Platform.getExtensionRegistry();
190: IExtensionPoint point = registry.getExtensionPoint(PDEPlugin
191: .getPluginId(), PLUGIN_POINT);
192: if (point == null)
193: return wizards;
194: IExtension[] extensions = point.getExtensions();
195: for (int i = 0; i < extensions.length; i++) {
196: IConfigurationElement[] elements = extensions[i]
197: .getConfigurationElements();
198: for (int j = 0; j < elements.length; j++) {
199: if (elements[j].getName().equals(TAG_WIZARD)) {
200: WizardElement element = createWizardElement(elements[j]);
201: if (element != null) {
202: wizards.add(element);
203: }
204: }
205: }
206: }
207: return wizards;
208: }
209:
210: public String getPluginId() {
211: return fPluginData.getId();
212: }
213:
214: }
|