KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 import java.util.NoSuchElementException JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import javax.swing.event.ChangeListener JavaDoc;
31 import org.netbeans.api.progress.ProgressHandle;
32 import org.netbeans.api.project.Project;
33 import org.netbeans.api.project.ProjectManager;
34 import org.netbeans.modules.j2ee.api.ejbjar.Ear;
35 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject;
36 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings;
37 import org.netbeans.spi.project.support.ant.AntProjectHelper;
38
39 import org.openide.WizardDescriptor;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileUtil;
42
43 import org.netbeans.modules.j2ee.ejbjarproject.api.EjbJarProjectGenerator;
44 import org.netbeans.modules.j2ee.ejbjarproject.Utils;
45 import org.openide.util.NbBundle;
46
47 /**
48  * Wizard to create a new Web project.
49  * @author Jesse Glick
50  */

51 public class NewEjbJarProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
52     
53     static final String JavaDoc PROP_NAME_INDEX = "nameIndex"; //NOI18N
54

55     private static final long serialVersionUID = 1L;
56
57     // Make sure list of steps is accurate.
58
private static final String JavaDoc[] STEPS = new String JavaDoc[] {
59                                 NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_ProjectTitleName"), //NOI18N
60
//need this after EA1
61
///NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_ProjectAppName") //NOI18N
62
};
63
64     private WizardDescriptor.Panel[] createPanels() {
65         return new WizardDescriptor.Panel[] {
66             new PanelConfigureProject(),
67             //need this after EA1
68
///new PanelConfigureProjectApp(),
69
};
70     }
71
72     public Set JavaDoc instantiate() throws IOException JavaDoc {
73         assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator.";
74         return null;
75     }
76         
77     public Set JavaDoc<FileObject> instantiate(ProgressHandle handle) throws IOException JavaDoc {
78         handle.start(3);
79         handle.progress(NbBundle.getMessage(NewEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_CreatingProject"), 1);
80         
81         Set JavaDoc resultSet = new HashSet JavaDoc();
82         File JavaDoc dirF = (File JavaDoc) wiz.getProperty(WizardProperties.PROJECT_DIR);
83         String JavaDoc name = (String JavaDoc) wiz.getProperty(WizardProperties.NAME);
84         String JavaDoc serverInstanceID = (String JavaDoc) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID);
85         String JavaDoc j2eeLevel = (String JavaDoc) wiz.getProperty(WizardProperties.J2EE_LEVEL);
86         
87         AntProjectHelper h = EjbJarProjectGenerator.createProject(dirF, name, j2eeLevel, serverInstanceID);
88         handle.progress(2);
89         FileObject dir = FileUtil.toFileObject(dirF);
90         
91         Project earProject = (Project) wiz.getProperty(WizardProperties.EAR_APPLICATION);
92         EjbJarProject createdEjbJarProject = (EjbJarProject) ProjectManager.getDefault().findProject(dir);
93         if (earProject != null && createdEjbJarProject != null) {
94             Ear ear = Ear.getEar(earProject.getProjectDirectory());
95             if (ear != null) {
96                 ear.addEjbJarModule(createdEjbJarProject.getAPIEjbJar());
97             }
98         }
99         
100         // remember last used server
101
FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID);
102         
103         // downgrade the Java platform or src level to 1.4
104
String JavaDoc platformName = (String JavaDoc)wiz.getProperty(WizardProperties.JAVA_PLATFORM);
105         String JavaDoc sourceLevel = (String JavaDoc)wiz.getProperty(WizardProperties.SOURCE_LEVEL);
106         if (platformName != null || sourceLevel != null) {
107             EjbJarProjectGenerator.setPlatform(h, platformName, sourceLevel);
108         }
109         
110         handle.progress(NbBundle.getMessage(NewEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3);
111         
112         resultSet.add(dir);
113         
114         // Returning set of FileObject of project diretory.
115
// Project will be open and set as main
116
return resultSet;
117     }
118     
119     private transient int index;
120     private transient WizardDescriptor.Panel[] panels;
121     private transient WizardDescriptor wiz;
122     
123     public void initialize(WizardDescriptor wiz) {
124         this.wiz = wiz;
125         index = 0;
126         panels = createPanels();
127         Utils.setSteps(panels, STEPS);
128     }
129     public void uninitialize(WizardDescriptor wiz) {
130         this.wiz.putProperty(WizardProperties.PROJECT_DIR,null);
131         this.wiz.putProperty(WizardProperties.NAME,null);
132         this.wiz = null;
133         panels = null;
134     }
135     
136     public String JavaDoc name() {
137         return MessageFormat.format(NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_WizardStepsCount"), new String JavaDoc[] {(new Integer JavaDoc(index + 1)).toString(), (new Integer JavaDoc(panels.length)).toString()}); //NOI18N
138
}
139     
140     public boolean hasNext() {
141         return index < panels.length - 1;
142     }
143     public boolean hasPrevious() {
144         return index > 0;
145     }
146     public void nextPanel() {
147         if (!hasNext()) throw new NoSuchElementException JavaDoc();
148         index++;
149     }
150     public void previousPanel() {
151         if (!hasPrevious()) throw new NoSuchElementException JavaDoc();
152         index--;
153     }
154     public WizardDescriptor.Panel current() {
155         return panels[index];
156     }
157     
158     // If nothing unusual changes in the middle of the wizard, simply:
159
public final void addChangeListener(ChangeListener JavaDoc l) {}
160     public final void removeChangeListener(ChangeListener JavaDoc l) {}
161     
162 }
163
Popular Tags