KickJava   Java API By Example, From Geeks To Geeks.

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


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  * JmsPropertyVisualPanel.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.table.*;
28
import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.TableModelEvent JavaDoc;
30 import javax.swing.event.TableModelListener JavaDoc;
31 import javax.swing.ListSelectionModel JavaDoc;
32 import org.openide.util.NbBundle;
33 import java.util.ResourceBundle JavaDoc;
34
35 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
36
37 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
38 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
39 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper;
40
41 /**
42  *
43  * @author Jennifer Chou
44  */

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

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

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

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

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

254      public void setInitialFocus(){
255          new setFocus(addButton);
256      }
257 }
258
Popular Tags