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 2004-2005 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: package org.netbeans.modules.jmx.mbeanwizard.editor;
042:
043: import javax.swing.table.TableCellEditor;
044: import javax.swing.JPanel;
045: import javax.swing.event.EventListenerList;
046: import javax.swing.event.ChangeEvent;
047: import javax.swing.JTable;
048: import javax.swing.JTextField;
049: import javax.swing.event.CellEditorListener;
050:
051: import java.awt.Component;
052: import java.util.List;
053: import org.netbeans.modules.jmx.MBeanOperationParameter;
054: import org.netbeans.modules.jmx.mbeanwizard.tablemodel.MBeanOperationTableModel;
055:
056: /**
057: * Class which handels the behaviour of the panel which popups the parameter
058: * window
059: *
060: */
061: public class OperationParameterPanelEditor implements TableCellEditor {
062:
063: /*******************************************************************/
064: // here, the model is not typed because more than one table uses it
065: // i.e we have to call explicitely the model's internal structure
066: // via getValueAt and setValueAt
067: /********************************************************************/
068:
069: private JPanel this Panel;
070: private JTextField text;
071: private int editingRow = 0;
072: private MBeanOperationTableModel model = null;
073:
074: protected EventListenerList listenerList = new EventListenerList();
075: protected ChangeEvent changeEvent = new ChangeEvent(this );
076:
077: /**
078: * Constructor
079: * @param panel the panel containing the textfield and the popup button
080: * @param jTextField the textfield
081: * @param model the table model of the operation table
082: * @param editingRow the current edited row in the table
083: */
084: public OperationParameterPanelEditor(
085: MBeanOperationTableModel model, JPanel panel,
086: JTextField jTextField, int editingRow) {
087: this .this Panel = panel;
088: this .text = jTextField;
089: this .editingRow = editingRow;
090: this .model = model;
091: }
092:
093: /**
094: * Overriden method; called eached time the component gets in the editor
095: * mode
096: * @param table the JTable in which the component is in
097: * @param value the object with the current value
098: * @param isSelected boolean indicating whether the component is selected
099: * or not
100: * @param row the selected row in the table
101: * @param column the selected column in the table
102: * @return Component the modified component
103: */
104: public Component getTableCellEditorComponent(JTable table,
105: Object value, boolean isSelected, int row, int column) {
106: List<MBeanOperationParameter> oText = (List<MBeanOperationParameter>) table
107: .getModel().getValueAt(row, column);
108: String paramString = "";// NOI18N
109: for (int i = 0; i < oText.size(); i++) {
110: paramString += oText.get(i).getParamType() + " " + // NOI18N
111: oText.get(i).getParamName();
112:
113: if (i < oText.size() - 1)
114: paramString += ",";// NOI18N
115: }
116: text.setText(paramString);
117:
118: return this Panel;
119: }
120:
121: /**
122: * Adds a listener to the listener list
123: * @param listener a CellEditorListener
124: */
125: public void addCellEditorListener(CellEditorListener listener) {
126: listenerList.add(CellEditorListener.class, listener);
127: }
128:
129: /**
130: * Removes a listener from the listener list
131: * @param listener a CellEditorListener
132: */
133: public void removeCellEditorListener(CellEditorListener listener) {
134: listenerList.remove(CellEditorListener.class, listener);
135: }
136:
137: protected void fireEditingStopped() {
138: CellEditorListener listener;
139: Object[] listeners = listenerList.getListenerList();
140: for (int i = 0; i < listeners.length; i++) {
141: if (listeners[i] == CellEditorListener.class) {
142: listener = (CellEditorListener) listeners[i + 1];
143: listener.editingStopped(changeEvent);
144: }
145: }
146: }
147:
148: protected void fireEditingCanceled() {
149: CellEditorListener listener;
150: Object[] listeners = listenerList.getListenerList();
151: for (int i = 0; i < listeners.length; i++) {
152: if (listeners[i] == CellEditorListener.class) {
153: listener = (CellEditorListener) listeners[i + 1];
154: listener.editingCanceled(changeEvent);
155: }
156: }
157: }
158:
159: public void cancelCellEditing() {
160: fireEditingCanceled();
161: }
162:
163: public boolean stopCellEditing() {
164: cancelCellEditing();
165: return true;
166: }
167:
168: public boolean isCellEditable(java.util.EventObject event) {
169: return true;
170: }
171:
172: public boolean shouldSelectCell(java.util.EventObject event) {
173: return true;
174: }
175:
176: public Object getCellEditorValue() {
177: return model.getOperation(editingRow).getParametersList();
178: }
179:
180: }
|