KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > 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 /*
21  * CommonPropertyVisualPanel.java
22
23  */

24
25 package org.netbeans.modules.j2ee.sun.ws7.serverresources.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.ws7.serverresources.wizards.WS70WizardConstants;
38 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper;
39 /**
40  * Code reused from Appserver common API module
41  *
42  */

43 public class CommonPropertyVisualPanel extends javax.swing.JPanel JavaDoc implements WS70WizardConstants, TableModelListener JavaDoc {
44     
45     private final CommonPropertyPanel panel;
46     private ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.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 PropertyVisualPanel */
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(CommonPropertyVisualPanel.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         getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("TITLE_CommonPropertyPanel"));
91         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
92         descriptionTextArea.setEditable(false);
93         descriptionTextArea.setLineWrap(true);
94         descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
95         descriptionTextArea.setWrapStyleWord(true);
96         descriptionTextArea.setFocusable(false);
97         descriptionTextArea.setOpaque(false);
98         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
99         gridBagConstraints.gridx = 0;
100         gridBagConstraints.gridy = 0;
101         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
102         gridBagConstraints.weightx = 1.0;
103         gridBagConstraints.weighty = 1.0;
104         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 11);
105         add(descriptionTextArea, gridBagConstraints);
106         descriptionTextArea.getAccessibleContext().setAccessibleName(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
107         descriptionTextArea.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName)));
108
109         propertyInfo.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_properties_Mnemonic").charAt(0));
110         propertyInfo.setLabelFor(propertyTable);
111         propertyInfo.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_properties"));
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.gridx = 0;
114         gridBagConstraints.gridy = 1;
115         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 11);
117         add(propertyInfo, gridBagConstraints);
118         propertyInfo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
119
120         jScrollPane1.setPreferredSize(new java.awt.Dimension JavaDoc(descriptionTextArea.getWidth(), this.getHeight()));
121         propertyTable.setModel(tableModel);
122         jScrollPane1.setViewportView(propertyTable);
123         propertyTable.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_AddProperty"));
124         propertyTable.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
125
126         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
127         gridBagConstraints.gridx = 0;
128         gridBagConstraints.gridy = 2;
129         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 12, 10, 11);
131         add(jScrollPane1, gridBagConstraints);
132         jScrollPane1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_AddProperty"));
133         jScrollPane1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
134
135         buttonsPane.setLayout(new java.awt.GridBagLayout JavaDoc());
136
137         addButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Add_Mnemonic").charAt(0));
138         addButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Add"));
139         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
140             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
141                 addButtonActionPerformed(evt);
142             }
143         });
144
145         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
146         gridBagConstraints.gridx = 0;
147         gridBagConstraints.gridy = 0;
148         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 12);
150         buttonsPane.add(addButton, gridBagConstraints);
151         addButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_AddButtonA11yDesc"));
152
153         removeButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Remove_Mnemonic").charAt(0));
154         removeButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Remove"));
155         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
156             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
157                 removeButtonActionPerformed(evt);
158             }
159         });
160
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
162         gridBagConstraints.gridx = 0;
163         gridBagConstraints.gridy = 1;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
166         buttonsPane.add(removeButton, gridBagConstraints);
167         removeButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_RemoveButtonA11yDesc"));
168
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 1;
171         gridBagConstraints.gridy = 2;
172         gridBagConstraints.ipady = 150;
173         add(buttonsPane, gridBagConstraints);
174         buttonsPane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_AddProperty"));
175         buttonsPane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc"));
176
177     }// </editor-fold>//GEN-END:initComponents
178

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

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

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

239      public void setInitialFocus(){
240          new setFocus(addButton);
241      }
242 }
243
Popular Tags