001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * MailPropertyVisualPanel.java
043: *
044: * Created on December 17, 2002, 1:19 PM
045: */
046:
047: package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
048:
049: import javax.swing.event.ChangeEvent;
050: import javax.swing.event.TableModelEvent;
051: import javax.swing.event.TableModelListener;
052: import javax.swing.ListSelectionModel;
053: import org.openide.util.NbBundle;
054: import java.util.ResourceBundle;
055:
056: import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
057:
058: import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
059: import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
060: import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper;
061:
062: /**
063: *
064: * @author Jennifer Chou
065: */
066: public class MailPropertyVisualPanel extends javax.swing.JPanel
067: implements WizardConstants, TableModelListener {
068:
069: private final MailPropertyPanel panel;
070: private FieldGroup generalGroup;
071: private FieldGroup propertiesGroup;
072: private PropertiesTableModel tableModel;
073: private ResourceConfigHelper helper;
074: private javax.swing.table.TableColumn propNameColumn;
075: private javax.swing.table.TableColumn propValueColumn;
076:
077: /** Creates new form MailPropertyVisualPanel */
078: public MailPropertyVisualPanel(MailPropertyPanel panel) {
079: this .panel = panel;
080: this .helper = panel.getHelper();
081: this .generalGroup = panel.getFieldGroup(__General);
082: this .propertiesGroup = panel.getFieldGroup(__Properties);
083:
084: tableModel = new PropertiesTableModel(this .helper.getData());
085: initComponents();
086: setPropTableCellEditor();
087: tableModel.addTableModelListener(this );
088: propertyTable
089: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
090: propertyTable.setRowSelectionAllowed(true);
091:
092: // Provide a name in the title bar.
093: setName(NbBundle.getMessage(MailPropertyVisualPanel.class,
094: "TITLE_MailPropertyPanel")); //NOI18N
095:
096: }
097:
098: /** This method is called from within the constructor to
099: * initialize the form.
100: * WARNING: Do NOT modify this code. The content of this method is
101: * always regenerated by the Form Editor.
102: */
103: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
104: private void initComponents() {
105: java.awt.GridBagConstraints gridBagConstraints;
106:
107: descriptionTextArea = new javax.swing.JTextArea();
108: propertyInfo = new javax.swing.JLabel();
109: jScrollPane1 = new javax.swing.JScrollPane();
110: propertyTable = new PropertiesTable();
111: buttonsPane = new javax.swing.JPanel();
112: addButton = new javax.swing.JButton();
113: removeButton = new javax.swing.JButton();
114:
115: setMinimumSize(new java.awt.Dimension(627, 305));
116: setPreferredSize(new java.awt.Dimension(627, 305));
117: setLayout(new java.awt.GridBagLayout());
118:
119: descriptionTextArea.setEditable(false);
120: descriptionTextArea.setLineWrap(true);
121: descriptionTextArea.setText(NbBundle.getMessage(
122: MailPropertyVisualPanel.class,
123: "MailPropertyPanel_Description", this .helper.getData()
124: .getString(__JndiName)));
125: descriptionTextArea.setWrapStyleWord(true);
126: descriptionTextArea.setMinimumSize(new java.awt.Dimension(500,
127: 17));
128: descriptionTextArea.setOpaque(false);
129: descriptionTextArea.setPreferredSize(new java.awt.Dimension(
130: 500, 17));
131: gridBagConstraints = new java.awt.GridBagConstraints();
132: gridBagConstraints.gridx = 0;
133: gridBagConstraints.gridy = 0;
134: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
135: gridBagConstraints.weightx = 1.0;
136: gridBagConstraints.weighty = 1.0;
137: gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 11);
138: add(descriptionTextArea, gridBagConstraints);
139: java.util.ResourceBundle bundle = java.util.ResourceBundle
140: .getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle"); // NOI18N
141: descriptionTextArea.getAccessibleContext().setAccessibleName(
142: bundle.getString("MailPropertyPanel_Description")); // NOI18N
143: descriptionTextArea
144: .getAccessibleContext()
145: .setAccessibleDescription(
146: bundle
147: .getString("MailPropertyPanel_Description")); // NOI18N
148:
149: propertyInfo
150: .setDisplayedMnemonic(java.util.ResourceBundle
151: .getBundle(
152: "org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle")
153: .getString("LBL_properties_Mnemonic").charAt(0));
154: propertyInfo.setLabelFor(propertyTable);
155: propertyInfo.setText(bundle.getString("LBL_properties")); // NOI18N
156: gridBagConstraints = new java.awt.GridBagConstraints();
157: gridBagConstraints.gridx = 0;
158: gridBagConstraints.gridy = 1;
159: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11);
161: add(propertyInfo, gridBagConstraints);
162: propertyInfo.getAccessibleContext().setAccessibleName(
163: bundle.getString("LBL_properties")); // NOI18N
164: propertyInfo.getAccessibleContext().setAccessibleDescription(
165: bundle.getString("ACS_propTableMail_A11yDesc")); // NOI18N
166:
167: jScrollPane1.setPreferredSize(new java.awt.Dimension(453, 17));
168:
169: propertyTable.setModel(tableModel);
170: jScrollPane1.setViewportView(propertyTable);
171: propertyTable.getAccessibleContext().setAccessibleName(
172: bundle.getString("LBL_AddProperty")); // NOI18N
173: propertyTable.getAccessibleContext().setAccessibleDescription(
174: bundle.getString("ACS_propTableMail_A11yDesc")); // NOI18N
175:
176: gridBagConstraints = new java.awt.GridBagConstraints();
177: gridBagConstraints.gridx = 0;
178: gridBagConstraints.gridy = 2;
179: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
180: gridBagConstraints.insets = new java.awt.Insets(10, 12, 10, 11);
181: add(jScrollPane1, gridBagConstraints);
182: jScrollPane1.getAccessibleContext().setAccessibleName(
183: bundle.getString("LBL_properties")); // NOI18N
184: jScrollPane1.getAccessibleContext().setAccessibleDescription(
185: bundle.getString("ACS_propTableMail_A11yDesc")); // NOI18N
186:
187: buttonsPane.setLayout(new java.awt.GridBagLayout());
188:
189: addButton
190: .setMnemonic(java.util.ResourceBundle
191: .getBundle(
192: "org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle")
193: .getString("LBL_Add_Mnemonic").charAt(0));
194: addButton.setText(bundle.getString("LBL_Add")); // NOI18N
195: addButton
196: .addActionListener(new java.awt.event.ActionListener() {
197: public void actionPerformed(
198: java.awt.event.ActionEvent evt) {
199: addButtonActionPerformed(evt);
200: }
201: });
202: gridBagConstraints = new java.awt.GridBagConstraints();
203: gridBagConstraints.gridx = 0;
204: gridBagConstraints.gridy = 0;
205: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
206: gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12);
207: buttonsPane.add(addButton, gridBagConstraints);
208: addButton.getAccessibleContext().setAccessibleDescription(
209: bundle.getString("ACS_AddButtonA11yDesc")); // NOI18N
210:
211: removeButton
212: .setMnemonic(java.util.ResourceBundle
213: .getBundle(
214: "org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle")
215: .getString("LBL_Remove_Mnemonic").charAt(0));
216: removeButton.setText(bundle.getString("LBL_Remove")); // NOI18N
217: removeButton
218: .addActionListener(new java.awt.event.ActionListener() {
219: public void actionPerformed(
220: java.awt.event.ActionEvent evt) {
221: removeButtonActionPerformed(evt);
222: }
223: });
224: gridBagConstraints = new java.awt.GridBagConstraints();
225: gridBagConstraints.gridx = 0;
226: gridBagConstraints.gridy = 1;
227: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
228: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12);
229: buttonsPane.add(removeButton, gridBagConstraints);
230: removeButton.getAccessibleContext().setAccessibleDescription(
231: bundle.getString("ACS_RemoveButtonA11yDesc")); // NOI18N
232:
233: gridBagConstraints = new java.awt.GridBagConstraints();
234: gridBagConstraints.gridx = 1;
235: gridBagConstraints.gridy = 2;
236: gridBagConstraints.ipady = 150;
237: add(buttonsPane, gridBagConstraints);
238: buttonsPane.getAccessibleContext().setAccessibleName(
239: bundle.getString("LBL_properties")); // NOI18N
240: buttonsPane.getAccessibleContext().setAccessibleDescription(
241: bundle.getString("ACS_propTableMail_A11yDesc")); // NOI18N
242:
243: getAccessibleContext().setAccessibleName(
244: bundle.getString("TITLE_MailPropertyPanel")); // NOI18N
245: getAccessibleContext().setAccessibleDescription(
246: bundle.getString("MailPropertyPanel_Description")); // NOI18N
247: }// </editor-fold>//GEN-END:initComponents
248:
249: private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
250: // Add your handling code here:
251: //Fix for bug#4958730 - value overwrites into next row
252: propertyTable.editingStopped(new ChangeEvent(this ));
253: ResourceConfigData data = this .helper.getData();
254: data.addProperty(new NameValuePair());
255: tableModel.fireTableDataChanged();
256: }//GEN-LAST:event_addButtonActionPerformed
257:
258: private void removeButtonActionPerformed(
259: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
260: // Add your handling code here:
261: int selectedRow = propertyTable.getSelectedRow();
262: if (selectedRow != -1) {
263: //Fix for bug#4958730 - value overwrites into next row
264: propertyTable.editingStopped(new ChangeEvent(this ));
265: this .helper.getData().removeProperty(selectedRow);
266: tableModel.fireTableDataChanged();
267: }
268: }//GEN-LAST:event_removeButtonActionPerformed
269:
270: public void tableChanged(TableModelEvent evt) {
271: setPropTableCellEditor();
272: this .panel.fireChange(evt.getSource());
273: }
274:
275: public void setPropTableCellEditor() {
276: javax.swing.JComboBox propNameComboBox = new javax.swing.JComboBox();
277: String[] remainingProperties = FieldHelper
278: .getRemainingFieldNames(propertiesGroup, this .helper
279: .getData().getPropertyNames());
280:
281: for (int i = 0; i < remainingProperties.length; i++)
282: propNameComboBox.addItem(remainingProperties[i]);
283: propNameComboBox.setEditable(true);
284: this .propNameColumn = propertyTable.getColumnModel().getColumn(
285: 0);
286: propNameColumn.setCellEditor(new javax.swing.DefaultCellEditor(
287: propNameComboBox));
288: this .propValueColumn = propertyTable.getColumnModel()
289: .getColumn(1);
290:
291: javax.swing.DefaultCellEditor editor = new javax.swing.DefaultCellEditor(
292: new javax.swing.JTextField());
293: editor.setClickCountToStart(1);
294: propValueColumn.setCellEditor(editor);
295: }
296:
297: public void refreshFields() {
298: ResourceConfigData data = this .helper.getData();
299: ((PropertiesTableModel) propertyTable.getModel())
300: .setData(this .helper.getData());
301: descriptionTextArea.setText(NbBundle.getMessage(
302: MailPropertyVisualPanel.class,
303: "MailPropertyPanel_Description", data
304: .getString(__JndiName))); //NOI18N
305: }
306:
307: // Variables declaration - do not modify//GEN-BEGIN:variables
308: private javax.swing.JButton addButton;
309: private javax.swing.JPanel buttonsPane;
310: private javax.swing.JTextArea descriptionTextArea;
311: private javax.swing.JScrollPane jScrollPane1;
312: private javax.swing.JLabel propertyInfo;
313: private javax.swing.JTable propertyTable;
314: private javax.swing.JButton removeButton;
315:
316: // End of variables declaration//GEN-END:variables
317:
318: public void setInitialFocus() {
319: new setFocus(addButton);
320: }
321: }
|