KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExecutableExtension;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.pde.internal.ui.PDEPlugin;
21 import org.eclipse.pde.internal.ui.PDEPluginImages;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
24 import org.eclipse.pde.internal.ui.wizards.NewWizard;
25 import org.eclipse.pde.internal.ui.wizards.WizardElement;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
28
29 public class NewLibraryPluginProjectWizard extends NewWizard implements
30         IExecutableExtension {
31     public static final String JavaDoc DEF_PROJECT_NAME = "project_name"; //$NON-NLS-1$
32

33     public static final String JavaDoc DEF_TEMPLATE_ID = "template-id"; //$NON-NLS-1$
34

35     public static final String JavaDoc PLUGIN_POINT = "pluginContent"; //$NON-NLS-1$
36

37     public static final String JavaDoc TAG_WIZARD = "wizard"; //$NON-NLS-1$
38

39     private IConfigurationElement fConfig;
40
41     private LibraryPluginJarsPage fJarsPage;
42
43     private NewLibraryPluginCreationPage fMainPage;
44
45     private LibraryPluginFieldData fPluginData;
46
47     private IProjectProvider fProjectProvider;
48
49     public NewLibraryPluginProjectWizard() {
50         setDefaultPageImageDescriptor(PDEPluginImages.DESC_JAR_TO_PLUGIN_WIZ);
51         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
52         setWindowTitle(PDEUIMessages.NewLibraryPluginProjectWizard_title);
53         setNeedsProgressMonitor(true);
54         PDEPlugin.getDefault().getLabelProvider().connect(this);
55         fPluginData = new LibraryPluginFieldData();
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see org.eclipse.jface.wizard.Wizard#addPages()
62      */

63     public void addPages() {
64         fJarsPage = new LibraryPluginJarsPage("jars", fPluginData); //$NON-NLS-1$
65
addPage(fJarsPage);
66         fMainPage = new NewLibraryPluginCreationPage("main", fPluginData); //$NON-NLS-1$
67
String JavaDoc pname = getDefaultValue(DEF_PROJECT_NAME);
68         if (pname != null)
69             fMainPage.setInitialProjectName(pname);
70
71         fProjectProvider = new IProjectProvider() {
72             public IPath getLocationPath() {
73                 return fMainPage.getLocationPath();
74             }
75
76             public IProject getProject() {
77                 return fMainPage.getProjectHandle();
78             }
79
80             public String JavaDoc getProjectName() {
81                 return fMainPage.getProjectName();
82             }
83         };
84
85         addPage(fMainPage);
86     }
87
88     protected WizardElement createWizardElement(IConfigurationElement config) {
89         String JavaDoc name = config.getAttribute(WizardElement.ATT_NAME);
90         String JavaDoc id = config.getAttribute(WizardElement.ATT_ID);
91         String JavaDoc className = config.getAttribute(WizardElement.ATT_CLASS);
92         if (name == null || id == null || className == null)
93             return null;
94         WizardElement element = new WizardElement(config);
95         String JavaDoc imageName = config.getAttribute(WizardElement.ATT_ICON);
96         if (imageName != null) {
97             String JavaDoc pluginID = config.getNamespaceIdentifier();
98             Image image = PDEPlugin.getDefault().getLabelProvider()
99                     .getImageFromPlugin(pluginID, imageName);
100             element.setImage(image);
101         }
102         return element;
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see org.eclipse.jface.wizard.Wizard#dispose()
109      */

110     public void dispose() {
111         super.dispose();
112         PDEPlugin.getDefault().getLabelProvider().disconnect(this);
113     }
114
115     /*
116      * (non-Javadoc)
117      *
118      * @see org.eclipse.pde.internal.ui.wizards.NewWizard#performFinish()
119      */

120     public boolean performFinish() {
121         try {
122             fJarsPage.updateData();
123             fMainPage.updateData();
124             BasicNewProjectResourceWizard.updatePerspective(fConfig);
125             getContainer().run(
126                     false,
127                     true,
128                     new NewLibraryPluginCreationOperation(fPluginData,
129                             fProjectProvider, null));
130             return true;
131         } catch (InvocationTargetException JavaDoc e) {
132             PDEPlugin.logException(e);
133         } catch (InterruptedException JavaDoc e) {
134         }
135         return false;
136     }
137
138     /*
139      * (non-Javadoc)
140      *
141      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
142      * java.lang.String, java.lang.Object)
143      */

144     public void setInitializationData(IConfigurationElement config,
145             String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
146         fConfig = config;
147     }
148
149 }
150
Popular Tags