1 19 package org.netbeans.modules.subversion.ui.properties; 20 21 import java.util.Arrays ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.ResourceBundle ; 25 import javax.swing.table.AbstractTableModel ; 26 import org.openide.util.NbBundle; 27 28 29 33 public class PropertiesTableModel extends AbstractTableModel { 34 35 static final String COLUMN_NAME_NAME = "name"; 36 static final String COLUMN_NAME_VALUE = "value"; 37 38 private SvnPropertiesNode[] nodes; 39 private String [] columns; 40 41 private static final Map <String , String []> columnLabels = new HashMap <String , String []>(2); 42 43 { 44 ResourceBundle loc = NbBundle.getBundle(PropertiesTableModel.class); 45 columnLabels.put(COLUMN_NAME_NAME, new String [] {loc.getString("CTL_PropertiesTable_Column_Name"), loc.getString("CTL_PropertiesTable_Column_Name")}); 46 columnLabels.put(COLUMN_NAME_VALUE, new String [] {loc.getString("CTL_PropertiesTable_Column_Value"), loc.getString("CTL_PropertiesTable_Column_Value")}); 47 } 48 49 50 public PropertiesTableModel(String [] clms) { 51 if (Arrays.equals(columns, clms)) 52 return; 53 setColumns(clms); 54 setNodes(new SvnPropertiesNode[0]); 55 } 56 57 public void setColumns(String [] 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 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 getValueAt(int rowIndex, int columnIndex) { 88 String 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 ("The column index is out of index: " + columnIndex); 95 } 96 97 98 } 99 | Popular Tags |