KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > wizards > TagHandlerSelection


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.web.wizards;
21
22 import java.awt.Component JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.netbeans.api.project.ProjectUtils;
29
30 import org.openide.WizardDescriptor;
31 import org.openide.util.HelpCtx;
32 import org.openide.loaders.TemplateWizard;
33
34 import org.netbeans.api.project.Project;
35 import org.netbeans.api.project.Sources;
36 import org.netbeans.api.project.SourceGroup;
37 import org.netbeans.api.java.project.JavaProjectConstants;
38 import org.netbeans.spi.project.ui.templates.support.Templates;
39 import org.netbeans.modules.web.api.webmodule.WebModule;
40
41 /** A single panel descriptor for a wizard.
42  * You probably want to make a wizard iterator to hold it.
43  *
44  * @author Milan Kuchtiak
45  */

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

52     private transient TagHandlerPanel component;
53     private transient TemplateWizard wizard;
54     private transient String JavaDoc j2eeVersion;
55     
56     /** Create the wizard panel descriptor. */
57     public TagHandlerSelection(TemplateWizard wizard) {
58         this.wizard=wizard;
59     }
60     
61     // Get the visual component for the panel. In this template, the component
62
// is kept separate. This can be more efficient: if the wizard is created
63
// but never displayed, or not all panels are displayed, it is better to
64
// create only those which really need to be visible.
65
public Component JavaDoc getComponent() {
66         Project project = Templates.getProject( wizard );
67         Sources sources = ProjectUtils.getSources(project);
68         SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
69         WebModule wm=null;
70         j2eeVersion = WebModule.J2EE_14_LEVEL;
71         if (groups!=null && groups.length>0) {
72             wm = WebModule.getWebModule(groups[0].getRootFolder());;
73         }
74         if (wm!=null) {
75             j2eeVersion=wm.getJ2eePlatformVersion();
76         }
77         if (component == null) {
78             component = new TagHandlerPanel(this,j2eeVersion);
79         }
80         return component;
81     }
82     
83     public HelpCtx getHelp() {
84         return null;
85         //return new HelpCtx(TagHandlerSelection.class); //NOI18N
86
}
87     
88     public boolean isValid() {
89         // If it is always OK to press Next or Finish, then:
90
if (!isBodyTagSupport() && WebModule.J2EE_13_LEVEL.equals(j2eeVersion)) {
91             wizard.putProperty("WizardPanel_errorMessage", // NOI18N
92
org.openide.util.NbBundle.getMessage(TagHandlerSelection.class, "NOTE_simpleTag"));
93         } else {
94             wizard.putProperty("WizardPanel_errorMessage", ""); // NOI18N
95
}
96         return true;
97         // If it depends on some condition (form filled out...), then:
98
// return someCondition ();
99
// and when this condition changes (last form field filled in...) then:
100
// fireChangeEvent ();
101
// and uncomment the complicated stuff below.
102
}
103  
104     //public final void addChangeListener(ChangeListener l) {}
105
//public final void removeChangeListener(ChangeListener l) {}
106

107     private final Set JavaDoc listeners = new HashSet JavaDoc (1); // Set<ChangeListener>
108
public final void addChangeListener (ChangeListener JavaDoc l) {
109         synchronized (listeners) {
110             listeners.add (l);
111         }
112     }
113     public final void removeChangeListener (ChangeListener JavaDoc l) {
114         synchronized (listeners) {
115             listeners.remove (l);
116         }
117     }
118     protected final void fireChangeEvent () {
119         Iterator JavaDoc it;
120         synchronized (listeners) {
121             it = new HashSet JavaDoc (listeners).iterator ();
122         }
123         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc (this);
124         while (it.hasNext ()) {
125             ((ChangeListener JavaDoc) it.next ()).stateChanged (ev);
126         }
127     }
128
129     
130     // You can use a settings object to keep track of state.
131
// Normally the settings object will be the WizardDescriptor,
132
// so you can use WizardDescriptor.getProperty & putProperty
133
// to store information entered by the user.
134
public void readSettings(Object JavaDoc settings) {
135     }
136     public void storeSettings(Object JavaDoc settings) {
137         WizardDescriptor w = (WizardDescriptor)settings;
138         if (isBodyTagSupport())
139             w.putProperty("BODY_SUPPORT",Boolean.TRUE);//NOI18N
140
else
141             w.putProperty("BODY_SUPPORT",Boolean.FALSE);//NOI18N
142
}
143     
144     boolean isBodyTagSupport() {return component.isBodyTagSupport();}
145     
146 }
147
Popular Tags