KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > ui > TargetMappingWizardPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.freeform.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Set JavaDoc;
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
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 /**
44  * @author David Konecny
45  */

46 public class TargetMappingWizardPanel implements WizardDescriptor.Panel {
47
48     public static final String JavaDoc PROP_TARGET_MAPPINGS = "targetMappings"; // <List> NOI18N
49

50     private TargetMappingPanel component;
51     private WizardDescriptor wizardDescriptor;
52     private List JavaDoc<TargetDescriptor> targets;
53     private List JavaDoc<String JavaDoc> targetNames;
54     
55     public TargetMappingWizardPanel(List JavaDoc<TargetDescriptor> targets) {
56         this.targets = targets;
57         getComponent().setName(NbBundle.getMessage(TargetMappingWizardPanel.class, "WizardPanel_BuildAndRunActions"));
58     }
59     
60     public Component JavaDoc 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 JavaDoc<ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
78     public final void addChangeListener(ChangeListener JavaDoc l) {
79         synchronized (listeners) {
80             listeners.add(l);
81         }
82     }
83     public final void removeChangeListener(ChangeListener JavaDoc l) {
84         synchronized (listeners) {
85             listeners.remove(l);
86         }
87     }
88     protected final void fireChangeEvent() {
89         Set JavaDoc<ChangeListener JavaDoc> ls;
90         synchronized (listeners) {
91             ls = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners);
92         }
93         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
94         for (ChangeListener JavaDoc l : ls) {
95             l.stateChanged(ev);
96         }
97     }
98     
99     public void readSettings(Object JavaDoc settings) {
100         wizardDescriptor = (WizardDescriptor)settings;
101         wizardDescriptor.putProperty("NewProjectWizard_Title", component.getClientProperty("NewProjectWizard_Title")); // NOI18N
102
File JavaDoc f = (File JavaDoc)wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_ANT_SCRIPT);
103         FileObject fo = FileUtil.toFileObject(f);
104         // Util.getAntScriptTargetNames can return null when script is
105
// invalid but first panel checks script validity so it is OK here.
106
List JavaDoc<String JavaDoc> l = Util.getAntScriptTargetNames(fo);
107         // #47784 - update panel only once or when Ant script has changed
108
if (targetNames == null || !targetNames.equals(l)) {
109             targetNames = new ArrayList JavaDoc<String JavaDoc>(l);
110             component.setTargetNames(l, true);
111         }
112         File JavaDoc projDir = (File JavaDoc)wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER);
113         File JavaDoc antScript = (File JavaDoc)wizardDescriptor.getProperty(NewFreeformProjectSupport.PROP_ANT_SCRIPT);
114         if (!(antScript.getParentFile().equals(projDir) && antScript.getName().equals("build.xml"))) { // NOI18N
115
// NON-DEFAULT location of build file
116
component.setScript("${"+ProjectConstants.PROP_ANT_SCRIPT+"}"); // NOI18N
117
} else {
118             component.setScript(null);
119         }
120     }
121     
122     public void storeSettings(Object JavaDoc settings) {
123         wizardDescriptor = (WizardDescriptor)settings;
124         wizardDescriptor.putProperty(PROP_TARGET_MAPPINGS, component.getMapping());
125         wizardDescriptor.putProperty("NewProjectWizard_Title", null); // NOI18N
126
}
127     
128 }
129
Popular Tags