1 29 30 package nextapp.echo2.app.table; 31 32 import java.io.Serializable ; 33 import java.util.EventListener ; 34 35 import nextapp.echo2.app.event.EventListenerList; 36 import nextapp.echo2.app.event.TableModelEvent; 37 import nextapp.echo2.app.event.TableModelListener; 38 39 54 public abstract class AbstractTableModel 55 implements Serializable , TableModel { 56 57 private EventListenerList listenerList = new EventListenerList(); 58 59 62 public AbstractTableModel() { 63 super(); 64 } 65 66 69 public void addTableModelListener(TableModelListener l) { 70 listenerList.addListener(TableModelListener.class, l); 71 } 72 73 80 public void fireTableCellUpdated(int column, int row) { 81 fireTableChanged(new TableModelEvent(this, column, row, row, TableModelEvent.UPDATE)); 82 } 83 84 89 public void fireTableDataChanged() { 90 fireTableChanged(new TableModelEvent(this)); 91 } 92 93 100 public void fireTableRowsDeleted(int firstRow, int lastRow) { 101 fireTableChanged(new TableModelEvent(this, TableModelEvent.ALL_COLUMNS, firstRow, lastRow, TableModelEvent.DELETE)); 102 } 103 104 111 public void fireTableRowsInserted(int firstRow, int lastRow) { 112 fireTableChanged(new TableModelEvent(this, TableModelEvent.ALL_COLUMNS, firstRow, lastRow, TableModelEvent.INSERT)); 113 } 114 115 123 public void fireTableRowsUpdated(int firstRow, int lastRow) { 124 fireTableChanged(new TableModelEvent(this, TableModelEvent.ALL_COLUMNS, firstRow, lastRow, TableModelEvent.UPDATE)); 125 } 126 127 131 public void fireTableStructureChanged() { 132 fireTableChanged(new TableModelEvent(this, TableModelEvent.ALL_COLUMNS, TableModelEvent.HEADER_ROW, 133 TableModelEvent.HEADER_ROW, TableModelEvent.STRUCTURE_CHANGED)); 134 } 135 136 141 public void fireTableChanged(TableModelEvent e) { 142 EventListener [] listeners = listenerList.getListeners(TableModelListener.class); 143 144 for (int index = 0; index < listeners.length; ++index) { 145 ((TableModelListener) listeners[index]).tableChanged(e); 146 } 147 } 148 149 154 public Class getColumnClass(int column) { 155 return Object .class; 156 } 157 158 164 public String getColumnName(int column) { 165 StringBuffer sb = new StringBuffer (); 166 int value = column; 167 do { 168 int digit = value % 26; 169 sb.insert(0, (char) ('A' + digit)); 170 value = value / 26 - 1; 171 } while (value >= 0); 172 173 return sb.toString(); 174 } 175 176 181 public EventListenerList getEventListenerList() { 182 return listenerList; 183 } 184 185 188 public void removeTableModelListener(TableModelListener l) { 189 listenerList.removeListener(TableModelListener.class, l); 190 } 191 } 192 | Popular Tags |