KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > 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  * Created on October 10, 2002
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 import java.awt.Component JavaDoc;
28 import javax.swing.JTextField JavaDoc;
29
30 import org.openide.loaders.TemplateWizard;
31 import org.openide.util.HelpCtx;
32
33 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
34
35 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
36 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
37 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper;
38 import org.openide.WizardDescriptor;
39 import org.openide.filesystems.FileObject;
40
41 /** A single panel descriptor for a wizard.
42  * You probably want to make a wizard iterator to hold it.
43  *
44  * @author shirleyc
45  */

46 public class CommonGeneralFinishPanel extends ResourceWizardPanel {
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 CommonGeneralFinishVisualPanel component;
53     private ResourceConfigHelper helper;
54     private Wizard wizardInfo;
55     private String JavaDoc[] groupNames;
56     private boolean setupValid = true;
57     
58     /** Create the wizard panel descriptor. */
59     public CommonGeneralFinishPanel(ResourceConfigHelper helper, Wizard wizardInfo, String JavaDoc[] groupNames) {
60         this.helper = helper;
61         this.wizardInfo = wizardInfo;
62         this.groupNames = groupNames;
63     }
64     
65     // Get the visual component for the panel. In this template, the component
66
// is kept separate. This can be more efficient: if the wizard is created
67
// but never displayed, or not all panels are displayed, it is better to
68
// create only those which really need to be visible.
69
public Component JavaDoc getComponent() {
70         if (component == null) {
71                 FieldGroup[] groups = new FieldGroup[groupNames.length];
72                 for (int i = 0; i < this.groupNames.length; i++) {
73                     groups[i] = FieldGroupHelper.getFieldGroup(wizardInfo, this.groupNames[i]); //NOI18N
74
}
75                 String JavaDoc panelType = null;
76                 if (wizardInfo.getName().equals(__MailResource)) {
77                     panelType = CommonGeneralFinishVisualPanel.TYPE_MAIL_RESOUCE;
78                 }
79                 component = new CommonGeneralFinishVisualPanel(this, groups, panelType);
80         }
81         return component;
82     }
83     
84     public boolean createNew() {
85         if (component == null)
86             return false;
87         else
88             return component.createNew();
89     }
90     
91     public String JavaDoc getResourceName() {
92         return this.wizardInfo.getName();
93     }
94     
95     public HelpCtx getHelp() {
96         if (wizardInfo.getName().equals(__MailResource)) {
97             return new HelpCtx("AS_Wiz_Mail_general"); //NOI18N
98
}else{
99             return HelpCtx.DEFAULT_HELP;
100         }
101         
102     }
103     
104     public ResourceConfigHelper getHelper() {
105         return helper;
106     }
107     
108     public boolean isValid() {
109         // If it is always OK to press Next or Finish, then:
110
if(! setupValid){
111             setErrorMsg(bundle.getString("Err_InvalidSetup"));
112             return false;
113         }
114         setErrorMsg(bundle.getString("Empty_String"));
115         if (component != null && component.jLabels != null && component.jFields != null) {
116             int i;
117             for (i=0; i < component.jLabels.length; i++) {
118                 String JavaDoc jLabel = (String JavaDoc)component.jLabels[i].getText();
119                 if (jLabel.equals(bundle.getString("LBL_" + __JndiName))) { //NOI18N
120
String JavaDoc jndiName = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
121                     if (jndiName == null || jndiName.length() == 0) {
122                         setErrorMsg(bundle.getString("Err_InvalidJndiName"));
123                         return false;
124                     }else if(! ResourceUtils.isLegalResourceName(jndiName)){
125                         return false;
126                     }else if(! ResourceUtils.isUniqueFileName(jndiName, this.helper.getData().getTargetFileObject(), __MAILResource)){
127                         setErrorMsg(bundle.getString("Err_DuplFileJndiName"));
128                         return false;
129                     }
130                 }
131                 if (wizardInfo.getName().equals(__MailResource)) {
132                     if (jLabel.equals(bundle.getString("LBL_" + __Host))) { // NO18N
133
String JavaDoc host = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
134                         if (host == null || host.length() == 0) {
135                             setErrorMessage(bundle.getString("Err_EmptyValue"), jLabel);
136                             return false;
137                         }
138                     }
139                     if (jLabel.equals(bundle.getString("LBL_" + __MailUser))) { // NO18N
140
String JavaDoc user = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
141                         if (user == null || user.length() == 0) {
142                             setErrorMessage(bundle.getString("Err_EmptyValue"), jLabel);
143                             return false;
144                         }
145                     }
146                     if (jLabel.equals(bundle.getString("LBL_" + __From))) { //NOI18N
147
String JavaDoc from = (String JavaDoc)((JTextField JavaDoc)component.jFields[i]).getText();
148                         if (from == null || from.length() == 0) {
149                             setErrorMessage(bundle.getString("Err_EmptyValue"), jLabel);
150                             return false;
151                         }
152                     }
153                 } //Validity checks applicable to only Mail Resource Wizard
154
}//for
155
}
156         return true;
157     }
158   
159     public boolean isFinishPanel() {
160         return isValid();
161     }
162      
163     public void readSettings(Object JavaDoc settings) {
164         this.wizDescriptor = (WizardDescriptor)settings;
165         if (wizardInfo.getName().equals(__MailResource)) {
166             TemplateWizard wizard = (TemplateWizard)settings;
167             String JavaDoc targetName = wizard.getTargetName();
168             FileObject resFolder = ResourceUtils.getResourceDirectory(this.helper.getData().getTargetFileObject());
169             this.helper.getData().setTargetFileObject (resFolder);
170             if(resFolder != null){
171                 targetName = ResourceUtils.createUniqueFileName (targetName, resFolder, __MAILResource);
172                 this.helper.getData ().setTargetFile (targetName);
173                 if(component == null)
174                     getComponent ();
175                 component.setHelper (this.helper);
176             }else
177                setupValid = false;
178         }
179     }
180     
181     public void initData() {
182         this.component.initData();
183     }
184     
185     private boolean setupValid(){
186         return setupValid;
187     }
188 }
189
190
Popular Tags