KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > properties > PropertiesTableModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.ui.properties;
20
21 import java.util.Arrays JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25 import javax.swing.table.AbstractTableModel JavaDoc;
26 import org.openide.util.NbBundle;
27
28
29 /**
30  *
31  * @author Peter Pis
32  */

33 public class PropertiesTableModel extends AbstractTableModel JavaDoc {
34     
35     static final String JavaDoc COLUMN_NAME_NAME = "name";
36     static final String JavaDoc COLUMN_NAME_VALUE = "value";
37     
38     private SvnPropertiesNode[] nodes;
39     private String JavaDoc[] columns;
40     
41     private static final Map JavaDoc<String JavaDoc, String JavaDoc[]> columnLabels = new HashMap JavaDoc<String JavaDoc, String JavaDoc[]>(2);
42     
43     {
44         ResourceBundle JavaDoc loc = NbBundle.getBundle(PropertiesTableModel.class);
45         columnLabels.put(COLUMN_NAME_NAME, new String JavaDoc[] {loc.getString("CTL_PropertiesTable_Column_Name"), loc.getString("CTL_PropertiesTable_Column_Name")});
46         columnLabels.put(COLUMN_NAME_VALUE, new String JavaDoc[] {loc.getString("CTL_PropertiesTable_Column_Value"), loc.getString("CTL_PropertiesTable_Column_Value")});
47     }
48     
49     /** Creates a new instance of PropertiesTableModel */
50     public PropertiesTableModel(String JavaDoc[] clms) {
51         if (Arrays.equals(columns, clms))
52             return;
53         setColumns(clms);
54         setNodes(new SvnPropertiesNode[0]);
55     }
56     
57     public void setColumns(String JavaDoc[] clms) {
58         this.columns = clms;
59         fireTableStructureChanged();
60     }
61     
62     public void setNodes(SvnPropertiesNode[] nodes) {
63         this.nodes = nodes;
64         fireTableDataChanged();
65     }
66     
67     public SvnPropertiesNode[] getNodes() {
68         return nodes;
69     }
70     
71     public SvnPropertiesNode getNode(int row) {
72         return nodes[row];
73     }
74     
75     public int getRowCount() {
76         return nodes.length;
77     }
78
79     public String JavaDoc getColumnName(int column) {
80         return columnLabels.get(columns[column])[0];
81     }
82     
83     public int getColumnCount() {
84         return columns.length;
85     }
86
87     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
88         String JavaDoc clm = columns[columnIndex];
89         if (clm.equals(COLUMN_NAME_NAME)) {
90             return nodes[rowIndex].getName();
91         } else if (clm.equals(COLUMN_NAME_VALUE)) {
92             return nodes[rowIndex].getValue();
93         }
94         throw new IllegalArgumentException JavaDoc("The column index is out of index: " + columnIndex);
95     }
96
97     
98 }
99
Popular Tags