KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > dialogs > AddManagedBeanDialog


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.jsf.dialogs;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import javax.swing.SwingUtilities JavaDoc;
26 import org.netbeans.modules.web.jsf.JSFConfigDataObject;
27 import org.netbeans.modules.web.jsf.JSFConfigUtilities;
28 import org.netbeans.modules.web.jsf.api.ConfigurationUtils;
29 import org.netbeans.modules.web.jsf.api.facesmodel.FacesConfig;
30 import org.netbeans.modules.web.jsf.api.facesmodel.ManagedBean;
31 import org.netbeans.modules.web.jsf.api.facesmodel.ManagedBean;
32 import org.openide.util.NbBundle;
33
34 /**
35  *
36  * @author radko
37  */

38 public class AddManagedBeanDialog extends javax.swing.JPanel JavaDoc implements ValidatingPanel {
39     private JSFConfigDataObject config;
40     private Hashtable JavaDoc existingBeans = null;
41     /** Creates new form AddManagedBeanDialog */
42     public AddManagedBeanDialog(JSFConfigDataObject config) {
43         initComponents();
44         this.config = config;
45     }
46
47     public javax.swing.text.JTextComponent JavaDoc[] getDocumentChangeComponents() {
48         return new javax.swing.text.JTextComponent JavaDoc[]{jTextFieldName, jTextFieldClass};
49     }
50
51     public javax.swing.AbstractButton JavaDoc[] getStateChangeComponents() {
52         return new javax.swing.AbstractButton JavaDoc[]{ };
53     }
54
55     public String JavaDoc validatePanel() {
56         if (getName().length()==0)
57             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddManagedBean_EmptyName");
58         if (existingBeans == null){
59             existingBeans = new Hashtable JavaDoc();
60             ManagedBean bean;
61             //Iterator iter = JSFConfigUtilities.getAllManagedBeans(config).iterator();
62
FacesConfig facesConfig = ConfigurationUtils.getConfigModel(config.getPrimaryFile(), false).getRootComponent();
63             Collection JavaDoc<ManagedBean> beans = facesConfig.getManagedBeans();
64             for (Iterator JavaDoc<ManagedBean> it = beans.iterator(); it.hasNext();) {
65                 ManagedBean managedBean = it.next();
66                 existingBeans.put(managedBean.getManagedBeanName(), "");
67             }
68         }
69         if (existingBeans.get(getName()) != null)
70             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddManagedBean_BeanExist");
71         if (getBeanClass().length()==0)
72             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddManagedBean_EmptyClass");
73         return null;
74     }
75     
76     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
82
private void initComponents() {
83         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
84
85         jLabelClass = new javax.swing.JLabel JavaDoc();
86         jTextFieldClass = new javax.swing.JTextField JavaDoc();
87         jButtonClass = new javax.swing.JButton JavaDoc();
88         jLabelScope = new javax.swing.JLabel JavaDoc();
89         jComboBoxScope = new javax.swing.JComboBox JavaDoc();
90         jLabelDesc = new javax.swing.JLabel JavaDoc();
91         jScrollPaneDesc = new javax.swing.JScrollPane JavaDoc();
92         jTextAreaDesc = new javax.swing.JTextArea JavaDoc();
93         jLabelName = new javax.swing.JLabel JavaDoc();
94         jTextFieldName = new javax.swing.JTextField JavaDoc();
95
96         setLayout(new java.awt.GridBagLayout JavaDoc());
97
98         jLabelClass.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_ManagedBeanClass").charAt(0));
99         jLabelClass.setLabelFor(jTextFieldClass);
100         jLabelClass.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_ManagedBeanClass")); // NOI18N
101
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 0;
103         gridBagConstraints.gridy = 1;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
105         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 12);
106         add(jLabelClass, gridBagConstraints);
107         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
108         gridBagConstraints.gridx = 1;
109         gridBagConstraints.gridy = 1;
110         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
112         add(jTextFieldClass, gridBagConstraints);
113         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle"); // NOI18N
114
jTextFieldClass.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_BeanClass")); // NOI18N
115
jTextFieldClass.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_BeanClass")); // NOI18N
116

117         jButtonClass.setMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_Browse").charAt(0));
118         jButtonClass.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_Browse")); // NOI18N
119
jButtonClass.setEnabled(false);
120         jButtonClass.addActionListener(new java.awt.event.ActionListener JavaDoc() {
121             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
122                 jButtonClassActionPerformed(evt);
123             }
124         });
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridx = 2;
127         gridBagConstraints.gridy = 1;
128         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 11);
130         add(jButtonClass, gridBagConstraints);
131         jButtonClass.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Browse")); // NOI18N
132

133         jLabelScope.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_Scope").charAt(0));
134         jLabelScope.setLabelFor(jComboBoxScope);
135         jLabelScope.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_Scope")); // NOI18N
136
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridx = 0;
138         gridBagConstraints.gridy = 2;
139         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 12);
141         add(jLabelScope, gridBagConstraints);
142
143         jComboBoxScope.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "request", "session", "application", "none" }));
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 1;
146         gridBagConstraints.gridy = 2;
147         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
149         add(jComboBoxScope, gridBagConstraints);
150         jComboBoxScope.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_ManagedBeanScope")); // NOI18N
151
jComboBoxScope.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Scope")); // NOI18N
152

153         jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_BeanDescription").charAt(0));
154         jLabelDesc.setLabelFor(jTextAreaDesc);
155         jLabelDesc.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_BeanDescription")); // NOI18N
156
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 0;
158         gridBagConstraints.gridy = 3;
159         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
160         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
161         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
162         add(jLabelDesc, gridBagConstraints);
163
164         jTextAreaDesc.setColumns(20);
165         jTextAreaDesc.setRows(5);
166         jScrollPaneDesc.setViewportView(jTextAreaDesc);
167         jTextAreaDesc.getAccessibleContext().setAccessibleName(bundle.getString("ACN_ManagedBeanDescription")); // NOI18N
168
jTextAreaDesc.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_BeanDescription")); // NOI18N
169

170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridx = 1;
172         gridBagConstraints.gridy = 3;
173         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
174         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
175         gridBagConstraints.weightx = 1.0;
176         gridBagConstraints.weighty = 1.0;
177         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
178         add(jScrollPaneDesc, gridBagConstraints);
179
180         jLabelName.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("MNE_ManagedBeanName").charAt(0));
181         jLabelName.setLabelFor(jTextFieldName);
182         jLabelName.setText(bundle.getString("LBL_Bean_Name")); // NOI18N
183
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
184         gridBagConstraints.gridx = 0;
185         gridBagConstraints.gridy = 0;
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 5, 0);
188         add(jLabelName, gridBagConstraints);
189         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
190         gridBagConstraints.gridx = 1;
191         gridBagConstraints.gridy = 0;
192         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 5, 0);
194         add(jTextFieldName, gridBagConstraints);
195         jTextFieldName.getAccessibleContext().setAccessibleName(bundle.getString("ACS_BeanName")); // NOI18N
196
jTextFieldName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_BeanName")); // NOI18N
197

198         getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_AddManagedBeanDialog")); // NOI18N
199
getAccessibleContext().setAccessibleParent(this);
200     }// </editor-fold>//GEN-END:initComponents
201

202     private void jButtonClassActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonClassActionPerformed
203
SwingUtilities.invokeLater(new Runnable JavaDoc() {
204             public void run() {
205 //TODO: RETOUCHE FQN search
206
// FQNSearch.showFastOpen(jTextFieldClass);
207
}
208         });
209     }//GEN-LAST:event_jButtonClassActionPerformed
210

211     
212     // Variables declaration - do not modify//GEN-BEGIN:variables
213
private javax.swing.JButton JavaDoc jButtonClass;
214     private javax.swing.JComboBox JavaDoc jComboBoxScope;
215     private javax.swing.JLabel JavaDoc jLabelClass;
216     private javax.swing.JLabel JavaDoc jLabelDesc;
217     private javax.swing.JLabel JavaDoc jLabelName;
218     private javax.swing.JLabel JavaDoc jLabelScope;
219     private javax.swing.JScrollPane JavaDoc jScrollPaneDesc;
220     private javax.swing.JTextArea JavaDoc jTextAreaDesc;
221     private javax.swing.JTextField JavaDoc jTextFieldClass;
222     private javax.swing.JTextField JavaDoc jTextFieldName;
223     // End of variables declaration//GEN-END:variables
224

225     public String JavaDoc getBeanClass(){
226         return jTextFieldClass.getText();
227     }
228     
229     public String JavaDoc getScope(){
230         return (String JavaDoc)jComboBoxScope.getSelectedItem();
231     }
232     
233     public String JavaDoc getDescription(){
234         return jTextAreaDesc.getText();
235     }
236     
237     public String JavaDoc getName(){
238         return jTextFieldName.getText();
239     }
240 }
241
Popular Tags