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.MBeanOperationException;
054: import org.netbeans.modules.jmx.mbeanwizard.tablemodel.MBeanOperationTableModel;
055:
056: /**
057: * Class which handels the behaviour of the panel which popups the exception
058: * window
059: *
060: */
061: public class OperationExceptionPanelEditor 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 MBeanOperationTableModel model;
070: private JPanel this Panel;
071: private JTextField text;
072: private int editingRow;
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 model of the operation table
082: * @param editingRow the current edited row in the table
083: */
084: public OperationExceptionPanelEditor(
085: MBeanOperationTableModel model, JPanel panel,
086: JTextField jTextField, int editingRow) {
087: this .model = model;
088: this .this Panel = panel;
089: this .text = jTextField;
090: this .editingRow = editingRow;
091: }
092:
093: /**
094: * Overriden method; called eached time the component gets in the
095: * editor 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 or not
099: * @param row the selected row in the table
100: * @param column the selected column in the table
101: * @return Component the modified component
102: */
103: public Component getTableCellEditorComponent(JTable table,
104: Object value, boolean isSelected, int row, int column) {
105:
106: List<MBeanOperationException> oText = (List<MBeanOperationException>) table
107: .getModel().getValueAt(row, column);
108: String excepClassString = "";// NOI18N
109: for (int i = 0; i < oText.size(); i++) {
110: excepClassString += oText.get(i).getExceptionClass();
111:
112: if (i < oText.size() - 1)
113: excepClassString += ",";// NOI18N
114: }
115: text.setText(excepClassString);
116:
117: return this Panel;
118: }
119:
120: /**
121: * Adds a listener to the listener list
122: * @param listener a CellEditorListener
123: */
124: public void addCellEditorListener(CellEditorListener listener) {
125: listenerList.add(CellEditorListener.class, listener);
126: }
127:
128: /**
129: * Removes a listener from the listener list
130: * @param listener a CellEditorListener
131: */
132: public void removeCellEditorListener(CellEditorListener listener) {
133: listenerList.remove(CellEditorListener.class, listener);
134: }
135:
136: protected void fireEditingStopped() {
137: CellEditorListener listener;
138: Object[] listeners = listenerList.getListenerList();
139: for (int i = 0; i < listeners.length; i++) {
140: if (listeners[i] == CellEditorListener.class) {
141: listener = (CellEditorListener) listeners[i + 1];
142: listener.editingStopped(changeEvent);
143: }
144: }
145: }
146:
147: protected void fireEditingCanceled() {
148: CellEditorListener listener;
149: Object[] listeners = listenerList.getListenerList();
150: for (int i = 0; i < listeners.length; i++) {
151: if (listeners[i] == CellEditorListener.class) {
152: listener = (CellEditorListener) listeners[i + 1];
153: listener.editingCanceled(changeEvent);
154: }
155: }
156: }
157:
158: public void cancelCellEditing() {
159: fireEditingCanceled();
160: }
161:
162: public boolean stopCellEditing() {
163: cancelCellEditing();
164: return true;
165: }
166:
167: public boolean isCellEditable(java.util.EventObject event) {
168: return true;
169: }
170:
171: public boolean shouldSelectCell(java.util.EventObject event) {
172: return true;
173: }
174:
175: public Object getCellEditorValue() {
176: return model.getOperation(editingRow).getExceptionsList();
177: }
178:
179: }
|