KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > ejbmodule > EjbJarRootCustomizer


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  * EjbJarRootCustomizer.java
21  *
22  * Created on October 1, 2003, 3:40 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
26
27 import java.beans.PropertyVetoException JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29
30 import org.netbeans.modules.j2ee.sun.share.configbean.EjbJarRoot;
31 import org.netbeans.modules.j2ee.sun.share.configbean.EjbJarVersion;
32 import org.netbeans.modules.j2ee.sun.share.configbean.ErrorMessageDB;
33 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
34 import org.netbeans.modules.j2ee.sun.share.configbean.ValidationError;
35 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer;
36 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.CustomizerTitlePanel;
37
38
39 /**
40  *
41  * @author Rajeshwar Patil
42  */

43 public class EjbJarRootCustomizer extends BaseCustomizer {
44
45     static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
46             "org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule.Bundle"); // NOI18N
47

48     private EjbJarRoot theBean;
49     
50     private EjbJarPmDescriptorsPanel pmDescriptorPanel;
51     private EjbJarMessagesPanel messagesPanel;
52     private EjbJarCmpResourcePanel cmpResourcePanel;
53     
54     // true during initialization
55
private boolean fieldInit;
56
57     // true for j2ee 1.4 onward.
58
private boolean ejb20FeaturesVisible;
59     
60     /** Creates new customizer EjbJarRootCustomizer */
61     public EjbJarRootCustomizer() {
62         initComponents();
63         initUserComponents();
64     }
65     
66     public EjbJarRoot getBean() {
67         return theBean;
68     }
69     
70     /** This method is called from within the constructor to
71      * initialize the form.
72      * WARNING: Do NOT modify this code. The content of this method is
73      * always regenerated by the FormEditor.
74      */

75     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
76
private void initComponents() {
77         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
78
79         nameLabel = new javax.swing.JLabel JavaDoc();
80         nameTextField = new javax.swing.JTextField JavaDoc();
81         tabbedPanel = new javax.swing.JTabbedPane JavaDoc();
82
83         setLayout(new java.awt.GridBagLayout JavaDoc());
84
85         nameLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("MNC_Name").charAt(0));
86         nameLabel.setLabelFor(nameTextField);
87         nameLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("LBL_Name_1"));
88         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
89         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
90         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
91         add(nameLabel, gridBagConstraints);
92         nameLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("Name_Acsbl_Name"));
93         nameLabel.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("Ejb_Module_Name_Acsbl_Desc"));
94
95         nameTextField.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("Ejb_Module_Name_Tool_Tip"));
96         nameTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
97             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
98                 nameTextFieldKeyReleased(evt);
99             }
100         });
101
102         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
103         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
104         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105         gridBagConstraints.weightx = 1.0;
106         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
107         add(nameTextField, gridBagConstraints);
108         nameTextField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("Name_Acsbl_Name"));
109         nameTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/share/configbean/customizers/ejbmodule/Bundle").getString("Ejb_Module_Name_Acsbl_Desc"));
110
111         tabbedPanel.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
112         tabbedPanel.addChangeListener(new javax.swing.event.ChangeListener JavaDoc() {
113             public void stateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {
114                 tabbedPanelStateChanged(evt);
115             }
116         });
117
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
120         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         gridBagConstraints.weightx = 1.0;
123         gridBagConstraints.weighty = 1.0;
124         add(tabbedPanel, gridBagConstraints);
125
126     }// </editor-fold>//GEN-END:initComponents
127

128     private void tabbedPanelStateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {//GEN-FIRST:event_tabbedPanelStateChanged
129
showErrors();
130     }//GEN-LAST:event_tabbedPanelStateChanged
131

132     private void nameTextFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_nameTextFieldKeyReleased
133
String JavaDoc newName = nameTextField.getText();
134         String JavaDoc oldName = theBean.getName();
135
136         try {
137             if(Utils.notEmpty(newName)) {
138                 theBean.setName(newName);
139             } else {
140                 theBean.setName(null);
141             }
142             
143             validateField(EjbJarRoot.FIELD_EJBJAR_NAME);
144         } catch (PropertyVetoException JavaDoc ex) {
145             // this should never happen.
146
}
147     }//GEN-LAST:event_nameTextFieldKeyReleased
148

149     // Variables declaration - do not modify//GEN-BEGIN:variables
150
private javax.swing.JLabel JavaDoc nameLabel;
151     private javax.swing.JTextField JavaDoc nameTextField;
152     protected javax.swing.JTabbedPane JavaDoc tabbedPanel;
153     // End of variables declaration//GEN-END:variables
154

155     private void initUserComponents() {
156         ejb20FeaturesVisible = true;
157         
158         // Add title panel
159
CustomizerTitlePanel titlePanel = new CustomizerTitlePanel();
160         titlePanel.setCustomizerTitle(bundle.getString("LBL_SunEjbJar")); //NOI18N
161
add(titlePanel, titlePanel.getConstraints(), 0);
162         
163         // add CMP Resource panel
164
cmpResourcePanel = new EjbJarCmpResourcePanel(this);
165         tabbedPanel.addTab(bundle.getString("CMP_RESOURCE_TAB"), cmpResourcePanel); // NOI18N
166

167         // add PM Descriptors panel
168
pmDescriptorPanel = new EjbJarPmDescriptorsPanel(this);
169         tabbedPanel.addTab(bundle.getString("PM_DESCRIPTORS_TAB"), pmDescriptorPanel); // NOI18N
170

171         // add Messages panel
172
messagesPanel = new EjbJarMessagesPanel(this);
173         tabbedPanel.addTab(bundle.getString("MESSAGES_TAB"), messagesPanel); // NOI18N
174

175         // Add error panel
176
addErrorPanel();
177     }
178
179     protected void initFields() {
180         try {
181             fieldInit = true;
182             nameTextField.setText(theBean.getName());
183
184             cmpResourcePanel.initFields(theBean);
185             pmDescriptorPanel.initFields(theBean);
186             
187             if(theBean.getJ2EEModuleVersion().compareTo(EjbJarVersion.EJBJAR_2_0) >= 0) {
188                 showEjb20Panels();
189                 messagesPanel.initFields(theBean);
190             } else {
191                 hideEjb20Panels();
192             }
193         } finally {
194             fieldInit = false;
195         }
196     }
197     
198     private void showEjb20Panels() {
199         if(!ejb20FeaturesVisible) {
200             tabbedPanel.insertTab(bundle.getString("MESSAGES_TAB"), // NOI18N
201
null, messagesPanel, null, getMessagesTabIndex());
202             ejb20FeaturesVisible = true;
203         }
204     }
205     
206     private void hideEjb20Panels() {
207         if(ejb20FeaturesVisible) {
208             tabbedPanel.removeTabAt(getMessagesTabIndex()); // Remove messages panel
209
ejb20FeaturesVisible = false;
210         }
211     }
212     
213     protected void addListeners() {
214         super.addListeners();
215         
216         cmpResourcePanel.addListeners();
217         pmDescriptorPanel.addListeners();
218         messagesPanel.addListeners();
219     }
220     
221     protected void removeListeners() {
222         super.removeListeners();
223         
224         messagesPanel.removeListeners();
225         pmDescriptorPanel.removeListeners();
226         cmpResourcePanel.removeListeners();
227     }
228
229     public void partitionStateChanged(ErrorMessageDB.PartitionState oldState, ErrorMessageDB.PartitionState newState) {
230         if(newState.getPartition() == getPartition()) {
231             showErrors();
232         }
233         
234         if(oldState.hasMessages() != newState.hasMessages()) {
235             tabbedPanel.setIconAt(newState.getPartition().getTabIndex(), newState.hasMessages() ? panelErrorIcon : null);
236         }
237     }
238     
239     protected boolean setBean(Object JavaDoc bean) {
240         boolean result = super.setBean(bean);
241         
242         if(bean instanceof EjbJarRoot) {
243             theBean = (EjbJarRoot) bean;
244             result = true;
245         } else {
246             // if bean is not a EjbJarRoot, then it shouldn't have passed Base either.
247
assert (result == false) :
248                 "EjbJarRootCustomizer was passed wrong bean type in setBean(Object bean)"; // NOI18N
249

250             theBean = null;
251             result = false;
252         }
253         
254         return result;
255     }
256
257     private int getMessagesTabIndex() {
258         return 3;
259     }
260     
261     /** Returns the help ID for sun-ejb-jar root customizer, based on current
262      * selected tab.
263      *
264      * @return String representing the current active help ID for this customizer
265      */

266     public String JavaDoc getHelpId() {
267         // Determine which tab has focus and return help context for that tab.
268
switch(tabbedPanel.getSelectedIndex()) {
269             case 2:
270                 return "AS_CFG_EjbJarMessages"; // NOI18N
271
case 1:
272                 return "AS_CFG_EjbJarPmDescriptors"; // NOI18N
273
case 0:
274                 return "AS_CFG_EjbJarCmpResource"; // NOI18N
275
default:
276                 return "AS_CFG_EjbJarRoot"; // NOI18N
277
}
278     }
279
280     /** Retrieve the partition that should be associated with the current
281      * selected tab.
282      *
283      * @return ValidationError.Partition
284      */

285     public ValidationError.Partition getPartition() {
286         switch(tabbedPanel.getSelectedIndex()) {
287             case 2:
288                 return ValidationError.PARTITION_EJBJAR_MESSAGES;
289             case 1:
290                 return ValidationError.PARTITION_EJBJAR_PM_DESCRIPTORS;
291             case 0:
292                 return ValidationError.PARTITION_EJBJAR_CMP_RESOURCE;
293             default:
294                 return ValidationError.PARTITION_GLOBAL;
295         }
296     }
297 }
298
Popular Tags