1 19 20 package org.netbeans.modules.java.freeform.ui; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Set ; 30 import javax.swing.JComponent ; 31 import javax.swing.event.ChangeEvent ; 32 import javax.swing.event.ChangeListener ; 33 import org.netbeans.api.java.project.JavaProjectConstants; 34 import org.netbeans.modules.ant.freeform.spi.ProjectConstants; 35 import org.netbeans.modules.ant.freeform.spi.support.NewFreeformProjectSupport; 36 import org.netbeans.modules.java.freeform.JavaProjectGenerator; 37 import org.netbeans.modules.java.freeform.JavaProjectNature; 38 import org.netbeans.modules.java.freeform.spi.support.NewJavaFreeformProjectSupport; 39 import org.openide.WizardDescriptor; 40 import org.openide.util.HelpCtx; 41 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 42 import org.netbeans.spi.project.support.ant.PropertyProvider; 43 import org.netbeans.spi.project.support.ant.PropertyUtils; 44 import org.openide.util.NbBundle; 45 46 49 public class SourceFoldersWizardPanel implements WizardDescriptor.Panel, ChangeListener , WizardDescriptor.FinishablePanel { 50 51 private SourceFoldersPanel component; 52 private WizardDescriptor wizardDescriptor; 53 54 public SourceFoldersWizardPanel() { 55 getComponent().setName(NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_SourcePackageFolders")); 56 } 57 58 public Component getComponent() { 59 if (component == null) { 60 component = new SourceFoldersPanel(); 61 component.setChangeListener(this); 62 ((JComponent )component).getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(SourceFoldersWizardPanel.class, "ACSD_SourceFoldersWizardPanel")); } 64 return component; 65 } 66 67 public HelpCtx getHelp() { 68 return new HelpCtx( SourceFoldersWizardPanel.class ); 69 } 70 71 public boolean isValid() { 72 getComponent(); 73 wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); return true; 79 } 80 81 public boolean isFinishPanel() { 82 return true; 83 } 84 85 private final Set <ChangeListener > listeners = new HashSet <ChangeListener >(1); 86 public final void addChangeListener(ChangeListener l) { 87 synchronized (listeners) { 88 listeners.add(l); 89 } 90 } 91 public final void removeChangeListener(ChangeListener l) { 92 synchronized (listeners) { 93 listeners.remove(l); 94 } 95 } 96 protected final void fireChangeEvent() { 97 Collection <ChangeListener > ls; 98 synchronized (listeners) { 99 ls = new HashSet <ChangeListener >(listeners); 100 } 101 ChangeEvent ev = new ChangeEvent (this); 102 for (ChangeListener l : ls) { 103 l.stateChanged(ev); 104 } 105 } 106 107 public void readSettings(Object settings) { 108 wizardDescriptor = (WizardDescriptor)settings; 109 File projectLocation = (File )wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_PROJECT_LOCATION); 110 File projectFolder = (File )wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER); 111 PropertyEvaluator evaluator = PropertyUtils.sequentialPropertyEvaluator(null, new PropertyProvider[]{ 112 PropertyUtils.fixedPropertyProvider( 113 Collections.singletonMap(ProjectConstants.PROP_PROJECT_LOCATION, projectLocation.getAbsolutePath()))}); 114 115 ProjectModel pm = (ProjectModel)wizardDescriptor.getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL); 116 if (pm == null || 117 !pm.getBaseFolder().equals(projectLocation) || 118 !pm.getNBProjectFolder().equals(projectFolder)) { 119 pm = ProjectModel.createEmptyModel(projectLocation, projectFolder, evaluator); 120 wizardDescriptor.putProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL, pm); 121 } 122 List l = (List )wizardDescriptor.getProperty(NewJavaFreeformProjectSupport.PROP_EXTRA_JAVA_SOURCE_FOLDERS); 123 if (l != null) { 124 Iterator it = l.iterator(); 125 while (it.hasNext()) { 126 String path = (String )it.next(); 127 assert it.hasNext(); 128 String label = (String )it.next(); 129 boolean found = false; 131 for (int i = 0; i < pm.getSourceFoldersCount(); i++) { 132 JavaProjectGenerator.SourceFolder existingSf = pm.getSourceFolder(i); 133 if (existingSf.location.equals(path)) { 134 found = true; 135 break; 136 } 137 } 138 if (!found) { 140 JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder(); 141 sf.location = path; 142 sf.label = label; 143 sf.type = JavaProjectConstants.SOURCES_TYPE_JAVA; 144 sf.style = JavaProjectNature.STYLE_PACKAGES; 145 pm.addSourceFolder(sf, false); 146 } 147 } 148 } 149 150 wizardDescriptor.putProperty("NewProjectWizard_Title", component.getClientProperty("NewProjectWizard_Title")); component.setModel(pm, null); 152 } 153 154 public void storeSettings(Object settings) { 155 wizardDescriptor = (WizardDescriptor)settings; 156 wizardDescriptor.putProperty("NewProjectWizard_Title", null); } 158 159 public void stateChanged(ChangeEvent e) { 160 fireChangeEvent(); 161 } 162 163 } 164 | Popular Tags |