KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > wizards > CommonPropertyPanel


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  * CommonPropertyPanel.java
21  */

22
23 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards;
24
25 import java.awt.Component JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Vector JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32
33 import org.openide.WizardDescriptor;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
38
39 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
40 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
41 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants;
42 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper;
43
44 /**
45  * Code reused from Appserver common API module
46  *
47  */

48 public class CommonPropertyPanel implements WizardDescriptor.Panel, WS70WizardConstants{
49     
50     private CommonPropertyVisualPanel component;
51     private ResourceConfigHelper helper;
52     private Wizard wiz;
53     boolean firstTime = false;
54     /** Creates a new instance of CommonPropertyPanel */
55     public CommonPropertyPanel(ResourceConfigHelper helper, Wizard wiz) {
56         this.helper = helper;
57         this.wiz = wiz;
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             component = new CommonPropertyVisualPanel(this);
67         }
68         return component;
69     }
70     
71     public void setInitialFocus(){
72         if(component != null) {
73             component.refreshFields();
74             component.setInitialFocus();
75         }
76     }
77     
78     public FieldGroup getFieldGroup(String JavaDoc groupName) {
79         return FieldGroupHelper.getFieldGroup(wiz, groupName);
80     }
81     
82     public ResourceConfigHelper getHelper() {
83         return helper;
84     }
85     
86     public HelpCtx getHelp() {
87         if (wiz.getName().equals(__JdbcResource)) {
88             return new HelpCtx("AS_Wiz_DataSource_props"); //NOI18N
89
//}else if (wiz.getName().equals(__PersistenceManagerFactoryResource)) {
90
// return new HelpCtx("AS_Wiz_PMF_props"); //NOI18N
91
}else {
92             return HelpCtx.DEFAULT_HELP;
93         }
94     }
95     
96     public boolean isValid() {
97         ResourceConfigData data = helper.getData();
98         Vector JavaDoc vec = data.getProperties();
99         for (int i = 0; i < vec.size(); i++) {
100             NameValuePair pair = (NameValuePair)vec.elementAt(i);
101             if (pair.getParamName() == null || pair.getParamValue() == null ||
102             pair.getParamName().length() == 0 || pair.getParamValue().length() == 0)
103                 return false;
104         }
105         return true;
106     }
107     
108    private final Set JavaDoc listeners = new HashSet JavaDoc(1);
109     
110     public final void addChangeListener(ChangeListener JavaDoc l) {
111         synchronized (listeners) {
112             listeners.add(l);
113         }
114     }
115     
116     public final void removeChangeListener(ChangeListener JavaDoc l) {
117         synchronized (listeners) {
118             listeners.remove(l);
119         }
120     }
121     
122     protected final void fireChangeEvent() {
123         Iterator JavaDoc it;
124         synchronized (listeners) {
125             it = new HashSet JavaDoc(listeners).iterator();
126         }
127         if(firstTime){
128             ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
129             while (it.hasNext()) {
130                 ((ChangeListener JavaDoc) it.next()).stateChanged(ev);
131             }
132         }else{
133             firstTime = true;
134         }
135     }
136     
137      // You can use a settings object to keep track of state.
138
// Normally the settings object will be the WizardDescriptor,
139
// so you can use WizardDescriptor.getProperty & putProperty
140
// to store information entered by the user.
141
public void readSettings(Object JavaDoc settings) {
142     }
143     public void storeSettings(Object JavaDoc settings) {
144     }
145     
146 }
147
Popular Tags