KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MailPropertyVisualPanel.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  *
42  * @author Jennifer Chou
43  */

44 public class MailPropertyVisualPanel extends javax.swing.JPanel JavaDoc implements WizardConstants, TableModelListener JavaDoc {
45     
46     private final MailPropertyPanel panel;
47     private FieldGroup generalGroup;
48     private FieldGroup propertiesGroup;
49     private PropertiesTableModel tableModel;
50     private ResourceConfigHelper helper;
51     private javax.swing.table.TableColumn JavaDoc propNameColumn;
52     private javax.swing.table.TableColumn JavaDoc propValueColumn;
53         
54     /** Creates new form MailPropertyVisualPanel */
55     public MailPropertyVisualPanel(MailPropertyPanel panel) {
56         this.panel = panel;
57         this.helper = panel.getHelper();
58         this.generalGroup = panel.getFieldGroup(__General);
59         this.propertiesGroup = panel.getFieldGroup(__Properties);
60
61         tableModel = new PropertiesTableModel(this.helper.getData());
62         initComponents();
63         setPropTableCellEditor();
64         tableModel.addTableModelListener(this);
65         propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
66         propertyTable.setRowSelectionAllowed(true);
67         
68         // Provide a name in the title bar.
69
setName(NbBundle.getMessage(MailPropertyVisualPanel.class, "TITLE_MailPropertyPanel")); //NOI18N
70

71     }
72     
73     /** This method is called from within the constructor to
74      * initialize the form.
75      * WARNING: Do NOT modify this code. The content of this method is
76      * always regenerated by the Form Editor.
77      */

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

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

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

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

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