1 19 20 package org.netbeans.swing.outline; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.event.TableModelEvent ; 25 import javax.swing.event.TableModelListener ; 26 import javax.swing.table.TableModel ; 27 28 35 final class ProxyTableModel implements TableModel , NodeRowModel { 36 private List listeners = new ArrayList (); 37 private RowModel rowmodel; 38 private OutlineModel outlineModel; 39 41 public ProxyTableModel(RowModel rowmodel) { 42 this.rowmodel = rowmodel; 43 } 44 45 47 void setOutlineModel (OutlineModel mdl) { 48 this.outlineModel = mdl; 49 } 50 51 53 OutlineModel getOutlineModel () { 54 return outlineModel; 55 } 56 57 public Class getColumnClass(int columnIndex) { 58 return rowmodel.getColumnClass(columnIndex); 59 } 60 61 public int getColumnCount() { 62 return rowmodel.getColumnCount(); 63 } 64 65 public String getColumnName(int columnIndex) { 66 return rowmodel.getColumnName(columnIndex); 67 } 68 69 public int getRowCount() { 70 return -1; 73 } 74 75 public Object getValueAt(int rowIndex, int columnIndex) { 76 Object node = getNodeForRow(rowIndex); 77 return rowmodel.getValueFor(node, columnIndex); 78 } 79 80 public boolean isCellEditable(int rowIndex, int columnIndex) { 81 Object node = getNodeForRow(rowIndex); 82 return rowmodel.isCellEditable (node, columnIndex); 83 } 84 85 public synchronized void removeTableModelListener(TableModelListener l) { 86 listeners.remove(l); 87 } 88 89 public synchronized void addTableModelListener(TableModelListener l) { 90 listeners.add(l); 91 } 92 93 private void fire (TableModelEvent e) { 94 TableModelListener [] l; 95 synchronized (this) { 96 l = new TableModelListener [listeners.size()]; 97 l = (TableModelListener []) listeners.toArray(l); 98 } 99 for (int i=0; i < l.length; i++) { 100 l[i].tableChanged(e); 101 } 102 } 103 104 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 105 Object node = getNodeForRow(rowIndex); 106 rowmodel.setValueFor (node, columnIndex, aValue); 107 TableModelEvent e = new TableModelEvent (this, rowIndex, rowIndex, 108 columnIndex); 109 fire(e); 110 } 111 112 117 public Object getNodeForRow(int row) { 118 return getOutlineModel().getValueAt(row, 0); 119 } 120 121 122 } 123 | Popular Tags |