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 1997-2006 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.mercurial.options;
042:
043: import java.util.Arrays;
044: import java.util.HashMap;
045: import java.util.Map;
046: import java.util.ResourceBundle;
047: import javax.swing.table.AbstractTableModel;
048: import org.openide.util.NbBundle;
049: import org.netbeans.modules.mercurial.ui.properties.HgPropertiesNode;
050:
051: /**
052: *
053: * @author Peter Pis
054: */
055: public class PropertiesTableModel extends AbstractTableModel {
056:
057: public static final String COLUMN_NAME_NAME = "name"; // NOI18N
058: public static final String COLUMN_NAME_VALUE = "value"; // NOI18N
059:
060: private HgPropertiesNode[] nodes;
061: private String[] columns;
062:
063: private static final Map<String, String[]> columnLabels = new HashMap<String, String[]>(
064: 2);
065:
066: {
067: ResourceBundle loc = NbBundle
068: .getBundle(PropertiesTableModel.class);
069: columnLabels.put(COLUMN_NAME_NAME, new String[] {
070: loc.getString("CTL_PropertiesTable_Column_Name"),
071: loc.getString("CTL_PropertiesTable_Column_Name") }); // NOI18N
072: columnLabels.put(COLUMN_NAME_VALUE, new String[] {
073: loc.getString("CTL_PropertiesTable_Column_Value"),
074: loc.getString("CTL_PropertiesTable_Column_Value") }); // NOI18N
075: }
076:
077: /** Creates a new instance of PropertiesTableModel */
078: public PropertiesTableModel(String[] clms) {
079: if (Arrays.equals(columns, clms))
080: return;
081: setColumns(clms);
082: setNodes(new HgPropertiesNode[0]);
083: }
084:
085: public void setColumns(String[] clms) {
086: this .columns = clms;
087: fireTableStructureChanged();
088: }
089:
090: public void setNodes(HgPropertiesNode[] nodes) {
091: this .nodes = nodes;
092: fireTableDataChanged();
093: }
094:
095: public HgPropertiesNode[] getNodes() {
096: return nodes;
097: }
098:
099: public HgPropertiesNode getNode(int row) {
100: return nodes[row];
101: }
102:
103: public int getRowCount() {
104: return nodes.length;
105: }
106:
107: public String getColumnName(int column) {
108: return columnLabels.get(columns[column])[0];
109: }
110:
111: public int getColumnCount() {
112: return columns.length;
113: }
114:
115: public Object getValueAt(int rowIndex, int columnIndex) {
116: String clm = columns[columnIndex];
117: if (clm.equals(COLUMN_NAME_NAME)) {
118: return nodes[rowIndex].getName();
119: } else if (clm.equals(COLUMN_NAME_VALUE)) {
120: return nodes[rowIndex].getValue();
121: }
122: throw new IllegalArgumentException(
123: "The column index is out of index: " + columnIndex); // NOI18N
124: }
125:
126: }
|