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:
042: package org.netbeans.modules.jmx.mbeanwizard.tablemodel;
043:
044: import java.util.ArrayList;
045: import org.openide.util.NbBundle;
046: import org.netbeans.modules.jmx.WizardConstants;
047: import org.netbeans.modules.jmx.mbeanwizard.MBeanWrapperAttribute;
048: import org.netbeans.modules.jmx.MBeanAttribute;
049:
050: /**
051: *
052: * @author an156382
053: */
054: public class MBeanWrapperAttributeTableModel extends
055: MBeanAttributeTableModel {
056:
057: //other idx inherited
058: public static final int IDX_ATTR_SELECTION = 0;
059:
060: private int firstEditableRow = 0;
061:
062: /**
063: * Creates a new instance of MBeanWrapperAttributeTableModel
064: */
065: public MBeanWrapperAttributeTableModel() {
066:
067: bundle = NbBundle.getBundle(MBeanAttributeTableModel.class);
068:
069: data = new ArrayList();
070:
071: columnNames = new String[5];
072:
073: String ss = bundle.getString("LBL_AttrSelection");// NOI18N
074: String sn = bundle.getString("LBL_AttrName");// NOI18N
075: String st = bundle.getString("LBL_AttrType");// NOI18N
076: String sa = bundle.getString("LBL_AttrAccess");// NOI18N
077: String sd = bundle.getString("LBL_AttrDescription");// NOI18N
078:
079: columnNames[IDX_ATTR_SELECTION] = ss;
080: columnNames[super .IDX_ATTR_NAME + 1] = sn;
081: columnNames[super .IDX_ATTR_TYPE + 1] = st;
082: columnNames[super .IDX_ATTR_ACCESS + 1] = sa;
083: columnNames[super .IDX_ATTR_DESCRIPTION + 1] = sd;
084:
085: lastIndex = 0;
086: }
087:
088: public void setFirstEditableRow(int row) {
089: firstEditableRow = row;
090: }
091:
092: public int getFirstEditableRow() {
093: return firstEditableRow;
094: }
095:
096: /**
097: * Overridden method from superclass
098: */
099: public Object getValueAt(int row, int col) {
100:
101: MBeanWrapperAttribute attr = (MBeanWrapperAttribute) data
102: .get(row);
103: switch (col) {
104: case 0:
105: return attr.isSelected();
106: case 1:
107: return attr.getName();
108: case 2:
109: return attr.getTypeName();
110: case 3:
111: return attr.getAccess();
112: case 4:
113: return attr.getDescription();
114: default:
115: System.out.println("Error getValueAt " + // NOI18N
116: "MBeanWrapperAttributeTableModel " + col);// NOI18N
117: break;
118: }
119: return null;
120: }
121:
122: /**
123: * Overriden method from superclass
124: */
125: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
126:
127: if (rowIndex < this .size()) {
128: MBeanWrapperAttribute attr = (MBeanWrapperAttribute) data
129: .get(rowIndex);
130: switch (columnIndex) {
131: case 0:
132: attr.setSelected((Boolean) aValue);
133: break;
134: case 1:
135: attr.setName((String) aValue);
136: break;
137: case 2:
138: attr.setTypeName((String) aValue);
139: break;
140: case 3:
141: attr.setAccess((String) aValue);
142: break;
143: case 4:
144: attr.setDescription((String) aValue);
145: break;
146: default:
147: System.out.println("Error setValueAt "
148: + // NOI18N
149: "MBeanWrapperAttributeTableModel "
150: + columnIndex);// NOI18N
151: break;
152: }
153: }
154: }
155:
156: public MBeanWrapperAttribute getWrapperAttribute(int row) {
157: return (MBeanWrapperAttribute) data.get(row);
158: }
159:
160: public void addRow(MBeanAttribute attr) {
161: MBeanWrapperAttribute mba = new MBeanWrapperAttribute(true,
162: attr.getName(), attr.getTypeName(), attr.getAccess(),
163: attr.getDescription(), attr.getTypeMirror());
164: data.add(mba);
165:
166: //table is informed about the change to update the view
167: this .fireTableDataChanged();
168: }
169:
170: public void addRow() {
171: MBeanWrapperAttribute mba = new MBeanWrapperAttribute(true,
172: WizardConstants.ATTR_NAME_DEFVALUE + lastIndex,
173: WizardConstants.STRING_OBJ_FULLNAME,
174: WizardConstants.ATTR_ACCESS_READ_WRITE,
175: WizardConstants.ATTR_DESCR_DEFVALUE_PREFIX + lastIndex
176: + WizardConstants.ATTR_DESCR_DEFVALUE_SUFFIX,
177: null);
178: lastIndex++;
179: data.add(mba);
180:
181: //table is informed about the change to update the view
182: this.fireTableDataChanged();
183: }
184: }
|