KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > CommonPropertyVisualPanel


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  * CommonPropertyVisualPanel.java
21  *
22  * Created on December 17, 2002, 1:19 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.TableModelEvent JavaDoc;
29 import javax.swing.event.TableModelListener JavaDoc;
30 import javax.swing.ListSelectionModel JavaDoc;
31 import org.openide.util.NbBundle;
32 import java.util.ResourceBundle JavaDoc;
33
34 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
35
36 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
37 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
38 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper;
39 /**
40  *
41  * @author Jennifer Chou
42  */

43 public class CommonPropertyVisualPanel extends javax.swing.JPanel JavaDoc implements WizardConstants, TableModelListener JavaDoc {
44     
45     private final CommonPropertyPanel panel;
46     private ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.Bundle");
47     private FieldGroup propertiesGroup;
48     private PropertiesTableModel tableModel;
49     private javax.swing.table.TableColumn JavaDoc propNameColumn;
50     private javax.swing.table.TableColumn JavaDoc propValueColumn;
51     private ResourceConfigHelper helper;
52     
53         
54     /** Creates new form JmsPropertyVisualPanel */
55     public CommonPropertyVisualPanel(CommonPropertyPanel panel) {
56         this.panel = panel;
57         this.helper = panel.getHelper();
58         this.propertiesGroup = panel.getFieldGroup(__Properties);
59         tableModel = new PropertiesTableModel(this.helper.getData());
60         initComponents();
61         propNameColumn = propertyTable.getColumnModel().getColumn(0);
62         setPropTableCellEditor();
63         tableModel.addTableModelListener(this);
64         propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
65         propertyTable.setRowSelectionAllowed(true);
66         
67         // Provide a name in the title bar.
68
setName(NbBundle.getMessage(JmsPropertyVisualPanel.class, "TITLE_CommonPropertyPanel")); //NOI18N
69
}
70     
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the Form Editor.
75      */

76     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
77
private void initComponents() {
78         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
79
80         descriptionTextArea = new javax.swing.JTextArea JavaDoc();
81         propertyInfo = new javax.swing.JLabel JavaDoc();
82         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
83         propertyTable = new javax.swing.JTable JavaDoc();
84         buttonsPane = new javax.swing.JPanel JavaDoc();
85         addButton = new javax.swing.JButton JavaDoc();
86         removeButton = new javax.swing.JButton JavaDoc();
87
88         setLayout(new java.awt.GridBagLayout JavaDoc());
89
90         setMinimumSize(new java.awt.Dimension JavaDoc(627, 305));
91         setPreferredSize(new java.awt.Dimension JavaDoc(627, 305));
92         getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("TITLE_CommonPropertyPanel"));
93         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
94         descriptionTextArea.setEditable(false);
95         descriptionTextArea.setLineWrap(true);
96         descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
97         descriptionTextArea.setWrapStyleWord(true);
98         descriptionTextArea.setFocusable(false);
99         descriptionTextArea.setMinimumSize(new java.awt.Dimension JavaDoc(500, 17));
100         descriptionTextArea.setOpaque(false);
101         descriptionTextArea.setPreferredSize(new java.awt.Dimension JavaDoc(500, 17));
102         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
103         gridBagConstraints.gridx = 0;
104         gridBagConstraints.gridy = 0;
105         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
106         gridBagConstraints.weightx = 1.0;
107         gridBagConstraints.weighty = 1.0;
108         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 11);
109         add(descriptionTextArea, gridBagConstraints);
110         descriptionTextArea.getAccessibleContext().setAccessibleName(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
111         descriptionTextArea.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
112
113         propertyInfo.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties_Mnemonic").charAt(0));
114         propertyInfo.setLabelFor(propertyTable);
115         propertyInfo.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties"));
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.gridx = 0;
118         gridBagConstraints.gridy = 1;
119         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
120         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 11);
121         add(propertyInfo, gridBagConstraints);
122         propertyInfo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
123
124         jScrollPane1.setPreferredSize(new java.awt.Dimension JavaDoc(453, 17));
125         propertyTable.setModel(tableModel);
126         jScrollPane1.setViewportView(propertyTable);
127         propertyTable.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty"));
128         propertyTable.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
129
130         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridx = 0;
132         gridBagConstraints.gridy = 2;
133         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
134         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 12, 10, 11);
135         add(jScrollPane1, gridBagConstraints);
136         jScrollPane1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty"));
137         jScrollPane1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
138
139         buttonsPane.setLayout(new java.awt.GridBagLayout JavaDoc());
140
141         addButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Add_Mnemonic").charAt(0));
142         addButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Add"));
143         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
144             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
145                 addButtonActionPerformed(evt);
146             }
147         });
148
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridx = 0;
151         gridBagConstraints.gridy = 0;
152         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 12);
154         buttonsPane.add(addButton, gridBagConstraints);
155         addButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_AddButtonA11yDesc"));
156
157         removeButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Remove_Mnemonic").charAt(0));
158         removeButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Remove"));
159         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
160             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
161                 removeButtonActionPerformed(evt);
162             }
163         });
164
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 0;
167         gridBagConstraints.gridy = 1;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
170         buttonsPane.add(removeButton, gridBagConstraints);
171         removeButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_RemoveButtonA11yDesc"));
172
173         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
174         gridBagConstraints.gridx = 1;
175         gridBagConstraints.gridy = 2;
176         gridBagConstraints.ipady = 150;
177         add(buttonsPane, gridBagConstraints);
178         buttonsPane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty"));
179         buttonsPane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
180
181     }
182     // </editor-fold>//GEN-END:initComponents
183

184     private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addButtonActionPerformed
185
// Add your handling code here:
186
//Fix for bug#4958730 - value overwrites into next row
187
propertyTable.editingStopped(new ChangeEvent JavaDoc (this));
188         ResourceConfigData data = this.helper.getData();
189         data.addProperty(new NameValuePair());
190         tableModel.fireTableDataChanged();
191     }//GEN-LAST:event_addButtonActionPerformed
192

193     private void removeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeButtonActionPerformed
194
// Add your handling code here:
195
int selectedRow = propertyTable.getSelectedRow();
196         if (selectedRow != -1) {
197             //Fix for bug#4958730 - value overwrites into next row
198
propertyTable.editingStopped(new ChangeEvent JavaDoc (this));
199             this.helper.getData().removeProperty(selectedRow);
200             tableModel.fireTableDataChanged();
201         }
202     }//GEN-LAST:event_removeButtonActionPerformed
203

204     public void tableChanged(TableModelEvent JavaDoc evt) {
205         setPropTableCellEditor();
206         this.panel.fireChange(evt.getSource());
207     }
208     
209     public void setPropTableCellEditor() {
210         
211         javax.swing.JComboBox JavaDoc propNameComboBox = new javax.swing.JComboBox JavaDoc();
212                 
213         String JavaDoc[] remainingProperties = null;
214         remainingProperties = FieldHelper.getRemainingFieldNames(propertiesGroup, this.helper.getData().getPropertyNames());
215         
216         for (int i = 0; i < remainingProperties.length; i++)
217             propNameComboBox.addItem(remainingProperties[i]);
218         propNameComboBox.setEditable(true);
219         this.propNameColumn = propertyTable.getColumnModel().getColumn(0);
220         propNameColumn.setCellEditor(new javax.swing.DefaultCellEditor JavaDoc(propNameComboBox));
221         this.propValueColumn = propertyTable.getColumnModel().getColumn(1);
222         
223         javax.swing.DefaultCellEditor JavaDoc editor = new javax.swing.DefaultCellEditor JavaDoc(new javax.swing.JTextField JavaDoc());
224         editor.setClickCountToStart(1);
225         propValueColumn.setCellEditor(editor);
226     }
227     
228     public void refreshFields() {
229         ResourceConfigData data = this.helper.getData();
230         ((PropertiesTableModel)propertyTable.getModel()).setData(this.helper.getData());
231         descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", data.getString(__JndiName)));
232     }
233     
234     // Variables declaration - do not modify//GEN-BEGIN:variables
235
private javax.swing.JButton JavaDoc addButton;
236     private javax.swing.JPanel JavaDoc buttonsPane;
237     private javax.swing.JTextArea JavaDoc descriptionTextArea;
238     private javax.swing.JScrollPane JavaDoc jScrollPane1;
239     private javax.swing.JLabel JavaDoc propertyInfo;
240     private javax.swing.JTable JavaDoc propertyTable;
241     private javax.swing.JButton JavaDoc removeButton;
242     // End of variables declaration//GEN-END:variables
243

244      public void setInitialFocus(){
245          new setFocus(addButton);
246      }
247 }
248
Popular Tags