1 19 20 package org.netbeans.modules.ant.freeform.ui; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.util.ArrayList ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Set ; 29 import javax.swing.JComponent ; 30 import javax.swing.event.ChangeEvent ; 31 import javax.swing.event.ChangeListener ; 32 import org.netbeans.modules.ant.freeform.FreeformProjectGenerator; 33 import org.netbeans.modules.ant.freeform.Util; 34 import org.netbeans.modules.ant.freeform.spi.ProjectConstants; 35 import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; 36 import org.netbeans.modules.ant.freeform.spi.support.NewFreeformProjectSupport; 37 import org.openide.WizardDescriptor; 38 import org.openide.filesystems.FileObject; 39 import org.openide.filesystems.FileUtil; 40 import org.openide.util.HelpCtx; 41 import org.openide.util.NbBundle; 42 43 46 public class TargetMappingWizardPanel implements WizardDescriptor.Panel { 47 48 public static final String PROP_TARGET_MAPPINGS = "targetMappings"; 50 private TargetMappingPanel component; 51 private WizardDescriptor wizardDescriptor; 52 private List <TargetDescriptor> targets; 53 private List <String > targetNames; 54 55 public TargetMappingWizardPanel(List <TargetDescriptor> targets) { 56 this.targets = targets; 57 getComponent().setName(NbBundle.getMessage(TargetMappingWizardPanel.class, "WizardPanel_BuildAndRunActions")); 58 } 59 60 public Component getComponent() { 61 if (component == null) { 62 component = new TargetMappingPanel(targets, false); 63 component.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TargetMappingWizardPanel.class, "ACSD_TargetMappingWizardPanel")); 64 } 65 return component; 66 } 67 68 public HelpCtx getHelp() { 69 return new HelpCtx( TargetMappingWizardPanel.class ); 70 } 71 72 public boolean isValid() { 73 getComponent(); 74 return true; 75 } 76 77 private final Set <ChangeListener > listeners = new HashSet <ChangeListener >(1); 78 public final void addChangeListener(ChangeListener l) { 79 synchronized (listeners) { 80 listeners.add(l); 81 } 82 } 83 public final void removeChangeListener(ChangeListener l) { 84 synchronized (listeners) { 85 listeners.remove(l); 86 } 87 } 88 protected final void fireChangeEvent() { 89 Set <ChangeListener > ls; 90 synchronized (listeners) { 91 ls = new HashSet <ChangeListener >(listeners); 92 } 93 ChangeEvent ev = new ChangeEvent (this); 94 for (ChangeListener l : ls) { 95 l.stateChanged(ev); 96 } 97 } 98 99 public void readSettings(Object settings) { 100 wizardDescriptor = (WizardDescriptor)settings; 101 wizardDescriptor.putProperty("NewProjectWizard_Title", component.getClientProperty("NewProjectWizard_Title")); File f = (File )wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_ANT_SCRIPT); 103 FileObject fo = FileUtil.toFileObject(f); 104 List <String > l = Util.getAntScriptTargetNames(fo); 107 if (targetNames == null || !targetNames.equals(l)) { 109 targetNames = new ArrayList <String >(l); 110 component.setTargetNames(l, true); 111 } 112 File projDir = (File )wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER); 113 File antScript = (File )wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_ANT_SCRIPT); 114 if (!(antScript.getParentFile().equals(projDir) && antScript.getName().equals("build.xml"))) { component.setScript("${"+ProjectConstants.PROP_ANT_SCRIPT+"}"); } else { 118 component.setScript(null); 119 } 120 } 121 122 public void storeSettings(Object settings) { 123 wizardDescriptor = (WizardDescriptor)settings; 124 wizardDescriptor.putProperty(PROP_TARGET_MAPPINGS, component.getMapping()); 125 wizardDescriptor.putProperty("NewProjectWizard_Title", null); } 127 128 } 129 | Popular Tags |