KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > GenericTablePanel


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  * GenericTablePanel.java
21  *
22  * Created on October 7, 2003, 4:09 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
26
27 import java.util.Collection JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33
34 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
35 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
36
37 /**
38  *
39  * @author Peter Williams
40  * @version %I%, %G%
41  */

42
43 public class GenericTablePanel extends BeanTablePanel {
44
45     // Resource bundle to retrieve string from and the base resource name to use.
46
private ResourceBundle JavaDoc resourceBundle;
47     private String JavaDoc resourceBase;
48     
49     // Title of popup dialog used for entering table rows.
50
private String JavaDoc dialogTitle;
51     
52     // Heading that goes above the table.
53
private String JavaDoc panelHeading;
54     
55     // JLabel containing the heading
56
private JLabel JavaDoc jLblTableHeading;
57     
58     // 'entryList' is a hack to get the field list passed to via the GenericTableDialog
59
// to the GenericTableDialogPanel object. getInputDialog(...) is called from
60
// the base class constructor and needs access to the entry list. Correct solution
61
// would involve redesigning the base class but that would have a ripple effect
62
// across all derivations.
63
//
64
private List JavaDoc entryList;
65     
66     // This field holds the class of the object used for the entry panel in the
67
// input dialog to allow for easier customization. (Some tables require
68
// sophisticated layout and/or input controls.)
69
private Class JavaDoc entryPanelClass;
70     
71     // This field holds extra data to be passed to the popup dialog. Currently,
72
// it's main use is for the dynamic property popup and it holds the list of
73
// properties along with their value definitions but it can be used for
74
// anything the entry dialog needs.
75
private Object JavaDoc extraData;
76     
77     // This field holds the help id for the popup entry panel used to enter data
78
// into this table.
79
private String JavaDoc entryPanelHelpId;
80     
81     /** Creates a new instance of GenericTablePanel -- accessibility enabled
82      * Resources required to match the base resource tag:
83      * TITLE_##
84      * HEADING_##
85      * ACSN_TABLE_##
86      * ACSD_TABLE_##
87      * ACSN_POPUP_##
88      * ACSD_POPUP_##
89      *
90      * @param model the table model for this table.
91      * @param bundle the resource bundle to retrieve the resources from.
92      * @param resourceBase the base resource tag (combined via described rules).
93      * @param helpId the helpId for the popup dialog
94      */

95     public GenericTablePanel(GenericTableModel model, ResourceBundle JavaDoc bundle, String JavaDoc resourceBase, String JavaDoc helpId) {
96         this(model, bundle, resourceBase, GenericTableDialogPanel.class, helpId);
97     }
98     
99     /** Creates a new instance of GenericTablePanel */
100     public GenericTablePanel(GenericTableModel model, ResourceBundle JavaDoc bundle, String JavaDoc resourceBase,
101         Class JavaDoc entryPanelClass, String JavaDoc helpId) {
102         this(model, bundle, resourceBase, entryPanelClass, helpId, null);
103     }
104     
105     /** Creates a new instance of GenericTablePanel */
106     public GenericTablePanel(GenericTableModel model, ResourceBundle JavaDoc bundle, String JavaDoc resourceBase,
107         Class JavaDoc entryPanelClass, String JavaDoc helpId, Object JavaDoc extraData) {
108         super(model);
109         
110         this.resourceBundle = bundle;
111         this.resourceBase = resourceBase;
112         this.dialogTitle = bundle.getString("TITLE_" + resourceBase); // NOI18N
113
this.panelHeading = bundle.getString("HEADING_" + resourceBase); // NOI18N
114
this.entryPanelClass = entryPanelClass;
115         this.extraData = extraData;
116         this.entryPanelHelpId = helpId;
117          
118         table.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_TABLE_" + resourceBase)); // NOI18N
119
table.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TABLE_" + resourceBase)); // NOI18N
120
getAccessibleContext().setAccessibleName(bundle.getString("ACSN_TABLE_" + resourceBase)); // NOI18N
121
getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TABLE_" + resourceBase)); // NOI18N
122

123         initUserComponents();
124     }
125     
126     protected void initUserComponents() {
127         jLblTableHeading = new JLabel JavaDoc(panelHeading);
128         jLblTableHeading.setLabelFor(table);
129         add(jLblTableHeading, java.awt.BorderLayout.NORTH);
130     }
131     
132     public void setHeadingMnemonic(char mnemonic) {
133         jLblTableHeading.setDisplayedMnemonic(mnemonic);
134     }
135     
136     public void setModel(CommonDDBean parent, ASDDVersion asVersion) {
137         getTableModel().setData(parent, asVersion);
138         
139 /* !PW tinkering with table colunn widths... hasn't really worked well though.
140         JTableHeader header = table.getTableHeader();
141         TableColumnModel columnModel = header.getColumnModel();
142         
143         int width = columnModel.getTotalColumnWidth();
144         int [] columnWidths = new int [entryList.size()];
145         columnWidths[0] = columnWidths[1] = width/5;
146         columnWidths[2] = width - (columnWidths[0] + columnWidths[1]);
147         
148         for(int i = 0; i < entryList.size() && i < columnModel.getColumnCount(); i++) {
149             TableColumn column = columnModel.getColumn(i);
150             column.setPreferredWidth(columnWidths[i]);
151         }
152  */

153     }
154     
155     public void setModel(List JavaDoc rows, ASDDVersion asVersion) {
156         getTableModel().setData(rows, asVersion);
157     }
158     
159     public void setModel(CommonDDBean [] rows, ASDDVersion asVersion) {
160         getTableModel().setData(rows, asVersion);
161     }
162     
163     
164     public void setModelBaseBean(CommonDDBean parent, ASDDVersion asVersion) {
165         getTableModel().setDataBaseBean(parent, asVersion);
166     }
167     
168     public BeanInputDialog getInputDialog(Object JavaDoc[] values) {
169         // Called during EDIT operation
170
entryList = getTableModel().getPropertyDefinitions();
171         return new GenericTableDialog(this, dialogTitle, values);
172     }
173
174     public BeanInputDialog getInputDialog() {
175         // Called during ADD operation
176
entryList = getTableModel().getPropertyDefinitions();
177         return new GenericTableDialog(this, dialogTitle);
178     }
179
180     private GenericTableModel getTableModel() {
181         return (GenericTableModel) model;
182     }
183     
184     private String JavaDoc getHelpId() {
185         return entryPanelHelpId;
186     }
187     
188     /** GenericTableDialog nested class. This class definition cannot be static
189      * or an outer classes, as it relies on a bound inner->outer class reference
190      * to access the entryList and entryPanelClass objects in the outer class.
191      * In particular, it accesses these fields during execution of the base
192      * class constructor, so they are not even viable constructor parameters.
193      */

194     public class GenericTableDialog extends BeanInputDialog {
195         private GenericTablePanel parentPanel;
196         private GenericTableDialogPanelAccessor entryPanel;
197
198         public GenericTableDialog(GenericTablePanel parent, String JavaDoc title){
199             super(parent, title, true);
200             parentPanel = parent;
201             initAccessibility();
202         }
203
204         public GenericTableDialog(GenericTablePanel parent, String JavaDoc title, Object JavaDoc[] values) {
205             super(parent, title, true, values);
206             parentPanel = parent;
207             initAccessibility();
208         }
209         
210         protected void initAccessibility() {
211             getAccessibleContext().setAccessibleName(
212                 resourceBundle.getString("ACSN_POPUP_" + resourceBase)); // NOI18N
213
getAccessibleContext().setAccessibleDescription(
214                 resourceBundle.getString("ACSD_POPUP_" + resourceBase)); // NOI18N
215
}
216
217         protected JPanel JavaDoc getDialogPanel(Object JavaDoc[] values) {
218             // Called during EDIT operation
219
// Create panel
220
// Initialize all the components in the panel
221
// Provide handlers for all the components
222
entryPanel = internalGetDialogPanel();
223             entryPanel.setValues(values);
224             return (JPanel JavaDoc) entryPanel;
225         }
226
227         protected JPanel JavaDoc getDialogPanel() {
228             // Called during ADD operation
229
// Create panel
230
// Initialize all the components in the panel
231
// Provide handlers for all the components
232
entryPanel = internalGetDialogPanel();
233             entryPanel.setValues(null);
234             return (JPanel JavaDoc) entryPanel;
235         }
236         
237         private GenericTableDialogPanelAccessor internalGetDialogPanel() {
238             GenericTableDialogPanelAccessor subPanel = null;
239             
240             try {
241                 subPanel = (GenericTableDialogPanelAccessor) entryPanelClass.newInstance();
242                 subPanel.init(getTableModel().getAppServerVersion(),
243                         GenericTablePanel.this.getWidth()*3/4, entryList, extraData);
244                 
245                 ((JPanel JavaDoc) subPanel).getAccessibleContext().setAccessibleName(
246                     resourceBundle.getString("ACSN_POPUP_" + resourceBase)); // NOI18N
247
((JPanel JavaDoc) subPanel).getAccessibleContext().setAccessibleDescription(
248                     resourceBundle.getString("ACSD_POPUP_" + resourceBase)); // NOI18N
249
} catch(InstantiationException JavaDoc ex) {
250                 // !PW Should never happen, but it's fatal for field editing if
251
// it does so what should exception should we throw?
252
} catch(IllegalAccessException JavaDoc ex) {
253                 // !PW Should never happen, but it's fatal for field editing if
254
// it does so what should exception should we throw?
255
}
256             
257             return subPanel;
258         }
259
260         protected Object JavaDoc[] getValues() {
261             return entryPanel.getValues();
262         }
263
264         protected Collection JavaDoc getErrors() {
265             return entryPanel.getErrors(validationSupport);
266         }
267         
268         protected String JavaDoc getHelpId() {
269             return GenericTablePanel.this.getHelpId();
270         }
271     }
272 }
273
Popular Tags