1 19 20 package org.netbeans.modules.web.freeform.ui; 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.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.NoSuchElementException ; 32 import java.util.Set ; 33 import javax.swing.JComponent ; 34 import javax.swing.event.ChangeListener ; 35 import org.netbeans.api.project.Project; 36 import org.netbeans.api.project.ProjectManager; 37 import org.netbeans.api.project.ProjectUtils; 38 import org.netbeans.api.project.SourceGroup; 39 import org.netbeans.api.project.Sources; 40 import org.netbeans.modules.ant.freeform.spi.support.NewFreeformProjectSupport; 41 import org.netbeans.modules.ant.freeform.spi.support.Util; 42 import org.netbeans.modules.java.freeform.spi.support.NewJavaFreeformProjectSupport; 43 import org.netbeans.modules.web.api.webmodule.WebProjectConstants; 44 import org.netbeans.modules.web.freeform.WebProjectGenerator; 45 import org.netbeans.modules.web.freeform.WebProjectNature; 46 import org.netbeans.spi.project.AuxiliaryConfiguration; 47 import org.netbeans.spi.project.support.ant.AntProjectHelper; 48 import org.netbeans.spi.project.ui.support.ProjectChooser; 49 import org.openide.WizardDescriptor; 50 import org.openide.filesystems.FileUtil; 51 import org.openide.util.NbBundle; 52 53 56 public class NewWebFreeformProjectWizardIterator implements WizardDescriptor.InstantiatingIterator { 57 58 public static final String PROP_WEB_WEBMODULES = "webModules"; public static final String PROP_WEB_SOURCE_FOLDERS = "webSourceFolders"; 62 protected static final String PROP_WEB_CLASSPATH = "webClasspath"; 64 private static final long serialVersionUID = 1L; 65 66 private transient int index; 67 private transient WizardDescriptor.Panel[] panels; 68 private transient WizardDescriptor wiz; 69 70 public NewWebFreeformProjectWizardIterator() { 71 } 72 73 private WizardDescriptor.Panel[] createPanels () { 74 List l = new ArrayList (); 75 List extraTargets = new ArrayList (); 76 extraTargets.add(WebProjectNature.getExtraTarget()); 77 l.add(NewFreeformProjectSupport.createBasicProjectInfoWizardPanel()); 78 l.add(NewFreeformProjectSupport.createTargetMappingWizardPanel(extraTargets)); 79 l.add(new WebLocationsWizardPanel()); 80 l.addAll(Arrays.asList(NewJavaFreeformProjectSupport.createJavaPanels())); 81 l.add(new WebClasspathWizardPanel()); 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 webSources = (List )wiz.getProperty(PROP_WEB_SOURCE_FOLDERS); 96 AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(helper); 97 WebProjectGenerator.putWebSourceFolder(helper, webSources); 98 99 List webModules = (List ) wiz.getProperty(PROP_WEB_WEBMODULES); 100 if (webModules != null) { 101 String webClasspath = (String )wiz.getProperty(NewWebFreeformProjectWizardIterator.PROP_WEB_CLASSPATH); 103 Iterator iter = webModules.iterator(); 104 WebProjectGenerator.WebModule wm; 105 while(iter.hasNext()){ 106 wm = (WebProjectGenerator.WebModule)iter.next(); 107 wm.classpath = webClasspath; 108 } 109 WebProjectGenerator.putWebModules (helper, aux, webModules); 110 } 111 112 Project p = ProjectManager.getDefault().findProject(helper.getProjectDirectory()); 113 ProjectManager.getDefault().saveProject(p); 114 } catch (IOException e) { 115 ioe[0] = e; 116 return; 117 } 118 }}); 119 if (ioe[0] != null) { 120 throw ioe[0]; 121 } 122 File nbProjectFolder = (File )wiz.getProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER); 123 Set resultSet = new HashSet (); 124 resultSet.add(FileUtil.toFileObject(nbProjectFolder)); 125 Project p = ProjectManager.getDefault().findProject(FileUtil.toFileObject(nbProjectFolder)); 126 if (p != null) { 127 Sources srcs = ProjectUtils.getSources(p); 128 if (srcs != null) { 129 SourceGroup[] grps = srcs.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT); 130 if (grps != null && grps.length > 0) { 131 resultSet.add(grps[0].getRootFolder()); 132 } 133 } 134 } 135 File f = nbProjectFolder.getParentFile(); 136 if (f != null) { 137 ProjectChooser.setProjectsFolder(f); 138 } 139 return resultSet; 140 } 141 142 143 public void initialize(WizardDescriptor wiz) { 144 this.wiz = wiz; 145 index = 0; 146 panels = createPanels(); 147 148 List l = new ArrayList (); 149 for (int i = 0; i < panels.length; i++) { 150 Component c = panels[i].getComponent(); 151 assert c instanceof JComponent ; 152 JComponent jc = (JComponent )c; 153 l.add(jc.getName()); 154 } 155 String [] steps = (String [])l.toArray(new String [l.size()]); 156 for (int i = 0; i < panels.length; i++) { 157 Component c = panels[i].getComponent(); 158 assert c instanceof JComponent ; 159 JComponent jc = (JComponent )c; 160 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); jc.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "TXT_NewWebFreeformProjectWizardIterator_NewProjectWizardTitle")); jc.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (NewWebFreeformProjectWizardIterator.class, "ACSD_NewWebFreeformProjectWizardIterator_NewProjectWizardTitle")); } 168 } 169 170 public void uninitialize(WizardDescriptor wiz) { 171 NewFreeformProjectSupport.uninitializeBasicProjectInfoWizardPanel(wiz); 172 NewFreeformProjectSupport.uninitializeTargetMappingWizardPanel(wiz); 173 NewJavaFreeformProjectSupport.uninitializeJavaPanels(wiz); 174 wiz.putProperty(PROP_WEB_SOURCE_FOLDERS, null); 175 wiz.putProperty(PROP_WEB_WEBMODULES, null); 176 this.wiz = null; 177 panels = null; 178 } 179 180 public String name() { 181 return MessageFormat.format (NbBundle.getMessage(NewWebFreeformProjectWizardIterator.class, "TXT_NewWebFreeformProjectWizardIterator_TitleFormat"), new Object [] {new Integer (index + 1), new Integer (panels.length) }); 183 } 184 185 public boolean hasNext() { 186 if (!NewJavaFreeformProjectSupport.enableNextButton(current())) { 187 return false; 188 } 189 return index < panels.length - 1; 190 } 191 public boolean hasPrevious() { 192 return index > 0; 193 } 194 public void nextPanel() { 195 if (!hasNext()) throw new NoSuchElementException (); 196 index++; 197 } 198 public void previousPanel() { 199 if (!hasPrevious()) throw new NoSuchElementException (); 200 index--; 201 } 202 public WizardDescriptor.Panel current () { 203 return panels[index]; 204 } 205 206 public final void addChangeListener(ChangeListener l) {} 208 public final void removeChangeListener(ChangeListener l) {} 209 210 211 } 212 | Popular Tags |