KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards;
24
25 import java.awt.Component JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29 import java.util.Set JavaDoc;
30 import javax.swing.JTextField JavaDoc;
31 import javax.swing.event.ChangeEvent JavaDoc;
32 import javax.swing.event.ChangeListener JavaDoc;
33
34 import org.openide.loaders.TemplateWizard;
35 import org.openide.WizardDescriptor;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38
39 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70ResourceUtils;
40
41 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
42 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
43 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants;
44 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper;
45
46 /** A single panel descriptor for a wizard.
47  * You probably want to make a wizard iterator to hold it.
48  *
49  *
50  * Code reused from Appserver common API module
51  */

52 public class CommonGeneralFinishPanel implements WizardDescriptor.FinishablePanel, WS70WizardConstants {
53     protected ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.Bundle"); //NOI18N
54

55     
56     /** The visual component that displays this panel.
57      * If you need to access the component from this class,
58      * just use getComponent().
59      */

60     private CommonGeneralFinishVisualPanel component;
61     private ResourceConfigHelper helper;
62     private Wizard wizardInfo;
63     private String JavaDoc[] groupNames;
64     
65     /** Create the wizard panel descriptor. */
66     public CommonGeneralFinishPanel(ResourceConfigHelper helper, Wizard wizardInfo, String JavaDoc[] groupNames) {
67         this.helper = helper;
68         this.wizardInfo = wizardInfo;
69         this.groupNames = groupNames;
70     }
71     
72     // Get the visual component for the panel. In this template, the component
73
// is kept separate. This can be more efficient: if the wizard is created
74
// but never displayed, or not all panels are displayed, it is better to
75
// create only those which really need to be visible.
76
public Component JavaDoc getComponent() {
77         if (component == null) {
78                 FieldGroup[] groups = new FieldGroup[groupNames.length];
79                 for (int i = 0; i < this.groupNames.length; i++) {
80                     groups[i] = FieldGroupHelper.getFieldGroup(wizardInfo, this.groupNames[i]); //NOI18N
81
}
82                 String JavaDoc panelType = null;
83                 if (wizardInfo.getName().equals(__MailResource)) {
84                     panelType = CommonGeneralFinishVisualPanel.TYPE_MAIL_RESOURCE;
85                 }else if(wizardInfo.getName().equals(__CustomResource)) {
86                     panelType = CommonGeneralFinishVisualPanel.TYPE_CUSTOM_RESOURCE;
87                 }else if(wizardInfo.getName().equals(__ExternalJndiResource)) {
88                     panelType = CommonGeneralFinishVisualPanel.TYPE_EXTERNAL_RESOURCE;
89                 }else if(wizardInfo.getName().equals(WS70WizardConstants.__JdbcResource)) {
90                     panelType = CommonGeneralFinishVisualPanel.TYPE_JDBC_RESOURCE;
91                 }
92                 component = new CommonGeneralFinishVisualPanel(this, groups, panelType);
93         }
94         return component;
95     }
96     
97     public boolean createNew() {
98         if (component == null)
99             return false;
100         else
101             return component.createNew();
102     }
103     
104     public String JavaDoc getResourceName() {
105         return this.wizardInfo.getName();
106     }
107     
108     public HelpCtx getHelp() {
109         if (wizardInfo.getName().equals(__MailResource)) {
110             return new HelpCtx("AS_Wiz_Mail_general"); //NOI18N
111
}else{
112             return HelpCtx.DEFAULT_HELP;
113         }
114         
115     }
116     
117     public ResourceConfigHelper getHelper() {
118         return helper;
119     }
120     
121     public boolean isValid() {
122         // If it is always OK to press Next or Finish, then:
123
if (component != null && component.jLabels != null && component.jFields != null) {
124             int i;
125             for (i=0; i < component.jLabels.length; i++) {
126                 String JavaDoc jLabel = (String JavaDoc)component.jLabels[i].getText();
127                 if (jLabel.equals(bundle.getString("LBL_" + __JndiName))) { //NOI18N
128
String JavaDoc jndiName = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
129                     if (jndiName == null || jndiName.trim().length() == 0) {
130                         return false;
131                     }else if(! WS70ResourceUtils.isLegalResourceName(jndiName)){
132                         return false;
133                     }
134                 }
135                 if (wizardInfo.getName().equals(__MailResource)) {
136                     if (jLabel.equals(bundle.getString("LBL_" + __Host))) { // NO18N
137
String JavaDoc host = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
138                         if (host == null || host.trim().length() == 0) {
139                             return false;
140                         }
141                     }
142                     if (jLabel.equals(bundle.getString("LBL_" + __MailUser))) { // NO18N
143
String JavaDoc user = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
144                         if (user == null || user.trim().length() == 0) {
145                             return false;
146                         }
147                     }
148                     if (jLabel.equals(bundle.getString("LBL_" + __From))) { //NOI18N
149
String JavaDoc from = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
150                         if (from == null || from.trim().length() == 0) {
151                             return false;
152                         }
153                     }
154                 }else if(wizardInfo.getName().equals(this.__CustomResource)){
155                     if (jLabel.equals(bundle.getString("LBL_" + this.__ResType))) { // NO18N
156
String JavaDoc restype = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
157                         if (restype == null || restype.trim().length() == 0) {
158                             return false;
159                         }
160                     }
161                     if (jLabel.equals(bundle.getString("LBL_" + this.__FactoryClass))) { // NO18N
162
String JavaDoc factclass = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
163                         if (factclass == null || factclass.trim().length() == 0) {
164                             return false;
165                         }
166                     }
167                     
168                 }else if(wizardInfo.getName().equals(this.__ExternalJndiResource)){
169                     if (jLabel.equals(bundle.getString("LBL_" + this.__ResType))) { // NO18N
170
String JavaDoc restype = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
171                         if (restype == null || restype.trim().length() == 0) {
172                             return false;
173                         }
174                     }
175                     if (jLabel.equals(bundle.getString("LBL_" + this.__FactoryClass))) { // NO18N
176
String JavaDoc factclass = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
177                         if (factclass == null || factclass.trim().length() == 0) {
178                             return false;
179                         }
180                     }
181                     if (jLabel.equals(bundle.getString("LBL_" + this.__ExternalJndiName))) { // NO18N
182
String JavaDoc extjndiname = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
183                         if (extjndiname == null || extjndiname.trim().length() == 0) {
184                             return false;
185                         }
186                     }
187                     
188                 }else if(wizardInfo.getName().equals(this.__JdbcResource)){
189                     if (jLabel.equals(bundle.getString("LBL_" + this.__DatasourceClassname))) { // NO18N
190
String JavaDoc dsclassname = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
191                         if (dsclassname == null || dsclassname.trim().length() == 0) {
192                             return false;
193                         }
194                     }
195                 }
196             }//for
197
}
198         return true;
199         // If it depends on some condition (form filled out...), then:
200
// return someCondition ();
201
// and when this condition changes (last form field filled in...) then:
202
// fireChangeEvent ();
203
// and uncomment the complicated stuff below.
204
}
205   
206     public boolean isFinishPanel() {
207         return isValid();
208     }
209      
210     private final Set JavaDoc listeners = new HashSet JavaDoc (1);
211     public final void addChangeListener (ChangeListener JavaDoc l) {
212         synchronized (listeners) {
213             listeners.add (l);
214         }
215     }
216     public final void removeChangeListener (ChangeListener JavaDoc l) {
217         synchronized (listeners) {
218             listeners.remove (l);
219         }
220     }
221     protected final void fireChangeEvent () {
222         Iterator JavaDoc it;
223         synchronized (listeners) {
224             it = new HashSet JavaDoc (listeners).iterator ();
225         }
226         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc (this);
227         while (it.hasNext ()) {
228             ((ChangeListener JavaDoc) it.next ()).stateChanged (ev);
229         }
230     }
231      
232     
233     // You can use a settings object to keep track of state.155
234
// Normally the settings object will be the WizardDescriptor,
235
// so you can use WizardDescriptor.getProperty & putProperty
236
// to store information entered by the user.
237
public void readSettings(Object JavaDoc settings) {
238         if (wizardInfo.getName().equals(__MailResource)) {
239             TemplateWizard wizard = (TemplateWizard)settings;
240             String JavaDoc targetName = wizard.getTargetName();
241             targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __MAILResource);
242             this.helper.getData().setTargetFile(targetName);
243             if(component == null)
244                 getComponent();
245             component.setHelper(this.helper);
246         }else if (wizardInfo.getName().equals(__CustomResource)) {
247             TemplateWizard wizard = (TemplateWizard)settings;
248             String JavaDoc targetName = wizard.getTargetName();
249             targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __CUSTOMResource);
250             this.helper.getData().setTargetFile(targetName);
251             if(component == null)
252                 getComponent();
253             component.setHelper(this.helper);
254         }else if (wizardInfo.getName().equals(__ExternalJndiResource)) {
255             TemplateWizard wizard = (TemplateWizard)settings;
256             String JavaDoc targetName = wizard.getTargetName();
257             targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __EXTERNALResource);
258             this.helper.getData().setTargetFile(targetName);
259             if(component == null)
260                 getComponent();
261             component.setHelper(this.helper);
262         }else if (wizardInfo.getName().equals(__JdbcResource)) {
263             TemplateWizard wizard = (TemplateWizard)settings;
264             String JavaDoc targetName = wizard.getTargetName();
265             targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __JDBCResource);
266             this.helper.getData().setTargetFile(targetName);
267             if(component == null)
268                 getComponent();
269             component.setHelper(this.helper);
270         }
271     }
272     public void storeSettings(Object JavaDoc settings) {
273     }
274     
275     public void initData() {
276         this.component.initData();
277     }
278 }
279
280
Popular Tags