KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > JMSWizardPanel


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  * JMSWizardPanel.java
21  *
22  * Created on November 17, 2003, 12:57 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 import java.awt.Component JavaDoc;
28 import java.util.Vector JavaDoc;
29 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
30 import org.openide.WizardDescriptor;
31 import org.openide.loaders.TemplateWizard;
32 import org.openide.util.HelpCtx;
33
34 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
35
36 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
37 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
38 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper;
39 import org.openide.filesystems.FileObject;
40
41 /**
42  *
43  * @author nityad
44  */

45 public class JMSWizardPanel extends ResourceWizardPanel {
46         
47     /** The visual component that displays this panel.
48      * If you need to access the component from this class,
49      * just use getComponent().
50      */

51     private JMSWizardVisualPanel component;
52     private ResourceConfigHelper helper;
53     private Wizard wizardInfo;
54     private String JavaDoc[] groupNames;
55     private boolean setupValid = true;
56     
57     /** Creates a new instance of JMSWizardPanel */
58     public JMSWizardPanel(ResourceConfigHelper helper, Wizard wizardInfo) {
59         this.helper = helper;
60         this.wizardInfo = wizardInfo;
61         this.groupNames = new String JavaDoc[]{"general"}; //NOI18N
62
}
63     
64     // Get the visual component for the panel. In this template, the component
65
// is kept separate. This can be more efficient: if the wizard is created
66
// but never displayed, or not all panels are displayed, it is better to
67
// create only those which really need to be visible.
68
public Component JavaDoc getComponent() {
69         if (component == null) {
70                 FieldGroup[] groups = new FieldGroup[groupNames.length];
71                 for (int i = 0; i < this.groupNames.length; i++) {
72                     groups[i] = FieldGroupHelper.getFieldGroup(wizardInfo, this.groupNames[i]); //NOI18N
73
}
74                 String JavaDoc panelType = null;
75                 component = new JMSWizardVisualPanel(this, groups);
76         }
77         return component;
78     }
79     
80     public boolean createNew() {
81         if (component == null)
82             return false;
83         else{
84             return true;
85             //return component.createNew();
86
}
87     }
88     
89     public HelpCtx getHelp() {
90        return new HelpCtx("AS_Wiz_JMS_general"); //NOI18N
91
}
92     
93     public ResourceConfigHelper getHelper() {
94         return helper;
95     }
96     
97     public boolean isValid() {
98         //Fix for bug# 5025502 & 5025573 - User should not be allowed to register a
99
//JMS Resource without JNDI name or invalid name
100
if(! setupValid){
101             setErrorMsg(bundle.getString("Err_InvalidSetup"));
102             return false;
103         }
104         setErrorMsg(bundle.getString("Empty_String"));
105         String JavaDoc jndiName = helper.getData().getString("jndi-name"); //NOI18N
106
if(jndiName.trim().length() == 0 || jndiName.trim().equals("")) {//NOI18N
107
setErrorMsg(bundle.getString("Err_InvalidJndiName"));
108             return false;
109         }else if(! ResourceUtils.isLegalResourceName(jndiName))
110             return false;
111         else if(! ResourceUtils.isUniqueFileName(jndiName, this.helper.getData().getTargetFileObject(), __JMSResource)){
112             setErrorMsg(bundle.getString("Err_DuplFileJndiName"));
113             return false;
114         }else
115             return true;
116     }
117   
118     public FieldGroup getFieldGroup(String JavaDoc groupName) {
119         return FieldGroupHelper.getFieldGroup(wizardInfo, groupName);
120     }
121     
122     public void readSettings(Object JavaDoc settings) {
123         this.wizDescriptor = (WizardDescriptor)settings;
124         TemplateWizard wizard = (TemplateWizard)settings;
125         String JavaDoc targetName = wizard.getTargetName();
126         FileObject resFolder = ResourceUtils.getResourceDirectory(this.helper.getData().getTargetFileObject());
127         this.helper.getData().setTargetFileObject (resFolder);
128         if(resFolder != null){
129             targetName = ResourceUtils.createUniqueFileName (targetName, resFolder, __JMSResource);
130             this.helper.getData ().setTargetFile (targetName);
131             if(component == null)
132                 getComponent ();
133             component.setHelper (this.helper);
134         }else
135             setupValid = false;
136     }
137     
138     public boolean isFinishPanel() {
139         isValid();
140         ResourceConfigData data = helper.getData();
141         Vector JavaDoc vec = data.getProperties();
142         for (int i = 0; i < vec.size(); i++) {
143             NameValuePair pair = (NameValuePair)vec.elementAt(i);
144             if (pair.getParamName() == null || pair.getParamValue() == null ||
145                     pair.getParamName().length() == 0 || pair.getParamValue().length() == 0){
146                 return false;
147             }
148         }
149         return true;
150     }
151     
152     private boolean setupValid(){
153         return setupValid;
154     }
155 }
156
Popular Tags