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 org.netbeans.modules.jmx.MBeanOperation;
045: import org.openide.util.NbBundle;
046: import org.netbeans.modules.jmx.WizardConstants;
047: import org.netbeans.modules.jmx.MBeanOperationException;
048: import org.netbeans.modules.jmx.MBeanOperationParameter;
049:
050: /**
051: * Class implementing the table model for the mbean operation table
052: *
053: */
054: public class MBeanOperationTableModel extends AbstractJMXTableModel {
055: public static final int IDX_METH_NAME = 0;
056: public static final int IDX_METH_TYPE = 1;
057: public static final int IDX_METH_PARAM = 2;
058: public static final int IDX_METH_EXCEPTION = 3;
059: public static final int IDX_METH_DESCRIPTION = 4;
060:
061: private int lastIndex;
062:
063: /**
064: * Constructor
065: */
066: public MBeanOperationTableModel() {
067: super ();
068:
069: bundle = NbBundle.getBundle(MBeanOperationTableModel.class);
070:
071: data = new ArrayList();
072:
073: columnNames = new String[5];
074:
075: String sn = bundle.getString("LBL_MethodName");// NOI18N
076: String st = bundle.getString("LBL_MethodReturnType");// NOI18N
077: String sp = bundle.getString("LBL_MethodParamType");// NOI18N
078: String se = bundle.getString("LBL_MethodExceptionType");// NOI18N
079: String sd = bundle.getString("LBL_MethodDescription");// NOI18N
080:
081: columnNames[IDX_METH_NAME] = sn;
082: columnNames[IDX_METH_TYPE] = st;
083: columnNames[IDX_METH_PARAM] = sp;
084: columnNames[IDX_METH_EXCEPTION] = se;
085: columnNames[IDX_METH_DESCRIPTION] = sd;
086:
087: lastIndex = 0;
088: }
089:
090: /**
091: * Instantiates a new operation; called when a line is added to the
092: * table
093: * @return MBeanOperation the created operation
094: */
095: public MBeanOperation createNewOperation() {
096: MBeanOperation oper = new MBeanOperation(
097: WizardConstants.METH_NAME_DEFVALUE + lastIndex,
098: WizardConstants.VOID_RET_TYPE, null, null,
099: WizardConstants.METH_DESCR_DEFVALUE_PREFIX + lastIndex
100: + WizardConstants.METH_DESCR_DEFVALUE_SUFFIX);
101: lastIndex++;
102: return oper;
103: }
104:
105: public void clear() {
106: data.clear();
107: }
108:
109: /**
110: * Returns the operation at index index
111: * @return MBeanOperation the operation at index index
112: */
113: public MBeanOperation getOperation(int index) {
114: return (MBeanOperation) data.get(index);
115: }
116:
117: /**
118: * Overriden method from superclass
119: */
120: public Object getValueAt(int row, int col) {
121: MBeanOperation oper = (MBeanOperation) data.get(row);
122: switch (col) {
123: case 0:
124: return oper.getName();
125: case 1:
126: return oper.getReturnTypeName();
127: case 2:
128: return oper.getParametersList();
129: case 3:
130: return oper.getExceptionsList();
131: case 4:
132: return oper.getDescription();
133: default:
134: System.out.println("Error getValueAt " + // NOI18N
135: "MBeanMethodTableModel " + col);// NOI18N
136: break;
137: }
138: return null;
139: }
140:
141: /**
142: * Overriden method from superclass
143: */
144: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
145: if (rowIndex < this .size()) {
146: MBeanOperation oper = (MBeanOperation) data.get(rowIndex);
147: switch (columnIndex) {
148: case 0:
149: oper.setName((String) aValue);
150: break;
151: case 1:
152: oper.setReturnTypeName((String) aValue);
153: break;
154: case 2:
155: oper
156: .setParametersList((ArrayList<MBeanOperationParameter>) aValue);
157: break;
158: case 3:
159: oper
160: .setExceptionsList((ArrayList<MBeanOperationException>) aValue);
161: break;
162: case 4:
163: oper.setDescription((String) aValue);
164: break;
165: default:
166: System.out.println("Error setValueAt " + // NOI18N
167: "MBeanMethodTableModel " + columnIndex);// NOI18N
168: break;
169: }
170: }
171: }
172:
173: /**
174: * Overriden method from superclass
175: */
176: public void addRow() {
177:
178: MBeanOperation mbo = createNewOperation();
179: data.add(mbo);
180:
181: //table is informed about the change to update the view
182: this .fireTableDataChanged();
183: }
184:
185: public void addRow(MBeanOperation op) {
186: MBeanOperation mbo = new MBeanOperation(op.getName(), op
187: .getReturnTypeName(), op.getParametersList(), op
188: .getExceptionsList(), op.getDescription());
189: data.add(mbo);
190:
191: //table is informed about the change to update the view
192: this.fireTableDataChanged();
193: }
194: }
|