KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > NewProjectWizard


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.ui.internal.ide.dialogs;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.jface.dialogs.IDialogSettings;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.ui.INewWizard;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
22 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
23
24 /**
25  * Standard workbench wizard that guides the user to supply
26  * the necessary information to create a project.
27  */

28 public class NewProjectWizard extends MultiStepWizard implements
29         INewWizard {
30
31     // Reference to the pages provided by this wizard
32
private WizardNewProjectNameAndLocationPage creationPage;
33
34
35     // Newly created project
36
private IProject newProject;
37
38     // initial values for the pages provided by this wizard
39
private String JavaDoc initialProjectName;
40
41
42     /**
43      * Creates an empty wizard for creating a new project
44      * in the workspace.
45      */

46     public NewProjectWizard() {
47         super();
48
49         IDEWorkbenchPlugin plugin = IDEWorkbenchPlugin.getDefault();
50         IDialogSettings workbenchSettings = plugin.getDialogSettings();
51         IDialogSettings section = workbenchSettings
52                 .getSection("NewProjectWizard");//$NON-NLS-1$
53
if (section == null) {
54             section = workbenchSettings.addNewSection("NewProjectWizard");//$NON-NLS-1$
55
}
56         setDialogSettings(section);
57     }
58
59     /* (non-Javadoc)
60      * Method declared on MultiStepWizard.
61      */

62     protected void addCustomPages() {
63         creationPage = new WizardNewProjectNameAndLocationPage(
64                 "newProjectCreationPage");//$NON-NLS-1$
65
creationPage.setTitle(IDEWorkbenchMessages.NewProjectWizard_title);
66         creationPage.setDescription(IDEWorkbenchMessages.WizardNewProjectCreationPage_description);
67         creationPage.setInitialProjectName(initialProjectName);
68         this.addPage(creationPage);
69
70     }
71
72     /* (non-Javadoc)
73      * Method declared on MultiStepWizard.
74      */

75     protected boolean canFinishOnReviewPage() {
76         // yes if the only step is to create the project.
77
return getSteps().length == 1;
78     }
79
80     /* (non-Javadoc)
81      * Method declared on MultiStepWizard.
82      */

83     protected String JavaDoc getConfigurePageTitle() {
84         return IDEWorkbenchMessages.NewProjectWizard_title;
85     }
86
87     /* (non-Javadoc)
88      * Method declared on MultiStepWizard.
89      */

90     protected String JavaDoc getConfigurePageDescription() {
91         return IDEWorkbenchMessages.WizardProjectConfigurePage_description;
92     }
93
94     /* (non-Javadoc)
95      * Method declared on MultiStepWizard.
96      */

97     protected String JavaDoc getReviewPageTitle() {
98         return IDEWorkbenchMessages.NewProjectWizard_title;
99     }
100
101     /* (non-Javadoc)
102      * Method declared on MultiStepWizard.
103      */

104     protected String JavaDoc getReviewPageDescription() {
105         return IDEWorkbenchMessages.WizardProjectReviewPage_description;
106     }
107
108     /* (non-Javadoc)
109      * Method declared on MultiStepWizard.
110      */

111     protected String JavaDoc getFinishStepLabel(WizardStep[] steps) {
112         // The first step is the project creation which has no wizard
113
// pages, so ignore it. If there is only one step after that,
114
// then it needs the "Finish" label. So the "Finish Step" label
115
// is only needed if more than 2 steps in the list.
116
if (steps.length > 2) {
117             return super.getFinishStepLabel(steps);
118         } else {
119             return null;
120         }
121     }
122
123     /**
124      * Returns the newly created project.
125      *
126      * @return the created project, or <code>null</code>
127      * if project is not created yet.
128      */

129     public IProject getNewProject() {
130         return newProject;
131     }
132
133     /* (non-Javadoc)
134      * Method declared on IProjectProvider.
135      */

136     public IProject getProject() {
137         return newProject;
138     }
139
140     /* (non-Javadoc)
141      * Method declared on MultiStepWizard.
142      */

143     /* package */boolean handleMissingStepWizard(WizardStep step) {
144         MessageDialog
145                 .openError(
146                         getShell(),
147                         IDEWorkbenchMessages.NewProjectWizard_errorTitle,
148                         NLS.bind(IDEWorkbenchMessages.NewProjectWizard_noWizard, step.getLabel()));
149         return false;
150     }
151
152     /* (non-Javadoc)
153      * Method declared on IWorkbenchWizard.
154      */

155     public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
156         initializeDefaultPageImageDescriptor();
157         setWindowTitle(IDEWorkbenchMessages.NewProjectWizard_windowTitle);
158     }
159
160     /**
161      * Sets the image banner for the wizard
162      */

163     protected void initializeDefaultPageImageDescriptor() {
164         ImageDescriptor desc = IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/newprj_wiz.png");//$NON-NLS-1$
165
setDefaultPageImageDescriptor(desc);
166        
167     }
168
169     /**
170      * Sets the initial project name. Leading and trailing
171      * spaces in the name are ignored.
172      *
173      * @param name initial project name
174      */

175     public void setInitialProjectName(String JavaDoc name) {
176         if (name == null) {
177             initialProjectName = null;
178         } else {
179             initialProjectName = name.trim();
180         }
181     }
182
183     /**
184      * Sets the newly created project resource
185      */

186     /* package */void setNewProject(IProject project) {
187         newProject = project;
188     }
189 }
190
Popular Tags