KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > struts > wizards > FormBeanPropertiesPanelVisual


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 package org.netbeans.modules.web.struts.wizards;
21
22 import javax.swing.DefaultListModel JavaDoc;
23 import javax.swing.ListSelectionModel JavaDoc;
24 import javax.swing.event.ListDataEvent JavaDoc;
25 import javax.swing.event.ListDataListener JavaDoc;
26 import javax.swing.table.AbstractTableModel JavaDoc;
27 import org.openide.WizardDescriptor;
28
29 import org.openide.util.NbBundle;
30
31 public class FormBeanPropertiesPanelVisual extends javax.swing.JPanel JavaDoc implements WizardDescriptor.Panel {
32
33     private PropertiesTableModel model;
34
35     /**
36      * Creates new form PropertiesPanelVisual
37      */

38     public FormBeanPropertiesPanelVisual() {
39         initComponents();
40         initTable();
41         
42 // this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FormBeanNewPanelVisual.class, "ACS_BeanFormProperties")); // NOI18N
43
}
44     
45     private void initTable() {
46         model = new PropertiesTableModel();
47         jTableProperties.setModel(model);
48         jTableProperties.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
49 // PropertiesTableCellRenderer renderer = new PropertiesTableCellRenderer();
50
// jTableProperties.setDefaultRenderer(String.class, renderer);
51

52         jTableProperties.setRowHeight(jTableProperties.getFontMetrics(jTableProperties.getFont()).getHeight() + 4);
53         jTableProperties.getParent().setBackground(jTableProperties.getBackground());
54     }
55     
56     public DefaultListModel JavaDoc getTableModel() {
57         return model.getDefaultListModel();
58     }
59
60     public void removeChangeListener(javax.swing.event.ChangeListener JavaDoc l) {
61     }
62
63     public void addChangeListener(javax.swing.event.ChangeListener JavaDoc l) {
64     }
65
66     public void storeSettings(Object JavaDoc settings) {
67     }
68
69     public void readSettings(Object JavaDoc settings) {
70     }
71
72     public org.openide.util.HelpCtx getHelp() {
73         return null;
74     }
75
76     public java.awt.Component JavaDoc getComponent() {
77         return this;
78     }
79     
80 // public java.awt.Dimension getPreferredSize() {
81
// return new java.awt.Dimension(560,350);
82
// }
83

84     /** This method is called from within the constructor to
85      * initialize the form.
86      * WARNING: Do NOT modify this code. The content of this method is
87      * always regenerated by the Form Editor.
88      */

89     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
90
private void initComponents() {
91         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
92
93         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
94         jTableProperties = new javax.swing.JTable JavaDoc();
95         jButtonAdd = new javax.swing.JButton JavaDoc();
96         jButtonRemove = new javax.swing.JButton JavaDoc();
97         jLabel1 = new javax.swing.JLabel JavaDoc();
98
99         setLayout(new java.awt.GridBagLayout JavaDoc());
100
101         jTableProperties.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
102             new Object JavaDoc [][] {
103                 {null, null, null, null},
104                 {null, null, null, null},
105                 {null, null, null, null},
106                 {null, null, null, null}
107             },
108             new String JavaDoc [] {
109                 "Title 1", "Title 2", "Title 3", "Title 4"
110             }
111         ));
112         jScrollPane1.setViewportView(jTableProperties);
113
114         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
115         gridBagConstraints.gridx = 0;
116         gridBagConstraints.gridy = 1;
117         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
118         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
119         gridBagConstraints.weightx = 1.0;
120         gridBagConstraints.weighty = 1.0;
121         add(jScrollPane1, gridBagConstraints);
122
123         jButtonAdd.setMnemonic(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_AddButton_LabelMnemonic").charAt(0));
124         jButtonAdd.setText(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_AddButton"));
125         jButtonAdd.addActionListener(new java.awt.event.ActionListener JavaDoc() {
126             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
127                 jButtonAddActionPerformed(evt);
128             }
129         });
130
131         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
132         gridBagConstraints.gridx = 1;
133         gridBagConstraints.gridy = 1;
134         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
138         add(jButtonAdd, gridBagConstraints);
139
140         jButtonRemove.setMnemonic(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_RemoveButton_LabelMnemonic").charAt(0));
141         jButtonRemove.setText(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_RemoveButton"));
142         jButtonRemove.addActionListener(new java.awt.event.ActionListener JavaDoc() {
143             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
144                 jButtonRemoveActionPerformed(evt);
145             }
146         });
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridx = 1;
150         gridBagConstraints.gridy = 2;
151         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
152         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
153         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
154         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
155         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
156         add(jButtonRemove, gridBagConstraints);
157
158         jLabel1.setLabelFor(jTableProperties);
159         jLabel1.setText(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_Properties"));
160         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
161         gridBagConstraints.gridx = 0;
162         gridBagConstraints.gridy = 0;
163         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
164         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
166         add(jLabel1, gridBagConstraints);
167
168     }
169     // </editor-fold>//GEN-END:initComponents
170

171     private void jButtonRemoveActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonRemoveActionPerformed
172
int index = jTableProperties.getSelectedRow();
173         if (index != -1)
174             model.getDefaultListModel().remove(index);
175     }//GEN-LAST:event_jButtonRemoveActionPerformed
176

177     private void jButtonAddActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonAddActionPerformed
178
model.addItem(new FormBeanProperty());
179     }//GEN-LAST:event_jButtonAddActionPerformed
180

181     
182     // Variables declaration - do not modify//GEN-BEGIN:variables
183
private javax.swing.JButton JavaDoc jButtonAdd;
184     private javax.swing.JButton JavaDoc jButtonRemove;
185     private javax.swing.JLabel JavaDoc jLabel1;
186     private javax.swing.JScrollPane JavaDoc jScrollPane1;
187     private javax.swing.JTable JavaDoc jTableProperties;
188     // End of variables declaration//GEN-END:variables
189

190 // boolean valid(WizardDescriptor wizardDescriptor) {
191
// wizardDescriptor.putProperty( "WizardPanel_errorMessage", null); //NOI18N
192
//
193
// for (int i = 0; i < model.getRowCount(); i++)
194
// if (model.getItem(i) == null || (model.getItem(i).getProperty()).trim().equals("")) //NOI18N
195
// return false;
196
//
197
// return true;
198
// }
199
//
200
// void read (WizardDescriptor settings) {
201
// }
202
//
203
// void store(WizardDescriptor settings) {
204
// settings.putProperty(WizardProperties.FORMBEAN_NEPROPERTIES, model.getDefaultListModel().elements());
205
// }
206

207 // public static class PropertiesTableCellRenderer extends DefaultTableCellRenderer {
208
// private TableCellRenderer booleanRenderer;
209
//
210
// public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
211
// if (value instanceof Boolean && booleanRenderer != null)
212
// return booleanRenderer.getTableCellRendererComponent(table, value, isSelected, false, row, column);
213
// else
214
// return super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
215
// }
216
//
217
// public void setBooleanRenderer(TableCellRenderer booleanRenderer) {
218
// this.booleanRenderer = booleanRenderer;
219
// }
220
// }
221

222     /**
223      * Implements a TableModel.
224      */

225     public static final class PropertiesTableModel extends AbstractTableModel JavaDoc implements ListDataListener JavaDoc {
226         
227         private DefaultListModel JavaDoc model;
228         
229         public PropertiesTableModel() {
230             model = new DefaultListModel JavaDoc();
231             model.addListDataListener(this);
232         }
233         
234         public DefaultListModel JavaDoc getDefaultListModel() {
235             return model;
236         }
237
238         public int getColumnCount() {
239             return 2;
240         }
241         
242         public int getRowCount() {
243             return model.size();
244         }
245         
246         public String JavaDoc getColumnName(int column) {
247             switch (column) {
248                 case 0:
249                     return NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_PropertiesTableHeader_Property");//NOI18N
250
case 1:
251                     return NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_PropertiesTableHeader_Value");//NOI18N
252
}
253             return ""; //NOI18N
254
}
255
256         public Class JavaDoc getColumnClass(int columnIndex) {
257             if (columnIndex == 2)
258                 return Boolean JavaDoc.class;
259             else
260                 return String JavaDoc.class;
261         }
262         
263         public boolean isCellEditable(int rowIndex, int columnIndex) {
264             return true;
265         }
266         
267         public Object JavaDoc getValueAt(int row, int column) {
268             FormBeanProperty item = getItem(row);
269             switch (column) {
270                 case 0: return item.getProperty();
271                 case 1: return item.getType();
272             }
273             return "";
274         }
275         
276         public void setValueAt(Object JavaDoc value, int row, int column) {
277             FormBeanProperty item = getItem(row);
278             switch (column) {
279                 case 0: item.setProperty((String JavaDoc) value);break;
280                 case 1: item.setType((String JavaDoc) value);
281             }
282         }
283
284         public void clear(){
285             model.clear();
286         }
287         
288         public void contentsChanged(ListDataEvent JavaDoc e) {
289             fireTableRowsUpdated(e.getIndex0(), e.getIndex1());
290         }
291         
292         public void intervalAdded(ListDataEvent JavaDoc e) {
293             fireTableRowsInserted(e.getIndex0(), e.getIndex1());
294         }
295         
296         public void intervalRemoved(ListDataEvent JavaDoc e) {
297             fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
298         }
299
300         private FormBeanProperty getItem(int index) {
301             return (FormBeanProperty) model.get(index);
302         }
303         
304         public void addItem(FormBeanProperty item){
305             model.addElement(item);
306         }
307     }
308 }
309
Popular Tags