KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > templates > SunDDWizardPanel


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 package org.netbeans.modules.j2ee.sun.share.configbean.templates;
20
21 import java.awt.Component JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.ChangeListener JavaDoc;
30
31 import org.openide.WizardDescriptor;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35
36 import org.netbeans.api.project.Project;
37 import org.netbeans.spi.project.ui.templates.support.Templates;
38
39
40 /*
41  *
42  * @author Peter Williams
43  */

44 public class SunDDWizardPanel implements WizardDescriptor.Panel {
45     
46     /**
47      * The visual component that displays this panel. If you need to access the
48      * component from this class, just use getComponent().
49      */

50 // private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1);
51
private final Set JavaDoc listeners = new HashSet JavaDoc(1);
52     private SunDDVisualPanel component = new SunDDVisualPanel();
53     private WizardDescriptor wizardDescriptor;
54     private Project project;
55     
56     public SunDDWizardPanel() {
57         component.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
58             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
59                 fireChangeEvent();
60             }
61         });
62     }
63     
64 // FileObject getSelectedLocation() {
65
File JavaDoc getSelectedLocation() {
66         return component.getSelectedLocation();
67     }
68     
69     Project getProject() {
70         return project;
71     }
72     
73     String JavaDoc getFileName() {
74         return component.getFileName();
75     }
76     
77     public Component JavaDoc getComponent() {
78         return component;
79     }
80     
81     public HelpCtx getHelp() {
82         // Show no Help button for this panel:
83
return HelpCtx.DEFAULT_HELP;
84         // If you have context help:
85
// return new HelpCtx(SampleWizardPanel1.class);
86
}
87     
88     public boolean isValid() {
89
90         String JavaDoc sunDDFileName = component.getFileName();
91         if(sunDDFileName == null) {
92             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
93
NbBundle.getMessage(SunDDWizardPanel.class,"ERR_NoJavaEEModuleType")); //NOI18N
94
return false;
95         }
96         
97         File JavaDoc location = component.getSelectedLocation();
98         if(location == null) {
99             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
100
NbBundle.getMessage(SunDDWizardPanel.class,"ERR_NoValidLocation", sunDDFileName)); //NOI18N
101
return false;
102         }
103
104         File JavaDoc sunDDFile = component.getFile();
105         if(sunDDFile.exists()) {
106             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
107
NbBundle.getMessage(SunDDWizardPanel.class,"ERR_FileExists", sunDDFileName)); //NOI18N
108
return false;
109         }
110         
111         return true;
112     }
113     
114     public final void addChangeListener(ChangeListener JavaDoc l) {
115         synchronized (listeners) {
116             listeners.add(l);
117         }
118     }
119     
120     public final void removeChangeListener(ChangeListener JavaDoc l) {
121         synchronized (listeners) {
122             listeners.remove(l);
123         }
124     }
125     
126     protected final void fireChangeEvent() {
127 // Iterator<ChangeListener> it;
128
Iterator JavaDoc it;
129         synchronized (listeners) {
130 // it = new HashSet<ChangeListener>(listeners).iterator();
131
it = new HashSet JavaDoc(listeners).iterator();
132         }
133         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
134         while (it.hasNext()) {
135 // it.next().stateChanged(ev);
136
((ChangeListener JavaDoc)it.next()).stateChanged(ev);
137         }
138     }
139     
140     // You can use a settings object to keep track of state. Normally the
141
// settings object will be the WizardDescriptor, so you can use
142
// WizardDescriptor.getProperty & putProperty to store information entered
143
// by the user.
144
public void readSettings(Object JavaDoc settings) {
145         wizardDescriptor = (WizardDescriptor) settings;
146         if (project == null) {
147             project = Templates.getProject(wizardDescriptor);
148             component.setProject(project);
149         }
150     }
151     
152     public void storeSettings(Object JavaDoc settings) {
153     }
154     
155 }
156
157
Popular Tags