KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ui > WSEjbBindingsPanel


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 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui;
20
21 import java.awt.event.ItemListener JavaDoc;
22 import javax.swing.DefaultComboBoxModel JavaDoc;
23 import org.netbeans.modules.j2ee.websphere6.dd.beans.*;
24 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject;
25 import org.netbeans.modules.xml.multiview.*;
26 import org.netbeans.modules.xml.multiview.ui.*;
27 import org.netbeans.modules.xml.multiview.Error;
28 import org.openide.util.NbBundle;
29 /**
30  *
31  * @author dlm198383
32  */

33 public class WSEjbBindingsPanel extends SectionInnerPanel implements java.awt.event.ItemListener JavaDoc,DDXmiConstants{
34     EjbBindingsType ejbBinding;
35     WSMultiViewDataObject dObj;
36     private static String JavaDoc [] Types=new String JavaDoc [] {
37         NbBundle.getMessage(WSEjbBindingsPanel.class,"LBL_TypeSession"),
38         NbBundle.getMessage(WSEjbBindingsPanel.class,"LBL_TypeEntity"),
39         NbBundle.getMessage(WSEjbBindingsPanel.class,"LBL_TypeContainerManagedEntity"),
40         NbBundle.getMessage(WSEjbBindingsPanel.class,"LBL_TypeMessageDriven")
41     };
42     
43     private javax.swing.JTextField JavaDoc cmpConnectionFactoryNameField;
44     private javax.swing.JTextField JavaDoc cmpConnectionFactoryJndiNameField;
45     private javax.swing.JCheckBox JavaDoc cmpConnectionFactoryCheckBox;
46     private javax.swing.JComboBox JavaDoc cmpConnectionFactoryAuthType;
47     private final String JavaDoc FACTORY_NAME="CMP Connection Factory Name"; //NOI18N
48
private final String JavaDoc FACTORY_JNDI_NAME="CMP Connection Factory JNDI Name"; //NOI18N
49

50     /** Creates new form WSResRefBindingsPanel */
51     public WSEjbBindingsPanel(SectionView view,WSMultiViewDataObject dObj,EjbBindingsType ejbBinding) {
52         super(view);
53         this.dObj=dObj;
54         this.ejbBinding=ejbBinding;
55         initComponents();
56         bindCmpConnectionFactoryComponents();
57         initCmpConnectionFactoryComponents();
58         
59         
60         
61         
62         idField.setText(ejbBinding.getXmiId());
63         jndiNameField.setText(ejbBinding.getJndiName());
64         hrefField.setText(ejbBinding.getHref());
65         addModifier(hrefField);
66         addModifier(jndiNameField);
67         addModifier(idField);
68         beanTypeComboBox.setModel(new DefaultComboBoxModel JavaDoc(Types));
69         String JavaDoc xmiType=ejbBinding.getXmiType();
70         if(xmiType!=null) {
71             if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_SESSION)) {
72                 beanTypeComboBox.setSelectedIndex(0);
73             } else if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_ENTITY)) {
74                 beanTypeComboBox.setSelectedIndex(1);
75             } else if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_CONTAINER_MANAGED_ENTITY)) {
76                 beanTypeComboBox.setSelectedIndex(2);
77             } else if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_MESSAGEDRIVEN)) {
78                 beanTypeComboBox.setSelectedIndex(3);
79             } else {
80                 beanTypeComboBox.setSelectedIndex(-1);
81             }
82         } else {
83             beanTypeComboBox.setSelectedIndex(-1);
84         }
85         beanTypeComboBox.addItemListener(this);
86         getSectionView().getErrorPanel().clearError();
87         
88         ReferencesTableModel model = new ReferencesTableModel(dObj.getModelSynchronizer());
89         model.setHrefType(EJB_JAR);
90         ReferenceTablePanel ptp= new ReferenceTablePanel(dObj, model);
91         ptp.setModel(ejbBinding,ejbBinding.getReferences());
92         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
93         gridBagConstraints.gridx = 0;
94         gridBagConstraints.gridy = 10;
95         //gridBagConstraints.gridwidth = 4;
96
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
97         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
98         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 0);
99         gridBagConstraints.weightx = 1.0;
100         jPanel1.add(ptp,gridBagConstraints);
101         
102     }
103     private void bindCmpConnectionFactoryComponents() {
104         CMPConnectionFactory panel=(CMPConnectionFactory)cmpConnectionFactoryPanel;
105         cmpConnectionFactoryNameField=panel.getNameField();
106         cmpConnectionFactoryJndiNameField=panel.getJndiNameField();
107         cmpConnectionFactoryCheckBox=panel.getFactoryCheckBox();
108         cmpConnectionFactoryAuthType=panel.getAuthTypeComboBox();
109         panel.setComponentsBackground(SectionVisualTheme.getSectionActiveBackgroundColor());
110         panel.setEnabledComponents();
111     }
112     
113     private void initCmpConnectionFactoryComponents(){
114         addModifier(cmpConnectionFactoryNameField);
115         addModifier(cmpConnectionFactoryJndiNameField);
116         addValidatee(cmpConnectionFactoryNameField);
117         addValidatee(cmpConnectionFactoryJndiNameField);
118         
119         boolean factoryEnabled=(ejbBinding.getCmpConnectionFactory()==null)?false:true;
120         cmpConnectionFactoryCheckBox.setSelected(factoryEnabled);
121         
122         if(factoryEnabled) {
123             
124             cmpConnectionFactoryNameField.setText(
125                     ejbBinding.getCmpConnectionFactoryXmiId());
126             
127             cmpConnectionFactoryJndiNameField.setText(
128                     ejbBinding.getCmpConnectionFactoryJndiName());
129             
130             cmpConnectionFactoryAuthType.setSelectedItem(
131                     ejbBinding.getCmpConnectionFactoryResAuth());
132             
133         }
134         cmpConnectionFactoryCheckBox.addItemListener(this);
135         cmpConnectionFactoryAuthType.addItemListener(this);
136         ((CMPConnectionFactory)cmpConnectionFactoryPanel).setEnabledComponents();
137     }
138     
139     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
140         if (source==idField) {
141             ejbBinding.setXmiId((String JavaDoc)value);
142         } else if(source==jndiNameField) {
143             ejbBinding.setJndiName((String JavaDoc)value);
144         } else if(source==hrefField) {
145             ejbBinding.setHref((String JavaDoc)value);
146         } else if(source==cmpConnectionFactoryNameField) {
147             ejbBinding.setCmpConnectionFactoryXmiId((String JavaDoc)value);
148         } else if(source==cmpConnectionFactoryJndiNameField) {
149             ejbBinding.setCmpConnectionFactoryJndiName((String JavaDoc)value);
150         }
151         
152     }
153     
154     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
155         if (comp==idField) {
156             String JavaDoc val = (String JavaDoc)value;
157             if (val.length()==0) {
158                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "ID", comp));
159                 return;
160             }
161             getSectionView().getErrorPanel().clearError();
162         }
163         if(comp==jndiNameField) {
164             String JavaDoc val = (String JavaDoc)value;
165             if (val.length()==0) {
166                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "JNDI Name", comp));
167                 return;
168             }
169             getSectionView().getErrorPanel().clearError();
170         }
171         if(comp==hrefField) {
172             String JavaDoc val = (String JavaDoc)value;
173             if (val.length()==0) {
174                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Bean Name", comp));
175                 return;
176             }
177             getSectionView().getErrorPanel().clearError();
178         }
179         if(comp==cmpConnectionFactoryNameField) {
180             String JavaDoc val = (String JavaDoc)value;
181             if (val.length()==0) {
182                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, FACTORY_NAME, comp));
183                 return;
184             }
185             getSectionView().getErrorPanel().clearError();
186         }
187         if(comp==cmpConnectionFactoryJndiNameField) {
188             String JavaDoc val = (String JavaDoc)value;
189             if (val.length()==0) {
190                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, FACTORY_JNDI_NAME, comp));
191                 return;
192             }
193             getSectionView().getErrorPanel().clearError();
194         }
195     }
196     
197     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
198         if (idField==source) {
199             idField.setText(ejbBinding.getXmiId());
200         }
201         if (jndiNameField==source) {
202             jndiNameField.setText(ejbBinding.getJndiName());
203         }
204         if (hrefField==source) {
205             hrefField.setText(ejbBinding.getHref());
206         }
207         if (cmpConnectionFactoryNameField==source) {
208             cmpConnectionFactoryNameField.setText(ejbBinding.getCmpConnectionFactoryXmiId());
209         }
210         if (cmpConnectionFactoryJndiNameField==source) {
211             cmpConnectionFactoryNameField.setText(ejbBinding.getCmpConnectionFactoryJndiName());
212         }
213     }
214     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
215     }
216     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
217         if ("ID".equals(errorId)) return idField;
218         if ("JNDI Name".equals(errorId)) return jndiNameField;
219         if ("Bean Name".equals(errorId)) return hrefField;
220         if (FACTORY_NAME.equals(errorId)) return cmpConnectionFactoryNameField;
221         if (FACTORY_JNDI_NAME.equals(errorId)) return cmpConnectionFactoryJndiNameField;
222         return null;
223     }
224     public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
225         dObj.setChangedFromUI(true);
226         String JavaDoc selectedString=(String JavaDoc)beanTypeComboBox.getSelectedItem();
227         if(selectedString!=null) {
228             if(selectedString.equals(Types[0])) { //session
229
ejbBinding.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_SESSION);
230             } else if(selectedString.equals(Types[1])) { //entity
231
ejbBinding.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_ENTITY);
232             } else if(selectedString.equals(Types[2])) { //entity
233
ejbBinding.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_CONTAINER_MANAGED_ENTITY);
234             } else if(selectedString.equals(Types[3])) { //message driven
235
ejbBinding.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_MESSAGEDRIVEN);
236             } else {
237                 ejbBinding.setXmiType(null);
238                 
239             }
240         }
241         changeCmpConnectionFactoryState();
242         // TODO add your handling code here:
243
dObj.modelUpdatedFromUI();
244         //dObj.setChangedFromUI(true);
245
dObj.setChangedFromUI(false);
246     }
247     
248     private void changeCmpConnectionFactoryState() {
249         if(cmpConnectionFactoryCheckBox.isSelected()) {
250             ejbBinding.setCmpConnectionFactory("");
251             ejbBinding.setCmpConnectionFactoryXmiId(cmpConnectionFactoryNameField.getText());
252             ejbBinding.setCmpConnectionFactoryResAuth(
253                     cmpConnectionFactoryAuthType.getSelectedItem().toString());
254         } else {
255             ejbBinding.setCmpConnectionFactory(null);
256         }
257         ((CMPConnectionFactory)cmpConnectionFactoryPanel).setEnabledComponents();
258     }
259     
260     /** This will be called before model is changed from this panel
261      */

262     protected void startUIChange() {
263         dObj.setChangedFromUI(true);
264     }
265     
266     /** This will be called after model is changed from this panel
267      */

268     protected void endUIChange() {
269         dObj.modelUpdatedFromUI();
270         dObj.setChangedFromUI(false);
271     }
272     /** This method is called from within the constructor to
273      * initialize the form.
274      * WARNING: Do NOT modify this code. The content of this method is
275      * always regenerated by the Form Editor.
276      */

277     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
278
private void initComponents() {
279         jLabel1 = new javax.swing.JLabel JavaDoc();
280         jLabel2 = new javax.swing.JLabel JavaDoc();
281         jLabel3 = new javax.swing.JLabel JavaDoc();
282         idField = new javax.swing.JTextField JavaDoc();
283         jndiNameField = new javax.swing.JTextField JavaDoc();
284         hrefField = new javax.swing.JTextField JavaDoc();
285         typeLabel = new javax.swing.JLabel JavaDoc();
286         beanTypeComboBox = new javax.swing.JComboBox JavaDoc();
287         jPanel1 = new javax.swing.JPanel JavaDoc();
288         cmpConnectionFactoryPanel = new CMPConnectionFactory();
289         jLabel4 = new javax.swing.JLabel JavaDoc();
290         jSeparator1 = new javax.swing.JSeparator JavaDoc();
291
292         jLabel1.setText("Id:");
293
294         jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_JndiName"));
295
296         jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_BeanName"));
297
298         typeLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_BeanType"));
299
300         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
301
302         jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_ReferenceBindings"));
303
304         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
305         this.setLayout(layout);
306         layout.setHorizontalGroup(
307             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
308             .add(layout.createSequentialGroup()
309                 .addContainerGap()
310                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
311                     .add(org.jdesktop.layout.GroupLayout.TRAILING, cmpConnectionFactoryPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
312                     .add(layout.createSequentialGroup()
313                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
314                             .add(typeLabel)
315                             .add(jLabel2)
316                             .add(jLabel3)
317                             .add(jLabel1))
318                         .add(16, 16, 16)
319                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
320                             .add(idField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
321                             .add(hrefField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
322                             .add(jndiNameField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
323                             .add(beanTypeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
324                 .addContainerGap())
325             .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
326             .add(layout.createSequentialGroup()
327                 .add(21, 21, 21)
328                 .add(jLabel4)
329                 .addContainerGap(370, Short.MAX_VALUE))
330             .add(layout.createSequentialGroup()
331                 .addContainerGap()
332                 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
333                 .addContainerGap())
334         );
335         layout.setVerticalGroup(
336             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
337             .add(layout.createSequentialGroup()
338                 .addContainerGap()
339                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
340                     .add(idField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
341                     .add(jLabel1))
342                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
343                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
344                     .add(jndiNameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
345                     .add(jLabel2))
346                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
347                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
348                     .add(jLabel3)
349                     .add(hrefField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
350                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
351                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
352                     .add(typeLabel)
353                     .add(beanTypeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
354                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
355                 .add(cmpConnectionFactoryPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
356                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
357                 .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
358                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
359                 .add(jLabel4)
360                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
361                 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
362                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
363         );
364     }// </editor-fold>//GEN-END:initComponents
365

366     
367     // Variables declaration - do not modify//GEN-BEGIN:variables
368
private javax.swing.JComboBox JavaDoc beanTypeComboBox;
369     private javax.swing.JPanel JavaDoc cmpConnectionFactoryPanel;
370     private javax.swing.JTextField JavaDoc hrefField;
371     private javax.swing.JTextField JavaDoc idField;
372     private javax.swing.JLabel JavaDoc jLabel1;
373     private javax.swing.JLabel JavaDoc jLabel2;
374     private javax.swing.JLabel JavaDoc jLabel3;
375     private javax.swing.JLabel JavaDoc jLabel4;
376     private javax.swing.JPanel JavaDoc jPanel1;
377     private javax.swing.JSeparator JavaDoc jSeparator1;
378     private javax.swing.JTextField JavaDoc jndiNameField;
379     private javax.swing.JLabel JavaDoc typeLabel;
380     // End of variables declaration//GEN-END:variables
381

382 }
383
Popular Tags