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.tablemodel;
042:
043: import java.util.ArrayList;
044: import javax.swing.JTable;
045: import org.openide.util.NbBundle;
046: import org.netbeans.modules.jmx.WizardConstants;
047: import org.netbeans.modules.jmx.MBeanOperationException;
048:
049: /**
050: * Class implementing the table model for the mbean operation exception
051: * popup table
052: *
053: */
054: public class OperationExceptionTableModel extends AbstractJMXTableModel {
055:
056: public static final int IDX_EXCEPTION_NAME = 0;
057: public static final int IDX_EXCEPTION_DESCR = 1;
058:
059: /**
060: * Constructor
061: */
062: public OperationExceptionTableModel() {
063: super ();
064: bundle = NbBundle.getBundle(OperationExceptionTableModel.class);
065: data = new ArrayList();
066: columnNames = new String[2];
067: String sen = bundle.getString("LBL_ExceptionClass");// NOI18N
068: String sed = bundle.getString("LBL_ExceptionDescription");// NOI18N
069: columnNames[IDX_EXCEPTION_NAME] = sen;
070: columnNames[IDX_EXCEPTION_DESCR] = sed;
071: }
072:
073: /**
074: * Instantiates a new exception; called when a line is added to the
075: * popup table
076: * @return MBeanOperationException the created exception
077: */
078: public MBeanOperationException createNewException() {
079:
080: return new MBeanOperationException(
081: WizardConstants.METH_EXCEP_CLASS_DEFVALUE,
082: WizardConstants.METH_EXCEP_DESCR_DEFVALUE);
083: }
084:
085: /**
086: * Returns the operation exception at index index
087: * @return MBeanOperationException the operation exception at index index
088: */
089: public MBeanOperationException getException(int index) {
090: return (MBeanOperationException) data.get(index);
091: }
092:
093: /**
094: * Sets the operation exception at index index to a new object
095: * @param index the index
096: * @param excep the Operation exception to set
097: */
098: public void setException(int index, MBeanOperationException excep) {
099: if (index < data.size()) {
100: data.set(index, excep);
101: }
102: }
103:
104: /**
105: * Overriden method from superclass
106: */
107: public Object getValueAt(int row, int col) {
108: MBeanOperationException excep = (MBeanOperationException) data
109: .get(row);
110: switch (col) {
111: case 0:
112: return excep.getExceptionClass();
113: case 1:
114: return excep.getExceptionDescription();
115: default:
116: System.out.println("Error getValueAt " + // NOI18N
117: "OperationExceptionTableModel " + col);// NOI18N
118: break;
119: }
120: return null;
121: }
122:
123: /**
124: * Overriden method from superclass
125: */
126: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
127: if (rowIndex < this .size()) {
128: MBeanOperationException excep = (MBeanOperationException) data
129: .get(rowIndex);
130: switch (columnIndex) {
131: case 0:
132: excep.setExceptionClass((String) aValue);
133: break;
134: case 1:
135: excep.setExceptionDescription((String) aValue);
136: break;
137: default:
138: System.out.println("Error setValueAt " + // NOI18N
139: "OperationExceptionTableModel " + columnIndex);// NOI18N
140: break;
141: }
142: }
143: }
144:
145: /**
146: * Overriden method from superclass
147: */
148: public void addRow() {
149:
150: MBeanOperationException mboe = createNewException();
151: data.add(mboe);
152:
153: //table is informed about the change to update the view
154: this.fireTableDataChanged();
155: }
156: }
|