1 19 20 package org.netbeans.modules.j2ee.ejbfreeform.ui; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.math.BigDecimal ; 26 import java.util.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.HashSet ; 29 import java.util.List ; 30 import java.util.NoSuchElementException ; 31 import java.util.Set ; 32 import javax.swing.JComponent ; 33 import javax.swing.event.ChangeListener ; 34 import org.netbeans.api.project.Project; 35 import org.netbeans.api.project.ProjectManager; 36 import org.netbeans.modules.ant.freeform.spi.support.NewFreeformProjectSupport; 37 import org.netbeans.modules.ant.freeform.spi.support.Util; 38 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 39 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 40 import org.netbeans.modules.java.freeform.spi.support.NewJavaFreeformProjectSupport; 41 import org.netbeans.modules.j2ee.ejbfreeform.EJBProjectGenerator; 42 import org.netbeans.modules.j2ee.ejbfreeform.EJBProjectNature; 43 import org.netbeans.spi.project.AuxiliaryConfiguration; 44 import org.netbeans.spi.project.support.ant.AntProjectHelper; 45 import org.netbeans.spi.project.ui.support.ProjectChooser; 46 import org.openide.WizardDescriptor; 47 import org.openide.filesystems.FileObject; 48 import org.openide.filesystems.FileUtil; 49 import org.openide.util.NbBundle; 50 51 52 55 public class NewEJBFreeformProjectWizardIterator implements WizardDescriptor.InstantiatingIterator { 56 57 public static final String PROP_EJB_EJBMODULES = "ejbModules"; public static final String PROP_EJB_SOURCE_FOLDERS = "ejbSourceFolders"; public static final String PROP_EJB_RESOURCE_FOLDERS = "ejbResourceFolders"; public static final String SERVER_ID = "serverID"; public static final String J2EE_LEVEL = "j2eeLevel"; public static final String J2EE_SERVER_TYPE = "j2eeServerType"; 65 private static final long serialVersionUID = 1L; 66 67 private transient int index; 68 private transient WizardDescriptor.Panel[] panels; 69 private transient WizardDescriptor wiz; 70 71 public NewEJBFreeformProjectWizardIterator() { 72 } 73 74 private WizardDescriptor.Panel[] createPanels () { 75 List l = new ArrayList (); 76 List extraTargets = new ArrayList (); 77 extraTargets.add(EJBProjectNature.getExtraTarget()); 78 l.add(NewFreeformProjectSupport.createBasicProjectInfoWizardPanel()); 79 l.add(NewFreeformProjectSupport.createTargetMappingWizardPanel(extraTargets)); 80 l.add(new EJBLocationsWizardPanel()); 81 l.addAll(Arrays.asList(NewJavaFreeformProjectSupport.createJavaPanels())); 82 return (WizardDescriptor.Panel[])l.toArray(new WizardDescriptor.Panel[l.size()]); 83 } 84 85 public Set instantiate () throws IOException { 86 final WizardDescriptor wiz = this.wiz; 87 final IOException [] ioe = new IOException [1]; 88 ProjectManager.mutex().writeAccess(new Runnable () { 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 ejbSources = (List )wiz.getProperty(PROP_EJB_SOURCE_FOLDERS); 96 AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(helper); 97 EJBProjectGenerator.putEJBSourceFolder(helper, ejbSources); 98 99 List resources = (List ) wiz.getProperty(PROP_EJB_RESOURCE_FOLDERS); 100 EJBProjectGenerator.putResourceFolder(helper, resources); 101 102 String j2eeLevel = (String ) wiz.getProperty(J2EE_LEVEL); 103 EJBProjectGenerator.putJ2EELevel(helper, j2eeLevel); 104 105 String serverID = (String ) wiz.getProperty(SERVER_ID); 106 EJBProjectGenerator.putServerID(helper, serverID); 107 108 List ejbModules = (List ) wiz.getProperty(PROP_EJB_EJBMODULES); 109 if (ejbModules != null) { 110 EJBProjectGenerator.putEJBModules (helper, aux, ejbModules); 111 } 112 113 Project p = ProjectManager.getDefault().findProject(helper.getProjectDirectory()); 114 115 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(p)[0]; 116 if (ejbModule != null) { 117 FileObject ejbJarFile = ejbModule.getDeploymentDescriptor(); 118 EjbJar dd = DDProvider.getDefault().getMergedDDRoot(ejbModule.getMetadataUnit()); 119 if (!new BigDecimal (EjbJar.VERSION_3_0).equals(dd.getVersion())) { 122 EJBProjectGenerator.putEJBNodeView(helper, ejbSources); 123 } 124 boolean write = false; 125 String dispName = dd.getDefaultDisplayName(); 127 if ((null == dispName || dispName.trim().length() == 0) && (ejbJarFile != null)) { 128 dd.setDisplayName(helper.getProjectDirectory().getName()); 129 write = true; 130 } 131 if (j2eeLevel.equals("1.4") && !new BigDecimal (EjbJar.VERSION_2_1).equals(dd.getVersion())) { dd.setVersion(new BigDecimal (EjbJar.VERSION_2_1)); 134 write = true; 135 } 136 if (write && ejbJarFile != null) { 143 dd.write(ejbJarFile); 144 } 145 } 146 147 ProjectManager.getDefault().saveProject(p); 148 } catch (IOException e) { 149 ioe[0] = e; 150 return; 151 } 152 }}); 153 if (ioe[0] != null) { 154 throw ioe[0]; 155 } 156 File nbProjectFolder = (File )wiz.getProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER); 157 Set resultSet = new HashSet (); 158 resultSet.add(FileUtil.toFileObject(nbProjectFolder)); 159 File f = nbProjectFolder.getParentFile(); 160 if (f != null) { 161 ProjectChooser.setProjectsFolder(f); 162 } 163 return resultSet; 164 } 165 166 167 public void initialize(WizardDescriptor wiz) { 168 this.wiz = wiz; 169 index = 0; 170 panels = createPanels(); 171 172 List l = new ArrayList (); 173 for (int i = 0; i < panels.length; i++) { 174 Component c = panels[i].getComponent(); 175 assert c instanceof JComponent ; 176 JComponent jc = (JComponent )c; 177 l.add(jc.getName()); 178 } 179 String [] steps = (String [])l.toArray(new String [l.size()]); 180 for (int i = 0; i < panels.length; i++) { 181 Component c = panels[i].getComponent(); 182 assert c instanceof JComponent ; 183 JComponent jc = (JComponent )c; 184 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); jc.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage (NewEJBFreeformProjectWizardIterator.class, "TXT_NewEJBFreeformProjectWizardIterator_NewProjectWizardTitle")); } 191 } 192 193 public void uninitialize(WizardDescriptor wiz) { 194 NewFreeformProjectSupport.uninitializeBasicProjectInfoWizardPanel(wiz); 195 NewFreeformProjectSupport.uninitializeTargetMappingWizardPanel(wiz); 196 NewJavaFreeformProjectSupport.uninitializeJavaPanels(wiz); 197 wiz.putProperty(PROP_EJB_SOURCE_FOLDERS, null); 198 wiz.putProperty(PROP_EJB_RESOURCE_FOLDERS, null); 199 wiz.putProperty(PROP_EJB_EJBMODULES, null); 200 wiz.putProperty(SERVER_ID, null); 201 wiz.putProperty(J2EE_LEVEL, null); 202 wiz.putProperty(J2EE_SERVER_TYPE, null); 203 this.wiz = null; 204 panels = null; 205 } 206 207 public String name() { 208 return NbBundle.getMessage(NewEJBFreeformProjectWizardIterator.class, "TXT_NewEJBFreeformProjectWizardIterator_TitleFormat", 209 new Object [] {new Integer (index + 1), new Integer (panels.length)} ); 210 } 211 212 public boolean hasNext() { 213 if (!NewJavaFreeformProjectSupport.enableNextButton(current())) { 214 return false; 215 } 216 return index < panels.length - 1; 217 } 218 public boolean hasPrevious() { 219 return index > 0; 220 } 221 public void nextPanel() { 222 if (!hasNext()) throw new NoSuchElementException (); 223 index++; 224 } 225 public void previousPanel() { 226 if (!hasPrevious()) throw new NoSuchElementException (); 227 index--; 228 } 229 public WizardDescriptor.Panel current () { 230 return panels[index]; 231 } 232 233 public final void addChangeListener(ChangeListener l) {} 235 public final void removeChangeListener(ChangeListener l) {} 236 237 238 } 239 | Popular Tags |