KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > plugin > NewPluginProjectWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.internal.ui.wizards.plugin;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IConfigurationElement;
19 import org.eclipse.core.runtime.IExecutableExtension;
20 import org.eclipse.core.runtime.IExtension;
21 import org.eclipse.core.runtime.IExtensionPoint;
22 import org.eclipse.core.runtime.IExtensionRegistry;
23 import org.eclipse.core.runtime.IPath;
24 import org.eclipse.core.runtime.Platform;
25 import org.eclipse.jface.dialogs.IDialogSettings;
26 import org.eclipse.jface.wizard.IWizardPage;
27 import org.eclipse.pde.internal.ui.PDEPlugin;
28 import org.eclipse.pde.internal.ui.PDEPluginImages;
29 import org.eclipse.pde.internal.ui.PDEUIMessages;
30 import org.eclipse.pde.internal.ui.elements.ElementList;
31 import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
32 import org.eclipse.pde.internal.ui.wizards.NewWizard;
33 import org.eclipse.pde.internal.ui.wizards.WizardElement;
34 import org.eclipse.pde.ui.IPluginContentWizard;
35 import org.eclipse.swt.graphics.Image;
36 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
37
38 public class NewPluginProjectWizard extends NewWizard implements IExecutableExtension {
39     public static final String JavaDoc PLUGIN_POINT = "pluginContent"; //$NON-NLS-1$
40
public static final String JavaDoc TAG_WIZARD = "wizard"; //$NON-NLS-1$
41
public static final String JavaDoc DEF_PROJECT_NAME = "project_name"; //$NON-NLS-1$
42
public static final String JavaDoc DEF_TEMPLATE_ID = "template-id"; //$NON-NLS-1$
43

44     private IConfigurationElement fConfig;
45     private PluginFieldData fPluginData;
46     private IProjectProvider fProjectProvider;
47     private NewProjectCreationPage fMainPage;
48     private PluginContentPage fContentPage;
49     private TemplateListSelectionPage fWizardListPage;
50     private boolean fPureOSGi;
51
52     public NewPluginProjectWizard() {
53         setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWPPRJ_WIZ);
54         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
55         setWindowTitle(PDEUIMessages.NewProjectWizard_title);
56         setNeedsProgressMonitor(true);
57         PDEPlugin.getDefault().getLabelProvider().connect(this);
58         fPluginData = new PluginFieldData();
59     }
60     
61     public NewPluginProjectWizard(String JavaDoc osgiFramework) {
62         this();
63         fPluginData.setOSGiFramework(osgiFramework);
64     }
65     
66     /* (non-Javadoc)
67      * @see org.eclipse.jface.wizard.Wizard#addPages()
68      */

69     public void addPages() {
70         fMainPage = new NewProjectCreationPage("main", fPluginData, fPureOSGi); //$NON-NLS-1$
71
fMainPage.setTitle(PDEUIMessages.NewProjectWizard_MainPage_title);
72         fMainPage.setDescription(PDEUIMessages.NewProjectWizard_MainPage_desc);
73         String JavaDoc pname = getDefaultValue(DEF_PROJECT_NAME);
74         if (pname!=null)
75             fMainPage.setInitialProjectName(pname);
76         addPage(fMainPage);
77         
78         fProjectProvider = new IProjectProvider() {
79             public String JavaDoc getProjectName() {
80                 return fMainPage.getProjectName();
81             }
82             public IProject getProject() {
83                 return fMainPage.getProjectHandle();
84             }
85             public IPath getLocationPath() {
86                 return fMainPage.getLocationPath();
87             }
88         };
89         
90         fContentPage = new PluginContentPage("page2", fProjectProvider, fMainPage, fPluginData); //$NON-NLS-1$
91

92         fWizardListPage = new TemplateListSelectionPage(getAvailableCodegenWizards(), fContentPage, PDEUIMessages.WizardListSelectionPage_templates);
93         String JavaDoc tid = getDefaultValue(DEF_TEMPLATE_ID);
94         if (tid!=null)
95             fWizardListPage.setInitialTemplateId(tid);
96
97         addPage(fContentPage);
98         addPage(fWizardListPage);
99     }
100     
101     
102     /* (non-Javadoc)
103      * @see org.eclipse.jface.wizard.Wizard#canFinish()
104      */

105     public boolean canFinish() {
106         IWizardPage page = getContainer().getCurrentPage();
107         return super.canFinish() && page != fMainPage;
108     }
109     /*
110      * (non-Javadoc)
111      *
112      * @see org.eclipse.pde.internal.ui.wizards.NewWizard#performFinish()
113      */

114     public boolean performFinish() {
115         try {
116             fMainPage.updateData();
117             fContentPage.updateData();
118             IDialogSettings settings = getDialogSettings();
119             if (settings != null) {
120                 fMainPage.saveSettings(settings);
121                 fContentPage.saveSettings(settings);
122             }
123             BasicNewProjectResourceWizard.updatePerspective(fConfig);
124             IPluginContentWizard contentWizard = fWizardListPage.getSelectedWizard();
125             getContainer().run(false, true,
126                     new NewProjectCreationOperation(fPluginData, fProjectProvider, contentWizard));
127             return true;
128         } catch (InvocationTargetException JavaDoc e) {
129             PDEPlugin.logException(e);
130         } catch (InterruptedException JavaDoc e) {
131         }
132         return false;
133     }
134     
135     /* (non-Javadoc)
136      * @see org.eclipse.jface.wizard.Wizard#dispose()
137      */

138     public void dispose() {
139         super.dispose();
140         PDEPlugin.getDefault().getLabelProvider().disconnect(this);
141     }
142
143     /* (non-Javadoc)
144      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
145      */

146     public void setInitializationData(IConfigurationElement config,
147             String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
148         fConfig = config;
149     }
150     
151     protected WizardElement createWizardElement(IConfigurationElement config) {
152         String JavaDoc name = config.getAttribute(WizardElement.ATT_NAME);
153         String JavaDoc id = config.getAttribute(WizardElement.ATT_ID);
154         String JavaDoc className = config.getAttribute(WizardElement.ATT_CLASS);
155         if (name == null || id == null || className == null)
156             return null;
157         WizardElement element = new WizardElement(config);
158         String JavaDoc imageName = config.getAttribute(WizardElement.ATT_ICON);
159         if (imageName != null) {
160             String JavaDoc pluginID = config.getNamespaceIdentifier();
161             Image image =
162                 PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
163             element.setImage(image);
164         }
165         return element;
166     }
167
168     public ElementList getAvailableCodegenWizards() {
169         ElementList wizards = new ElementList("CodegenWizards"); //$NON-NLS-1$
170
IExtensionRegistry registry = Platform.getExtensionRegistry();
171         IExtensionPoint point = registry.getExtensionPoint(PDEPlugin.getPluginId(), PLUGIN_POINT);
172         if (point == null)
173             return wizards;
174         IExtension[] extensions = point.getExtensions();
175         for (int i = 0; i < extensions.length; i++) {
176             IConfigurationElement[] elements =
177                 extensions[i].getConfigurationElements();
178             for (int j = 0; j < elements.length; j++) {
179                 if (elements[j].getName().equals(TAG_WIZARD)) {
180                     WizardElement element = createWizardElement(elements[j]);
181                     if (element != null) {
182                         wizards.add(element);
183                     }
184                 }
185             }
186         }
187         return wizards;
188     }
189     
190     public String JavaDoc getPluginId() {
191         return fPluginData.getId();
192     }
193     
194 }
195
Popular Tags