KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > other > AppClientRootCustomizer


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  * AppClientRootCustomizer.java
21  *
22  * Created on September 4, 2003, 5:28 PM
23  */

24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.other;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.ResourceBundle JavaDoc;
28
29 import java.awt.GridBagConstraints JavaDoc;
30 import java.awt.Insets JavaDoc;
31 import java.beans.PropertyVetoException JavaDoc;
32 import javax.swing.event.TableModelEvent JavaDoc;
33 import javax.swing.event.TableModelListener JavaDoc;
34
35 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
36 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination;
37
38 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
39 import org.netbeans.modules.j2ee.sun.share.configbean.AppClientRoot;
40 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
41 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
42 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
43 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel;
44 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer;
45 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext;
46
47
48 /**
49  *
50  * @author Peter Williams
51  */

52 public class AppClientRootCustomizer extends BaseCustomizer implements TableModelListener JavaDoc {
53     
54     private static final ResourceBundle JavaDoc otherBundle = ResourceBundle.getBundle(
55         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.other.Bundle"); // NOI18N
56

57     private AppClientRoot theBean;
58
59     // Table for editing MessageDestination entries
60
private GenericTableModel messageDestinationModel;
61     private GenericTablePanel messageDestinationPanel;
62
63 // // Table for editing MessageDestinationRef entries
64
// private GenericTableModel messageDestinationRefModel;
65
// private GenericTablePanel messageDestinationRefPanel;
66

67     // true if AS 9.0+ fields are visible.
68
private boolean as90FeaturesVisible;
69     
70     // if in setup
71
private boolean setup;
72     
73     /** Creates new form AppClientRootCustomizer */
74     public AppClientRootCustomizer() {
75         initComponents();
76         initUserComponents();
77     }
78
79     public AppClientRoot getBean() {
80         return theBean;
81     }
82
83     /** This method is called from within the constructor to
84      * initialize the form.
85      * WARNING: Do NOT modify this code. The content of this method is
86      * always regenerated by the Form Editor.
87      */

88     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
89
private void initComponents() {
90         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
91
92         jPnlJws = new javax.swing.JPanel JavaDoc();
93         jLblJavaWebStartAccess = new javax.swing.JLabel JavaDoc();
94         jLblContextRoot = new javax.swing.JLabel JavaDoc();
95         jTxtContextRoot = new javax.swing.JTextField JavaDoc();
96         jLblVendor = new javax.swing.JLabel JavaDoc();
97         jTxtVendor = new javax.swing.JTextField JavaDoc();
98         jLblEligible = new javax.swing.JLabel JavaDoc();
99         jChkEligible = new javax.swing.JCheckBox JavaDoc();
100
101         setLayout(new java.awt.GridBagLayout JavaDoc());
102
103         jPnlJws.setLayout(new java.awt.GridBagLayout JavaDoc());
104
105         jLblJavaWebStartAccess.setText(otherBundle.getString("LBL_JavaWebStartAccess"));
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
108         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
109         jPnlJws.add(jLblJavaWebStartAccess, gridBagConstraints);
110
111         jLblContextRoot.setLabelFor(jTxtContextRoot);
112         jLblContextRoot.setText(otherBundle.getString("LBL_ContextRoot_1"));
113         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
114         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
115         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
116         jPnlJws.add(jLblContextRoot, gridBagConstraints);
117
118         jTxtContextRoot.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
119             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
120                 jTxtContextRootKeyReleased(evt);
121             }
122         });
123
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
126         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
127         gridBagConstraints.weightx = 1.0;
128         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
129         jPnlJws.add(jTxtContextRoot, gridBagConstraints);
130         jTxtContextRoot.getAccessibleContext().setAccessibleName(otherBundle.getString("ContextRoot_Acsbl_Name"));
131         jTxtContextRoot.getAccessibleContext().setAccessibleDescription(otherBundle.getString("ContextRoot_Acsbl_Desc"));
132
133         jLblVendor.setLabelFor(jTxtVendor);
134         jLblVendor.setText(otherBundle.getString("LBL_Vendor_1"));
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
138         jPnlJws.add(jLblVendor, gridBagConstraints);
139
140         jTxtVendor.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
141             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
142                 jTxtVendorKeyReleased(evt);
143             }
144         });
145
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
148         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149         gridBagConstraints.weightx = 1.0;
150         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
151         jPnlJws.add(jTxtVendor, gridBagConstraints);
152         jTxtVendor.getAccessibleContext().setAccessibleName(otherBundle.getString("ASCN_Vendor"));
153         jTxtVendor.getAccessibleContext().setAccessibleDescription(otherBundle.getString("ASCD_Vendor"));
154
155         jLblEligible.setLabelFor(jChkEligible);
156         jLblEligible.setText(otherBundle.getString("LBL_Eligible_1"));
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
160         jPnlJws.add(jLblEligible, gridBagConstraints);
161
162         jChkEligible.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
163         jChkEligible.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
164         jChkEligible.addItemListener(new java.awt.event.ItemListener JavaDoc() {
165             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
166                 jChkEligibleItemStateChanged(evt);
167             }
168         });
169
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
172         gridBagConstraints.ipady = 8;
173         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
174         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
175         jPnlJws.add(jChkEligible, gridBagConstraints);
176         jChkEligible.getAccessibleContext().setAccessibleName(otherBundle.getString("ASCN_Eligible"));
177         jChkEligible.getAccessibleContext().setAccessibleDescription(otherBundle.getString("ASCD_Eligible"));
178
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
180         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
181         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182         gridBagConstraints.weightx = 1.0;
183         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 5);
184         add(jPnlJws, gridBagConstraints);
185
186     }// </editor-fold>//GEN-END:initComponents
187

188     private void jChkEligibleItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jChkEligibleItemStateChanged
189
if(!setup && jChkEligible.isVisible() && theBean != null) {
190             boolean newState = Utils.interpretCheckboxState(evt);
191             if(newState != theBean.isEligible()) {
192                 try {
193                     theBean.setEligible(newState);
194                 } catch(java.beans.PropertyVetoException JavaDoc exception) {
195                     jChkEligible.setSelected(theBean.isEligible());
196                 }
197             }
198         }
199     }//GEN-LAST:event_jChkEligibleItemStateChanged
200

201     private void jTxtVendorKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtVendorKeyReleased
202
if(!setup && jTxtVendor.isVisible() && theBean != null) {
203             String JavaDoc newVendor = jTxtVendor.getText();
204             if(newVendor != null) {
205                 newVendor = newVendor.trim();
206             }
207             String JavaDoc oldVendor = theBean.getVendor();
208             if(!Utils.strEquivalent(newVendor, oldVendor)) {
209                 try {
210                     theBean.setVendor(newVendor);
211                 } catch(java.beans.PropertyVetoException JavaDoc exception) {
212                     jTxtVendor.setText(oldVendor);
213                 }
214             }
215         }
216     }//GEN-LAST:event_jTxtVendorKeyReleased
217

218     private void jTxtContextRootKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtContextRootKeyReleased
219
if(!setup && jTxtContextRoot.isVisible() && theBean != null) {
220             String JavaDoc newContextRoot = jTxtContextRoot.getText();
221             if(newContextRoot != null) {
222                 newContextRoot = newContextRoot.trim();
223             }
224             String JavaDoc oldContextRoot = theBean.getContextRoot();
225             if(!Utils.strEquivalent(newContextRoot, oldContextRoot)) {
226                 try {
227                     theBean.setContextRoot(newContextRoot);
228 // theBean.validateField(AppClientRoot.FIELD_JWSA_CONTEXT_ROOT);
229
} catch(java.beans.PropertyVetoException JavaDoc exception) {
230                     jTxtContextRoot.setText(oldContextRoot);
231                 }
232             }
233         }
234     }//GEN-LAST:event_jTxtContextRootKeyReleased
235

236     // Variables declaration - do not modify//GEN-BEGIN:variables
237
private javax.swing.JCheckBox JavaDoc jChkEligible;
238     private javax.swing.JLabel JavaDoc jLblContextRoot;
239     private javax.swing.JLabel JavaDoc jLblEligible;
240     private javax.swing.JLabel JavaDoc jLblJavaWebStartAccess;
241     private javax.swing.JLabel JavaDoc jLblVendor;
242     private javax.swing.JPanel JavaDoc jPnlJws;
243     private javax.swing.JTextField JavaDoc jTxtContextRoot;
244     private javax.swing.JTextField JavaDoc jTxtVendor;
245     // End of variables declaration//GEN-END:variables
246

247     private void initUserComponents() {
248         as90FeaturesVisible = true;
249         
250         // Add title panel
251
addTitlePanel(otherBundle.getString("TITLE_SunApplicationClient")); // NOI18N
252
getAccessibleContext().setAccessibleName(otherBundle.getString("ACSN_SunApplicationClient")); // NOI18N
253
getAccessibleContext().setAccessibleDescription(otherBundle.getString("ACSD_SunApplicationClient")); // NOI18N
254

255         /* Add message destination table panel :
256          * TableEntry list has two properties: destination name, jndi name
257          */

258         ArrayList JavaDoc tableColumns = new ArrayList JavaDoc(2);
259         tableColumns.add(new GenericTableModel.ValueEntry(null, MessageDestination.MESSAGE_DESTINATION_NAME,
260             otherBundle, "MessageDestinationName", true, true)); // NOI18N - property name
261
tableColumns.add(new GenericTableModel.ValueEntry(null, MessageDestination.JNDI_NAME,
262             otherBundle, "JNDIName", true, false)); // NOI18N - property name
263

264         messageDestinationModel = new GenericTableModel(messageDestinationFactory, tableColumns);
265         messageDestinationPanel = new GenericTablePanel(messageDestinationModel,
266             otherBundle, "MessageDestination", // NOI18N - property name
267
HelpContext.HELP_APPCLIENT_MESSAGE_DESTINATION_POPUP);
268         
269         GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
270         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
271         gridBagConstraints.fill = GridBagConstraints.BOTH;
272         gridBagConstraints.weightx = 1.0;
273         gridBagConstraints.weighty = 1.0;
274         gridBagConstraints.insets = new Insets JavaDoc(0, 6, 5, 5);
275         add(messageDestinationPanel, gridBagConstraints);
276
277         /* Add message destination ref table panel :
278          * TableEntry list has two properties: destination ref name, jndi name
279          */

280 // tableColumns = new ArrayList(2);
281
// tableColumns.add(new GenericTableModel.ValueEntry(null, MessageDestinationRef.MESSAGE_DESTINATION_REF_NAME,
282
// otherBundle, "MessageDestinationRefName", true, true)); // NOI18N - property name
283
// tableColumns.add(new GenericTableModel.ValueEntry(null, MessageDestinationRef.JNDI_NAME,
284
// otherBundle, "JNDIName", true, false)); // NOI18N - property name
285

286 // messageDestinationRefModel = new GenericTableModel(messageDestinationRefFactory, tableColumns);
287
// messageDestinationRefPanel = new GenericTablePanel(messageDestinationRefModel,
288
// otherBundle, "MessageDestinationRef", // NOI18N - property name
289
// HelpContext.HELP_WEBAPP_MESSAGE_DESTINATION_REF_POPUP);
290
//
291
// gridBagConstraints = new GridBagConstraints();
292
// gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
293
// gridBagConstraints.fill = GridBagConstraints.BOTH;
294
// gridBagConstraints.weightx = 1.0;
295
// gridBagConstraints.weighty = 1.0;
296
// gridBagConstraints.insets = new Insets(6, 6, 5, 5);
297
// add(messageDestinationRefPanel, gridBagConstraints);
298

299         // Add error panel
300
addErrorPanel();
301     }
302     
303     protected void initFields() {
304         try {
305             setup = true;
306             messageDestinationPanel.setModel(theBean.getMessageDestinations(), theBean.getAppServerVersion());
307             if(ASDDVersion.SUN_APPSERVER_9_0.compareTo(theBean.getAppServerVersion()) <= 0) {
308                 jTxtContextRoot.setText(theBean.getContextRoot());
309                 jTxtVendor.setText(theBean.getVendor());
310                 jChkEligible.setSelected(theBean.isEligible());
311 // messageDestinationRefPanel.setModel(theBean.getMessageDestinationRefs(), theBean.getAppServerVersion());
312
showAS90Fields(true);
313             } else {
314                 jTxtContextRoot.setText("");
315                 jTxtVendor.setText("");
316                 jChkEligible.setSelected(false);
317                 showAS90Fields(false);
318             }
319         } finally {
320             setup = false;
321         }
322     }
323     
324     private void showAS90Fields(boolean show) {
325         if(as90FeaturesVisible != show) {
326             as90FeaturesVisible = show;
327             jPnlJws.setVisible(show);
328 // messageDestinationRefPanel.setVisible(show);
329
}
330     }
331     
332     public void addListeners() {
333     super.addListeners();
334
335         messageDestinationModel.addTableModelListener(this);
336 // messageDestinationRefModel.addTableModelListener(this);
337
}
338     
339     public void removeListeners() {
340     super.removeListeners();
341
342 // messageDestinationRefModel.removeTableModelListener(this);
343
messageDestinationModel.removeTableModelListener(this);
344     }
345
346     protected boolean setBean(Object JavaDoc bean) {
347         boolean result = super.setBean(bean);
348
349         if(bean instanceof AppClientRoot) {
350             theBean = (AppClientRoot) bean;
351             result = true;
352         } else {
353             // if bean is not an AppClientRoot, then it shouldn't have passed Base either.
354
assert (result == false) :
355                 "AppClientRootCustomizer was passed wrong bean type in setBean(Object bean)"; // NOI18N
356

357             theBean = null;
358             result = false;
359         }
360
361         return result;
362     }
363
364     /** -----------------------------------------------------------------------
365      * Implementation of javax.swing.event.TableModelListener
366      */

367     public void tableChanged(TableModelEvent JavaDoc e) {
368         if(theBean != null) {
369             try {
370                 Object JavaDoc eventSource = e.getSource();
371                 if(eventSource == messageDestinationModel) {
372                     theBean.setMessageDestinations(messageDestinationModel.getData());
373                     theBean.firePropertyChange("messageDestination", null, messageDestinationModel.getData());
374 // } else if(eventSource == messageDestinationRefModel) {
375
// theBean.setMessageDestinationRefs(messageDestinationRefModel.getData());
376
// theBean.firePropertyChange("messageDestinationRef", null, messageDestinationRefModel.getData());
377
}
378             } catch(PropertyVetoException JavaDoc ex) {
379                 // FIXME undo whatever changed... how?
380
}
381         }
382     }
383
384     public String JavaDoc getHelpId() {
385         return "AS_CFG_AppClient";
386     }
387
388     // New for migration to sun DD API model. Factory instance to pass to generic table model
389
// to allow it to create messageDestination beans.
390
static GenericTableModel.ParentPropertyFactory messageDestinationFactory =
391         new GenericTableModel.ParentPropertyFactory() {
392             public CommonDDBean newParentProperty(ASDDVersion asVersion) {
393                 return StorageBeanFactory.getStorageBeanFactory(asVersion).createMessageDestination();
394             }
395         };
396         
397 // static GenericTableModel.ParentPropertyFactory messageDestinationRefFactory =
398
// new GenericTableModel.ParentPropertyFactory() {
399
// public CommonDDBean newParentProperty(ASDDVersion asVersion) {
400
// return StorageBeanFactory.getStorageBeanFactory(asVersion).createMessageDestinationRef();
401
// }
402
// };
403
}
404
Popular Tags