KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > ui > wizards > ImportEjbJarProjectWizardIterator


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.j2ee.ejbjarproject.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import javax.swing.event.ChangeListener JavaDoc;
30 import org.netbeans.api.progress.ProgressHandle;
31 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings;
32 import org.netbeans.spi.project.ui.support.ProjectChooser;
33
34 import org.openide.WizardDescriptor;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileUtil;
37
38 import org.netbeans.api.project.Project;
39 import org.netbeans.api.project.ProjectManager;
40 import org.netbeans.modules.j2ee.api.ejbjar.Ear;
41 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject;
42 import org.openide.util.NbBundle;
43
44 import org.netbeans.modules.j2ee.ejbjarproject.api.EjbJarProjectGenerator;
45 import org.netbeans.modules.j2ee.ejbjarproject.Utils;
46 import org.netbeans.spi.project.support.ant.AntProjectHelper;
47
48
49 /**
50  * Wizard to create a new Web project for an existing web module.
51  * @author Pavel Buzek
52  */

53 public class ImportEjbJarProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
54     
55     private static final long serialVersionUID = 1L;
56 // private boolean imp = true;
57

58     // Make sure list of steps is accurate.
59
private static final String JavaDoc[] STEPS = new String JavaDoc[]{
60                 NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_IW_ImportTitle"), //NOI18N
61
NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LAB_ConfigureSourceRoots") //NOI18N
62
};
63
64     /** Create a new wizard iterator. */
65     public ImportEjbJarProjectWizardIterator() {}
66     
67     private WizardDescriptor.Panel[] createPanels() {
68         return new WizardDescriptor.Panel[] {
69             new ImportLocation(),
70             new PanelSourceFolders.Panel()
71         };
72     }
73
74     public Set JavaDoc instantiate() throws IOException JavaDoc/*, IllegalStateException*/ {
75         assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator.";
76         return null;
77     }
78         
79     public Set JavaDoc<FileObject> instantiate(ProgressHandle handle) throws IOException JavaDoc {
80         handle.start(3);
81         handle.progress(NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_CreatingProject"), 1);
82         
83         Set JavaDoc resultSet = new HashSet JavaDoc ();
84         File JavaDoc dirF = (File JavaDoc) wiz.getProperty(WizardProperties.PROJECT_DIR);
85         if (dirF != null) {
86             dirF = FileUtil.normalizeFile(dirF);
87         }
88         String JavaDoc name = (String JavaDoc) wiz.getProperty(WizardProperties.NAME);
89         File JavaDoc[] sourceFolders = (File JavaDoc[]) wiz.getProperty(WizardProperties.JAVA_ROOT);
90         File JavaDoc[] testFolders = (File JavaDoc[]) wiz.getProperty(WizardProperties.TEST_ROOT);
91         File JavaDoc configFilesFolder = (File JavaDoc) wiz.getProperty(WizardProperties.CONFIG_FILES_FOLDER);
92         File JavaDoc libName = (File JavaDoc) wiz.getProperty(WizardProperties.LIB_FOLDER);
93         String JavaDoc serverInstanceID = (String JavaDoc) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID);
94         String JavaDoc j2eeLevel = (String JavaDoc) wiz.getProperty(WizardProperties.J2EE_LEVEL);
95         
96         AntProjectHelper h = EjbJarProjectGenerator.importProject(dirF, name, sourceFolders, testFolders, configFilesFolder, libName, j2eeLevel, serverInstanceID);
97         handle.progress(2);
98         FileObject dir = FileUtil.toFileObject (dirF);
99
100         Project earProject = (Project) wiz.getProperty(WizardProperties.EAR_APPLICATION);
101         EjbJarProject createdEjbJarProject = (EjbJarProject) ProjectManager.getDefault().findProject(dir);
102         if (earProject != null && createdEjbJarProject != null) {
103             Ear ear = Ear.getEar(earProject.getProjectDirectory());
104             if (ear != null) {
105                 ear.addEjbJarModule(createdEjbJarProject.getAPIEjbJar());
106             }
107         }
108         
109         resultSet.add (dir);
110
111         dirF = (dirF != null) ? dirF.getParentFile() : null;
112         if (dirF != null && dirF.exists()) {
113             ProjectChooser.setProjectsFolder (dirF);
114         }
115         
116         // remember last used server
117
FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID);
118         
119         // downgrade the Java platform or src level to 1.4
120
String JavaDoc platformName = (String JavaDoc)wiz.getProperty(WizardProperties.JAVA_PLATFORM);
121         String JavaDoc sourceLevel = (String JavaDoc)wiz.getProperty(WizardProperties.SOURCE_LEVEL);
122         if (platformName != null || sourceLevel != null) {
123             EjbJarProjectGenerator.setPlatform(h, platformName, sourceLevel);
124         }
125                 
126         handle.progress(NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3);
127
128         return resultSet;
129     }
130     
131     private transient int index;
132     private transient WizardDescriptor.Panel[] panels;
133     private transient WizardDescriptor wiz;
134     
135     public void initialize(WizardDescriptor wiz) {
136         this.wiz = wiz;
137         index = 0;
138         panels = createPanels();
139         Utils.setSteps(panels, STEPS);
140     }
141
142     public void uninitialize(WizardDescriptor wiz) {
143         this.wiz.putProperty(WizardProperties.PROJECT_DIR, null);
144         this.wiz.putProperty(WizardProperties.NAME, null);
145         this.wiz.putProperty (WizardProperties.SOURCE_ROOT, null);
146         this.wiz.putProperty(WizardProperties.JAVA_ROOT, null);
147         this.wiz.putProperty(WizardProperties.TEST_ROOT, null);
148         this.wiz.putProperty(WizardProperties.CONFIG_FILES_FOLDER, null);
149         this.wiz.putProperty(WizardProperties.LIB_FOLDER, null);
150         this.wiz.putProperty(WizardProperties.SERVER_INSTANCE_ID, null);
151         this.wiz.putProperty(WizardProperties.J2EE_LEVEL, null);
152         this.wiz = null;
153         panels = null;
154     }
155     
156     public String JavaDoc name() {
157         return MessageFormat.format(NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_WizardStepsCount"),
158             new Object JavaDoc[] {(new Integer JavaDoc(index + 1)), (new Integer JavaDoc(panels.length))}); //NOI18N
159
}
160     
161     public boolean hasNext() {
162         return index < panels.length - 1;
163     }
164     public boolean hasPrevious() {
165         return index > 0;
166     }
167     public void nextPanel() {
168         if (!hasNext()) throw new NoSuchElementException JavaDoc();
169         index++;
170     }
171     public void previousPanel() {
172         if (!hasPrevious()) throw new NoSuchElementException JavaDoc();
173         index--;
174     }
175     public WizardDescriptor.Panel current() {
176         return panels[index];
177     }
178     
179     // If nothing unusual changes in the middle of the wizard, simply:
180
public final void addChangeListener(ChangeListener JavaDoc l) {}
181     public final void removeChangeListener(ChangeListener JavaDoc l) {}
182 }
183
Popular Tags