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.netbeans.modules.jmx.MBeanOperationParameter;
046: import org.openide.util.NbBundle;
047: import org.netbeans.modules.jmx.WizardConstants;
048:
049: /**
050: * Class implementing the table model for the mbean operation parameter popup table
051: *
052: */
053: public class OperationParameterTableModel extends AbstractJMXTableModel {
054:
055: public static final int IDX_OP_PARAM_NAME = 0;
056: public static final int IDX_OP_PARAM_TYPE = 1;
057: public static final int IDX_OP_PARAM_DESCRIPTION = 2;
058:
059: /**
060: * Constructor
061: */
062: public OperationParameterTableModel() {
063: super ();
064: bundle = NbBundle.getBundle(OperationParameterTableModel.class);
065: data = new ArrayList();
066:
067: columnNames = new String[3];
068: String sopn = bundle.getString("LBL_OperationParameterName");// NOI18N
069: String sopt = bundle.getString("LBL_OperationParameterType");// NOI18N
070: String sopd = bundle
071: .getString("LBL_OperationParameterDescription");// NOI18N
072:
073: columnNames[IDX_OP_PARAM_NAME] = sopn;
074: columnNames[IDX_OP_PARAM_TYPE] = sopt;
075: columnNames[IDX_OP_PARAM_DESCRIPTION] = sopd;
076: }
077:
078: /**
079: * Instantiates a new parameter; called when a line is added to the
080: * popup table
081: * @return MBeanOperationParameter the created parameter
082: */
083: public MBeanOperationParameter createNewParameter() {
084:
085: return new MBeanOperationParameter(
086: WizardConstants.METH_PARAM_NAME_DEFVALUE
087: + this .getRowCount(),
088: WizardConstants.STRING_OBJ_FULLNAME,
089: WizardConstants.METH_PARAM_DESCR_DEFVALUE_PREFIX
090: + this .getRowCount()
091: + WizardConstants.METH_PARAM_DESCR_DEFVALUE_SUFFIX);
092: }
093:
094: /**
095: * Returns the operation parameter at index index
096: * @return MBeanOperationParameter the operation parameter at index index
097: */
098: public MBeanOperationParameter getParameter(int index) {
099: return (MBeanOperationParameter) data.get(index);
100: }
101:
102: /**
103: * Sets the operation parameter at index index to a new object
104: * @param index the index
105: * @param param the Operation parameter to set
106: */
107: public void setParameter(int index, MBeanOperationParameter param) {
108: if (index < data.size()) {
109: data.set(index, param);
110: }
111: }
112:
113: /**
114: * Overriden method from superclass
115: */
116: public Object getValueAt(int row, int col) {
117: MBeanOperationParameter param = (MBeanOperationParameter) data
118: .get(row);
119: switch (col) {
120: case 0:
121: return param.getParamName();
122: case 1:
123: return param.getParamType();
124: case 2:
125: return param.getParamDescription();
126: default:
127: System.out.println("Error getValueAt " + // NOI18N
128: "OperationParameterTableModel " + col);// NOI18N
129: break;
130: }
131: return null;
132: }
133:
134: /**
135: * Overriden method from superclass
136: */
137: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
138: if (rowIndex < this .size()) {
139: MBeanOperationParameter param = (MBeanOperationParameter) data
140: .get(rowIndex);
141: switch (columnIndex) {
142: case 0:
143: param.setParamName((String) aValue);
144: break;
145: case 1:
146: param.setParamType((String) aValue);
147: break;
148: case 2:
149: param.setParamDescription((String) aValue);
150: break;
151: default:
152: System.out.println("Error setValueAt " + // NOI18N
153: "OperationParameterTableModel " + columnIndex);// NOI18N
154: break;
155: }
156: }
157: }
158:
159: /**
160: * Overriden method from superclass
161: */
162: public void addRow() {
163:
164: MBeanOperationParameter mbop = createNewParameter();
165: data.add(mbop);
166:
167: //table is informed about the change to update the view
168: this.fireTableDataChanged();
169: }
170: }
|