KickJava   Java API By Example, From Geeks To Geeks.

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


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 ListenerPanel 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 ListenerVisualPanel component;
53     private transient TemplateWizard wizard;
54     
55     /** Create the wizard panel descriptor. */
56     public ListenerPanel(TemplateWizard wizard) {
57         this.wizard=wizard;
58     }
59     
60     // Get the visual component for the panel. In this template, the component
61
// is kept separate. This can be more efficient: if the wizard is created
62
// but never displayed, or not all panels are displayed, it is better to
63
// create only those which really need to be visible.
64
public Component JavaDoc getComponent() {
65         if (component == null) {
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             String JavaDoc 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             component = new ListenerVisualPanel(this,j2eeVersion);
78         }
79         return component;
80     }
81     
82     public HelpCtx getHelp() {
83         //return new HelpCtx(ListenerPanel.class);
84
return HelpCtx.DEFAULT_HELP;
85     }
86     /*
87     public boolean isValid() {
88         // If it is always OK to press Next or Finish, then:
89         return true;
90         // If it depends on some condition (form filled out...), then:
91         // return someCondition ();
92         // and when this condition changes (last form field filled in...) then:
93         // fireChangeEvent ();
94         // and uncomment the complicated stuff below.
95     }
96     */

97     public boolean isValid() {
98     if(isListenerSelected()) {
99         wizard.putProperty("WizardPanel_errorMessage", ""); //NOI18N
100
return true;
101     }
102     wizard.putProperty("WizardPanel_errorMessage", //NOI18N
103
org.openide.util.NbBundle.getMessage(ListenerPanel.class,"MSG_noListenerSelected"));
104     return false;
105     }
106     
107     //public final void addChangeListener(ChangeListener l) {}
108
//public final void removeChangeListener(ChangeListener l) {}
109

110     private final Set JavaDoc listeners = new HashSet JavaDoc (1); // Set<ChangeListener>
111
public final void addChangeListener (ChangeListener JavaDoc l) {
112         synchronized (listeners) {
113             listeners.add (l);
114         }
115     }
116     public final void removeChangeListener (ChangeListener JavaDoc l) {
117         synchronized (listeners) {
118             listeners.remove (l);
119         }
120     }
121     protected final void fireChangeEvent () {
122         Iterator JavaDoc it;
123         synchronized (listeners) {
124             it = new HashSet JavaDoc (listeners).iterator ();
125         }
126         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc (this);
127         while (it.hasNext ()) {
128             ((ChangeListener JavaDoc) it.next ()).stateChanged (ev);
129         }
130     }
131
132     
133     // You can use a settings object to keep track of state.
134
// Normally the settings object will be the WizardDescriptor,
135
// so you can use WizardDescriptor.getProperty & putProperty
136
// to store information entered by the user.
137
public void readSettings(Object JavaDoc settings) {
138     }
139     public void storeSettings(Object JavaDoc settings) {
140     }
141     boolean createElementInDD (){
142         return component.createElementInDD();
143     }
144     
145     boolean isContextListener() {return component.isContextListener();}
146     
147     boolean isContextAttrListener() {return component.isContextAttrListener();}
148     
149     boolean isSessionListener() {return component.isSessionListener();}
150     
151     boolean isSessionAttrListener() {return component.isSessionAttrListener();}
152     
153     boolean isRequestListener() {return component.isRequestListener();}
154     
155     boolean isRequestAttrListener() {return component.isRequestAttrListener();}
156     
157     boolean isListenerSelected() {
158         return isContextListener() || isContextAttrListener() ||
159             isSessionListener() || isSessionAttrListener() ||
160             isRequestListener() || isRequestAttrListener();
161     }
162 }
163
Popular Tags