KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > freeform > ui > NewWebFreeformProjectWizardIterator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.freeform.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.NoSuchElementException JavaDoc;
32 import java.util.Set JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.event.ChangeListener JavaDoc;
35 import org.netbeans.api.project.Project;
36 import org.netbeans.api.project.ProjectManager;
37 import org.netbeans.api.project.ProjectUtils;
38 import org.netbeans.api.project.SourceGroup;
39 import org.netbeans.api.project.Sources;
40 import org.netbeans.modules.ant.freeform.spi.support.NewFreeformProjectSupport;
41 import org.netbeans.modules.ant.freeform.spi.support.Util;
42 import org.netbeans.modules.java.freeform.spi.support.NewJavaFreeformProjectSupport;
43 import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
44 import org.netbeans.modules.web.freeform.WebProjectGenerator;
45 import org.netbeans.modules.web.freeform.WebProjectNature;
46 import org.netbeans.spi.project.AuxiliaryConfiguration;
47 import org.netbeans.spi.project.support.ant.AntProjectHelper;
48 import org.netbeans.spi.project.ui.support.ProjectChooser;
49 import org.openide.WizardDescriptor;
50 import org.openide.filesystems.FileUtil;
51 import org.openide.util.NbBundle;
52
53 /**
54  * @author David Konecny, Radko Najman
55  */

56 public class NewWebFreeformProjectWizardIterator implements WizardDescriptor.InstantiatingIterator {
57
58     // web sources
59
public static final String JavaDoc PROP_WEB_WEBMODULES = "webModules"; // <List> NOI18N
60
public static final String JavaDoc PROP_WEB_SOURCE_FOLDERS = "webSourceFolders"; // <List> NOI18N
61

62     protected static final String JavaDoc PROP_WEB_CLASSPATH = "webClasspath"; // <String> NOI18N
63

64     private static final long serialVersionUID = 1L;
65     
66     private transient int index;
67     private transient WizardDescriptor.Panel[] panels;
68     private transient WizardDescriptor wiz;
69     
70     public NewWebFreeformProjectWizardIterator() {
71     }
72     
73     private WizardDescriptor.Panel[] createPanels () {
74         List JavaDoc l = new ArrayList JavaDoc();
75         List JavaDoc extraTargets = new ArrayList JavaDoc();
76         extraTargets.add(WebProjectNature.getExtraTarget());
77         l.add(NewFreeformProjectSupport.createBasicProjectInfoWizardPanel());
78         l.add(NewFreeformProjectSupport.createTargetMappingWizardPanel(extraTargets));
79         l.add(new WebLocationsWizardPanel());
80         l.addAll(Arrays.asList(NewJavaFreeformProjectSupport.createJavaPanels()));
81         l.add(new WebClasspathWizardPanel());
82         return (WizardDescriptor.Panel[])l.toArray(new WizardDescriptor.Panel[l.size()]);
83     }
84     
85     public Set JavaDoc/*<FileObject>*/ instantiate () throws IOException JavaDoc {
86         final WizardDescriptor wiz = this.wiz;
87         final IOException JavaDoc[] ioe = new IOException JavaDoc[1];
88         ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
89             public void run() {
90                 try {
91                     AntProjectHelper helper = NewFreeformProjectSupport.instantiateBasicProjectInfoWizardPanel(wiz);
92                     NewFreeformProjectSupport.instantiateTargetMappingWizardPanel(helper, wiz);
93                     NewJavaFreeformProjectSupport.instantiateJavaPanels(helper, wiz);
94                     
95                     List JavaDoc webSources = (List JavaDoc)wiz.getProperty(PROP_WEB_SOURCE_FOLDERS);
96                     AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(helper);
97                     WebProjectGenerator.putWebSourceFolder(helper, webSources);
98         
99                     List JavaDoc webModules = (List JavaDoc) wiz.getProperty(PROP_WEB_WEBMODULES);
100                     if (webModules != null) {
101                         // Save the web classpath for the web module
102
String JavaDoc webClasspath = (String JavaDoc)wiz.getProperty(NewWebFreeformProjectWizardIterator.PROP_WEB_CLASSPATH);
103                         Iterator JavaDoc iter = webModules.iterator();
104                         WebProjectGenerator.WebModule wm;
105                         while(iter.hasNext()){
106                             wm = (WebProjectGenerator.WebModule)iter.next();
107                             wm.classpath = webClasspath;
108                         }
109                         WebProjectGenerator.putWebModules (helper, aux, webModules);
110                     }
111                     
112                     Project p = ProjectManager.getDefault().findProject(helper.getProjectDirectory());
113                     ProjectManager.getDefault().saveProject(p);
114                 } catch (IOException JavaDoc e) {
115                     ioe[0] = e;
116                     return;
117                 }
118             }});
119         if (ioe[0] != null) {
120             throw ioe[0];
121         }
122         File JavaDoc nbProjectFolder = (File JavaDoc)wiz.getProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER);
123         Set JavaDoc resultSet = new HashSet JavaDoc();
124         resultSet.add(FileUtil.toFileObject(nbProjectFolder));
125         Project p = ProjectManager.getDefault().findProject(FileUtil.toFileObject(nbProjectFolder));
126         if (p != null) {
127             Sources srcs = ProjectUtils.getSources(p);
128             if (srcs != null) {
129                 SourceGroup[] grps = srcs.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT);
130                 if (grps != null && grps.length > 0) {
131                     resultSet.add(grps[0].getRootFolder());
132                 }
133             }
134         }
135         File JavaDoc f = nbProjectFolder.getParentFile();
136         if (f != null) {
137             ProjectChooser.setProjectsFolder(f);
138         }
139         return resultSet;
140     }
141     
142         
143     public void initialize(WizardDescriptor wiz) {
144         this.wiz = wiz;
145         index = 0;
146         panels = createPanels();
147         
148         List JavaDoc l = new ArrayList JavaDoc();
149         for (int i = 0; i < panels.length; i++) {
150             Component JavaDoc c = panels[i].getComponent();
151             assert c instanceof JComponent JavaDoc;
152             JComponent JavaDoc jc = (JComponent JavaDoc)c;
153             l.add(jc.getName());
154         }
155         String JavaDoc[] steps = (String JavaDoc[])l.toArray(new String JavaDoc[l.size()]);
156         for (int i = 0; i < panels.length; i++) {
157             Component JavaDoc c = panels[i].getComponent();
158             assert c instanceof JComponent JavaDoc;
159             JComponent JavaDoc jc = (JComponent JavaDoc)c;
160             // Step #.
161
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
162
// Step name (actually the whole list for reference).
163
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
164
// set title
165
jc.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewWebFreeformProjectWizardIterator_NewProjectWizardTitle")); // NOI18N
166
jc.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "ACSD_NewWebFreeformProjectWizardIterator_NewProjectWizardTitle")); // NOI18N
167
}
168     }
169     
170     public void uninitialize(WizardDescriptor wiz) {
171         NewFreeformProjectSupport.uninitializeBasicProjectInfoWizardPanel(wiz);
172         NewFreeformProjectSupport.uninitializeTargetMappingWizardPanel(wiz);
173         NewJavaFreeformProjectSupport.uninitializeJavaPanels(wiz);
174         wiz.putProperty(PROP_WEB_SOURCE_FOLDERS, null);
175         wiz.putProperty(PROP_WEB_WEBMODULES, null);
176         this.wiz = null;
177         panels = null;
178     }
179     
180     public String JavaDoc name() {
181         return MessageFormat.format (NbBundle.getMessage(NewWebFreeformProjectWizardIterator.class, "TXT_NewWebFreeformProjectWizardIterator_TitleFormat"), // NOI18N
182
new Object JavaDoc[] {new Integer JavaDoc (index + 1), new Integer JavaDoc (panels.length) });
183     }
184     
185     public boolean hasNext() {
186         if (!NewJavaFreeformProjectSupport.enableNextButton(current())) {
187             return false;
188         }
189         return index < panels.length - 1;
190     }
191     public boolean hasPrevious() {
192         return index > 0;
193     }
194     public void nextPanel() {
195         if (!hasNext()) throw new NoSuchElementException JavaDoc();
196         index++;
197     }
198     public void previousPanel() {
199         if (!hasPrevious()) throw new NoSuchElementException JavaDoc();
200         index--;
201     }
202     public WizardDescriptor.Panel current () {
203         return panels[index];
204     }
205     
206     // If nothing unusual changes in the middle of the wizard, simply:
207
public final void addChangeListener(ChangeListener JavaDoc l) {}
208     public final void removeChangeListener(ChangeListener JavaDoc l) {}
209
210     
211 }
212
Popular Tags