1 19 20 package org.netbeans.modules.web.project.ui.wizards; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.text.MessageFormat ; 26 import java.util.HashSet ; 27 import java.util.List ; 28 import java.util.NoSuchElementException ; 29 import java.util.Set ; 30 31 import javax.swing.JComponent ; 32 import javax.swing.event.ChangeListener ; 33 34 import org.openide.WizardDescriptor; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileUtil; 37 import org.openide.util.NbBundle; 38 39 import org.netbeans.api.project.Project; 40 import org.netbeans.api.project.ProjectManager; 41 import org.netbeans.spi.project.support.ant.AntProjectHelper; 42 import org.netbeans.spi.project.ui.support.ProjectChooser; 43 import org.netbeans.api.progress.ProgressHandle; 44 45 import org.netbeans.modules.j2ee.api.ejbjar.Ear; 46 import org.netbeans.modules.web.api.webmodule.WebFrameworkSupport; 47 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider; 48 import org.netbeans.modules.web.project.WebProject; 49 import org.netbeans.modules.web.project.api.WebProjectCreateData; 50 import org.netbeans.modules.web.project.api.WebProjectUtilities; 51 import org.netbeans.modules.web.project.ui.FoldersListSettings; 52 53 57 public class NewWebProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { 58 59 private static final long serialVersionUID = 1L; 60 61 static final String PROP_NAME_INDEX = "nameIndex"; 63 64 public NewWebProjectWizardIterator() {} 65 66 private String [] createSteps() { 67 String [] steps; 68 if (WebFrameworkSupport.getFrameworkProviders().size() > 0) 69 steps = new String [] { 70 NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_NWP1_ProjectTitleName"), NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_NWP2_Frameworks") }; 73 else 74 steps = new String [] { 75 NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_NWP1_ProjectTitleName"), }; 77 78 return steps; 79 } 80 81 public Set instantiate() throws IOException { 82 assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator."; 83 return null; 84 } 85 86 public Set <FileObject> instantiate(ProgressHandle handle) throws IOException { 87 handle.start(4); 88 handle.progress(NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_NewWebProjectWizardIterator_WizardProgress_CreatingProject"), 1); 89 90 Set resultSet = new HashSet (); 91 92 File dirF = (File ) wiz.getProperty(WizardProperties.PROJECT_DIR); 93 String servInstID = (String ) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID); 94 95 WebProjectCreateData createData = new WebProjectCreateData(); 96 createData.setProjectDir(dirF); 97 createData.setName((String ) wiz.getProperty(WizardProperties.NAME)); 98 createData.setServerInstanceID(servInstID); 99 createData.setSourceStructure((String )wiz.getProperty(WizardProperties.SOURCE_STRUCTURE)); 100 createData.setJavaEEVersion((String ) wiz.getProperty(WizardProperties.J2EE_LEVEL)); 101 createData.setContextPath((String ) wiz.getProperty(WizardProperties.CONTEXT_PATH)); 102 createData.setJavaPlatformName((String ) wiz.getProperty(WizardProperties.JAVA_PLATFORM)); 103 createData.setSourceLevel((String ) wiz.getProperty(WizardProperties.SOURCE_LEVEL)); 104 AntProjectHelper h = WebProjectUtilities.createProject(createData); 105 handle.progress(2); 106 107 FileObject webRoot = h.getProjectDirectory().getFileObject("web"); FileObject indexJSPFo = getIndexJSPFO(webRoot, "index"); assert indexJSPFo != null : "webRoot: " + webRoot + ", defaultJSP: index"; resultSet.add (indexJSPFo); 112 113 FileObject dir = FileUtil.toFileObject(dirF); 114 115 Integer index = (Integer ) wiz.getProperty(PROP_NAME_INDEX); 116 if(index != null) { 117 FoldersListSettings.getDefault().setNewProjectCount(index.intValue()); 118 } 119 wiz.putProperty(WizardProperties.NAME, null); 121 Project earProject = (Project) wiz.getProperty(WizardProperties.EAR_APPLICATION); 122 123 WebProject createdWebProject = (WebProject) ProjectManager.getDefault().findProject(dir); 124 if (earProject != null && createdWebProject != null) { 125 Ear ear = Ear.getEar(earProject.getProjectDirectory()); 126 if (ear != null) { 127 ear.addWebModule(createdWebProject.getAPIWebModule()); 128 } 129 } 130 131 FoldersListSettings.getDefault().setLastUsedServer(servInstID); 133 134 dirF = (dirF != null) ? dirF.getParentFile() : null; 136 if (dirF != null && dirF.exists()) { 137 ProjectChooser.setProjectsFolder (dirF); 138 } 139 140 resultSet.add(dir); 141 142 List selectedFrameworks = (List ) wiz.getProperty(WizardProperties.FRAMEWORKS); 144 if (selectedFrameworks != null){ 145 handle.progress(NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_NewWebProjectWizardIterator_WizardProgress_AddingFrameworks"), 3); 146 for(int i = 0; i < selectedFrameworks.size(); i++) { 147 Object o = ((WebFrameworkProvider) selectedFrameworks.get(i)).extend(createdWebProject.getAPIWebModule()); 148 if (o != null && o instanceof Set ) 149 resultSet.addAll((Set )o); 150 } 151 } 152 153 handle.progress(NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_NewWebProjectWizardIterator_WizardProgress_PreparingToOpen"), 4); 154 155 return resultSet; 158 } 159 160 private transient int index; 161 private transient int panelsCount; 162 private transient WizardDescriptor.Panel[] panels; 163 private transient WizardDescriptor wiz; 164 165 public void initialize(WizardDescriptor wiz) { 166 this.wiz = wiz; 167 index = 0; 168 169 if (WebFrameworkSupport.getFrameworkProviders().size() > 0) 170 panels = new WizardDescriptor.Panel[] { 172 new PanelConfigureProject(), 173 new PanelSupportedFrameworks() 174 }; 175 else 176 panels = new WizardDescriptor.Panel[] { 178 new PanelConfigureProject(), 179 }; 180 panelsCount = panels.length; 181 182 String [] steps = createSteps(); 184 for (int i = 0; i < steps.length; i++) { 185 Component c = panels[i].getComponent(); 186 if (c instanceof JComponent ) { JComponent jc = (JComponent )c; 188 jc.putClientProperty("WizardPanel_contentSelectedIndex", Integer.valueOf(i)); jc.putClientProperty("WizardPanel_contentData", steps); } 193 } 194 } 195 196 public void uninitialize(WizardDescriptor wiz) { 197 if (this.wiz != null) { 198 this.wiz.putProperty(WizardProperties.PROJECT_DIR,null); 199 this.wiz.putProperty(WizardProperties.NAME,null); 200 this.wiz = null; 201 } 202 panels = null; 203 } 204 205 public String name() { 206 return MessageFormat.format(NbBundle.getMessage(NewWebProjectWizardIterator.class, "LBL_WizardStepsCount"), Integer.toString(index + 1), Integer.toString(panels.length)); } 208 209 public boolean hasNext() { 210 return index < panelsCount - 1; 211 } 212 213 public boolean hasPrevious() { 214 return index > 0; 215 } 216 217 public void nextPanel() { 218 if (!hasNext()) throw new NoSuchElementException (); 219 index++; 220 } 221 222 public void previousPanel() { 223 if (!hasPrevious()) throw new NoSuchElementException (); 224 index--; 225 } 226 227 public WizardDescriptor.Panel current() { 228 return panels[index]; 229 } 230 231 public final void addChangeListener(ChangeListener l) {} 233 public final void removeChangeListener(ChangeListener l) {} 234 235 private FileObject getIndexJSPFO(FileObject webRoot, String indexJSP) { 237 indexJSP = indexJSP.replace ('.', '/'); 240 242 return webRoot.getFileObject (indexJSP, "jsp"); } 244 } 245 | Popular Tags |