KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejbext.WSEjbExtDataObject;
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  *
32  * @author dlm198383
33  */

34 public class EjbExtensionPanel extends SectionInnerPanel implements java.awt.event.ItemListener JavaDoc {
35     EjbExtensionsType ejbExtension;
36     WSEjbExtDataObject dObj;
37     
38     private javax.swing.JCheckBox JavaDoc localTransactionCheckBox;
39     private javax.swing.JTextField JavaDoc transactionNameField;
40     
41     
42     private javax.swing.JComboBox JavaDoc unresolvedActionComboBox;
43     private javax.swing.JCheckBox JavaDoc resolverCheckBox;
44     private javax.swing.JComboBox JavaDoc resolverComboBox;
45     private javax.swing.JCheckBox JavaDoc boundaryCheckBox;
46     private javax.swing.JComboBox JavaDoc boundaryComboBox;
47     
48     
49     private static String JavaDoc [] Types=new String JavaDoc [] {
50         NbBundle.getMessage(EjbExtensionPanel.class,"LBL_TypeSession"),
51         NbBundle.getMessage(EjbExtensionPanel.class,"LBL_TypeEntity"),
52         NbBundle.getMessage(EjbExtensionPanel.class,"LBL_TypeMessageDriven")};
53     /** Creates new form WSResRefBindingsPanel */
54     public EjbExtensionPanel(SectionView view, WSEjbExtDataObject dObj, EjbExtensionsType ejbExtension) {
55         
56         super(view);
57         this.dObj=dObj;
58         this.ejbExtension=ejbExtension;
59         initComponents();
60         bindLocalTransactionComponents();
61         
62         initLocalTransactionComponents();
63         
64         ((LocalTransactionPanel)jPanel1).setEnabledComponents();
65         
66         typeComboBox.setModel(new DefaultComboBoxModel JavaDoc(Types));
67         
68         nameField.setText(ejbExtension.getXmiName());
69         idField.setText(ejbExtension.getXmiId());
70         beanIdField.setText(ejbExtension.getHref());
71         
72         String JavaDoc [] data = new String JavaDoc[] {
73             ejbExtension.getEjbExtensionsType(),
74             ejbExtension.getEnterpriseBean(),
75             ejbExtension.getHref(),
76             ejbExtension.getXmiId(),
77             ejbExtension.getXmiName(),
78             ejbExtension.getXmiType()
79         };
80         addModifier(nameField);
81         addModifier(idField);
82         addModifier(beanIdField);
83         
84         addValidatee(nameField);
85         addValidatee(idField);
86         addValidatee(beanIdField);
87         
88         
89         String JavaDoc xmiType=ejbExtension.getXmiType();
90         if(xmiType!=null) {
91             if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_SESSION)) {
92                 typeComboBox.setSelectedIndex(0);
93             } else if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_ENTITY)) {
94                 typeComboBox.setSelectedIndex(1);
95             } else if(xmiType.equals(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_MESSAGEDRIVEN)) {
96                 typeComboBox.setSelectedIndex(2);
97             } else {
98                 typeComboBox.setSelectedIndex(-1);
99             }
100         } else {
101             typeComboBox.setSelectedIndex(-1);
102         }
103         typeComboBox.addItemListener(this);
104     }
105     
106     private void bindLocalTransactionComponents(){
107         LocalTransactionPanel localTransactionPanel=(LocalTransactionPanel)jPanel1;
108         
109         localTransactionCheckBox=localTransactionPanel.getLocalTransactionCheckBox();
110         transactionNameField=localTransactionPanel.getTransactionNameField();
111         unresolvedActionComboBox=localTransactionPanel.getUnresolvedActionComboBox();
112         resolverCheckBox=localTransactionPanel.getResolverCheckBox();
113         resolverComboBox=localTransactionPanel.getResolverComboBox();
114         boundaryCheckBox=localTransactionPanel.getBoundaryCheckBox();
115         boundaryComboBox=localTransactionPanel.getBoundaryComboBox();
116         localTransactionPanel.setComponentsBackground(SectionVisualTheme.getSectionActiveBackgroundColor());
117         
118     }
119     
120     public void initLocalTransactionComponents() {
121         addModifier(nameField);
122         addModifier(transactionNameField);
123         addValidatee(transactionNameField);
124         boolean localTransactionEnabled=(ejbExtension.getLocalTransaction()==null)?false:true;
125         localTransactionCheckBox.setSelected(localTransactionEnabled);
126         
127         if(localTransactionEnabled) {
128             transactionNameField.setText(ejbExtension.getLocalTransactionXmiId());
129             
130             unresolvedActionComboBox.setSelectedItem(ejbExtension.getLocalTransactionUnresolvedAction());
131             String JavaDoc str=ejbExtension.getLocalTransactionResolver();
132             if(str==null) {
133                 resolverCheckBox.setSelected(false);
134             } else {
135                 resolverCheckBox.setSelected(true);
136                 resolverComboBox.setSelectedItem(str);
137             }
138             
139             str=ejbExtension.getLocalTransactionBoundary();
140             if(str==null) {
141                 boundaryCheckBox.setSelected(false);
142             } else {
143                 boundaryCheckBox.setSelected(true);
144                 boundaryComboBox.setSelectedItem(str);
145             }
146         }
147         
148         
149         localTransactionCheckBox.addItemListener(this);
150         unresolvedActionComboBox.addItemListener(this);
151         
152         resolverCheckBox.addItemListener(this);
153         resolverComboBox.addItemListener(this);
154         
155         boundaryCheckBox.addItemListener(this);
156         boundaryComboBox.addItemListener(this);
157     }
158     
159     
160     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
161         if (source==nameField) {
162             ejbExtension.setXmiName((String JavaDoc)value);
163         }
164         if (source==idField) {
165             ejbExtension.setXmiId((String JavaDoc)value);
166             
167         }
168         if (source==beanIdField) {
169             ejbExtension.setHref((String JavaDoc)value);
170         }
171         
172     }
173     public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
174     dObj.setChangedFromUI(true);
175         String JavaDoc selectedString=(String JavaDoc)typeComboBox.getSelectedItem();
176         if(selectedString!=null) {
177             if(selectedString.equals(Types[0])) { //session
178
ejbExtension.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_SESSION);
179                 ejbExtension.setEjbExtensionsType(DDXmiConstants.EJB_EXTENSIONS_TYPE_SESSION);
180             } else if(selectedString.equals(Types[1])) { //entity
181
ejbExtension.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_ENTITY);
182                 ejbExtension.setEjbExtensionsType(DDXmiConstants.EJB_EXTENSIONS_TYPE_ENTITY);
183             } else if(selectedString.equals(Types[2])) { //message driven
184
ejbExtension.setXmiType(DDXmiConstants.EJB_ENTERPRISE_BEAN_TYPE_MESSAGEDRIVEN);
185                 ejbExtension.setEjbExtensionsType(DDXmiConstants.EJB_EXTENSIONS_TYPE_MESSAGEDRIVEN);
186             } else {
187                 ejbExtension.setXmiType(null);
188                 ejbExtension.setEjbExtensionsType(null);
189             }
190         }
191         changeLocalTransactionState();
192         dObj.modelUpdatedFromUI();
193         //dObj.setChangedFromUI(true);
194
dObj.setChangedFromUI(false);
195     }
196     
197     public void changeLocalTransactionState() {
198         if(localTransactionCheckBox.isSelected()) {
199             ejbExtension.setLocalTransaction("");
200             ejbExtension.setLocalTransactionXmiId(transactionNameField.getText());
201             
202             ejbExtension.setLocalTransactionUnresolvedAction(
203                     unresolvedActionComboBox.getSelectedItem().toString());
204             
205             ejbExtension.setLocalTransactionResolver(
206                     resolverCheckBox.isSelected()?
207                         resolverComboBox.getSelectedItem().toString():
208                         null);
209             ejbExtension.setLocalTransactionBoundary(
210                     boundaryCheckBox.isSelected()?
211                         boundaryComboBox.getSelectedItem().toString():
212                         null);
213         } else {
214             ejbExtension.setLocalTransaction(null);
215             //ejbExtension.setLocalTransactionXmiId(null);
216
}
217         ((LocalTransactionPanel)jPanel1).setEnabledComponents();
218     }
219     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
220         if (comp==nameField) {
221             String JavaDoc val = (String JavaDoc)value;
222             if (val.length()==0) {
223                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Name", comp));
224                 return;
225             }
226             getSectionView().getErrorPanel().clearError();
227         }
228         if(comp==idField) {
229             String JavaDoc val = (String JavaDoc)value;
230             if (val.length()==0) {
231                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "ID", comp));
232                 return;
233             }
234             getSectionView().getErrorPanel().clearError();
235         }
236         if(comp==beanIdField) {
237             String JavaDoc val = (String JavaDoc)value;
238             if (val.length()==0) {
239                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Bean Name", comp));
240                 return;
241             }
242             getSectionView().getErrorPanel().clearError();
243         }
244         if (comp==transactionNameField) {
245             String JavaDoc val = (String JavaDoc)value;
246             if (val.length()==0) {
247                 getSectionView()
248                 .getErrorPanel()
249                 .setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Local transaction name", comp));
250                 return;
251             }
252             getSectionView().getErrorPanel().clearError();
253         }
254     }
255     
256     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
257         if (nameField==source) {
258             nameField.setText(ejbExtension.getXmiName());
259         }
260         if (idField==source) {
261             idField.setText(ejbExtension.getXmiId());
262         }
263         if (beanIdField==source) {
264             beanIdField.setText(ejbExtension.getHref());
265         }
266         if (transactionNameField==source) {
267             transactionNameField.setText(ejbExtension.getLocalTransactionXmiId());
268         }
269         
270     }
271     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
272     }
273     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
274         if ("Name".equals(errorId)) return nameField;
275         if ("ID".equals(errorId)) return idField;
276         if ("Bean Name".equals(errorId)) return beanIdField;
277         if("Local transaction name".equals(errorId)) return transactionNameField;
278         return null;
279     }
280     
281     /** This will be called before model is changed from this panel
282      */

283     protected void startUIChange() {
284         dObj.setChangedFromUI(true);
285     }
286     
287     /** This will be called after model is changed from this panel
288      */

289     protected void endUIChange() {
290         dObj.modelUpdatedFromUI();
291         dObj.setChangedFromUI(false);
292     }
293     /** This method is called from within the constructor to
294      * initialize the form.
295      * WARNING: Do NOT modify this code. The content of this method is
296      * always regenerated by the Form Editor.
297      */

298     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
299
private void initComponents() {
300         nameLabel = new javax.swing.JLabel JavaDoc();
301         jLabel2 = new javax.swing.JLabel JavaDoc();
302         jLabel3 = new javax.swing.JLabel JavaDoc();
303         nameField = new javax.swing.JTextField JavaDoc();
304         idField = new javax.swing.JTextField JavaDoc();
305         beanIdField = new javax.swing.JTextField JavaDoc();
306         jLabel4 = new javax.swing.JLabel JavaDoc();
307         typeComboBox = new javax.swing.JComboBox JavaDoc();
308         jPanel1 = new LocalTransactionPanel();
309         jSeparator1 = new javax.swing.JSeparator JavaDoc();
310
311         nameLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_Name"));
312
313         jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_Id"));
314
315         jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_BeanName"));
316
317         jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_BeanType"));
318
319         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
320         this.setLayout(layout);
321         layout.setHorizontalGroup(
322             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
323             .add(layout.createSequentialGroup()
324                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
325                     .add(layout.createSequentialGroup()
326                         .add(10, 10, 10)
327                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
328                             .add(layout.createSequentialGroup()
329                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
330                                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
331                                     .add(nameLabel)
332                                     .add(jLabel2)
333                                     .add(jLabel3))
334                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
335                             .add(jLabel4))
336                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
337                             .add(idField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
338                             .add(nameField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
339                             .add(beanIdField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
340                             .add(typeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 164, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
341                     .add(layout.createSequentialGroup()
342                         .add(10, 10, 10)
343                         .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)))
344                 .addContainerGap())
345             .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE)
346         );
347         layout.setVerticalGroup(
348             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
349             .add(layout.createSequentialGroup()
350                 .addContainerGap()
351                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
352                     .add(nameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
353                     .add(nameLabel))
354                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
355                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
356                     .add(idField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
357                     .add(jLabel2))
358                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
359                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
360                     .add(beanIdField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
361                     .add(jLabel3))
362                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
363                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
364                     .add(typeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
365                     .add(jLabel4))
366                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
367                 .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
368                 .add(2, 2, 2)
369                 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
370                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
371         );
372     }// </editor-fold>//GEN-END:initComponents
373

374     
375     // Variables declaration - do not modify//GEN-BEGIN:variables
376
private javax.swing.JTextField JavaDoc beanIdField;
377     private javax.swing.JTextField JavaDoc idField;
378     private javax.swing.JLabel JavaDoc jLabel2;
379     private javax.swing.JLabel JavaDoc jLabel3;
380     private javax.swing.JLabel JavaDoc jLabel4;
381     private javax.swing.JPanel JavaDoc jPanel1;
382     private javax.swing.JSeparator JavaDoc jSeparator1;
383     private javax.swing.JTextField JavaDoc nameField;
384     private javax.swing.JLabel JavaDoc nameLabel;
385     private javax.swing.JComboBox JavaDoc typeComboBox;
386     // End of variables declaration//GEN-END:variables
387

388 }
389
Popular Tags