1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.wizards; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.text.MessageFormat ; 25 import java.util.HashSet ; 26 27 import java.util.NoSuchElementException ; 28 import java.util.Set ; 29 30 import javax.swing.event.ChangeListener ; 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 51 public class NewEjbJarProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { 52 53 static final String PROP_NAME_INDEX = "nameIndex"; 55 private static final long serialVersionUID = 1L; 56 57 private static final String [] STEPS = new String [] { 59 NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_ProjectTitleName"), }; 63 64 private WizardDescriptor.Panel[] createPanels() { 65 return new WizardDescriptor.Panel[] { 66 new PanelConfigureProject(), 67 }; 70 } 71 72 public Set instantiate() throws IOException { 73 assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator."; 74 return null; 75 } 76 77 public Set <FileObject> instantiate(ProgressHandle handle) throws IOException { 78 handle.start(3); 79 handle.progress(NbBundle.getMessage(NewEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_CreatingProject"), 1); 80 81 Set resultSet = new HashSet (); 82 File dirF = (File ) wiz.getProperty(WizardProperties.PROJECT_DIR); 83 String name = (String ) wiz.getProperty(WizardProperties.NAME); 84 String serverInstanceID = (String ) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID); 85 String j2eeLevel = (String ) 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 FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID); 102 103 String platformName = (String )wiz.getProperty(WizardProperties.JAVA_PLATFORM); 105 String sourceLevel = (String )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 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 name() { 137 return MessageFormat.format(NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_WizardStepsCount"), new String [] {(new Integer (index + 1)).toString(), (new Integer (panels.length)).toString()}); } 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 (); 148 index++; 149 } 150 public void previousPanel() { 151 if (!hasPrevious()) throw new NoSuchElementException (); 152 index--; 153 } 154 public WizardDescriptor.Panel current() { 155 return panels[index]; 156 } 157 158 public final void addChangeListener(ChangeListener l) {} 160 public final void removeChangeListener(ChangeListener l) {} 161 162 } 163 | Popular Tags |