| java.lang.Object org.isqlviewer.util.LoggableObject org.isqlviewer.swing.table.EnhancedTableModel
All known Subclasses: org.isqlviewer.swing.table.ResultSetTableModel, org.isqlviewer.swing.table.PropertyTableModel,
EnhancedTableModel | public class EnhancedTableModel extends LoggableObject implements Cloneable,Sortable,TableModel,Transferable(Code) | | An enhanced rendition of the TableModel interface.
This implementation of the TableModel interface mainly address the lack of some column oriented methods, also i liked
some of the methods provided by the default DefaultTableModel like removeRow addRow, etc.
This is a fairly good table mode to use if you need a fast WORM type table model, i do not recommend using this class
if you have to make lots of changes since the data storage is only synchronized when it is set or removed and not
read.
author: Markus A. Kobold <mkobold at sprintpcs dot com> version: 1.0 |
Method Summary | |
protected void | addColumn(String name, Collection c) Adds a full column to underlying data collection.
This method will iterate through the given collection c, and for each row in the underlying data store, the item
is added to the each row. | public void | addRow(ArrayList<? extends Object> lst) This will add a row to this TableModel.
This method will clone the given ArrayList and then add that reference to underlying data collection. | public synchronized void | addTableModelListener(TableModelListener l) | public int | applyFilter(String text) | protected boolean | canSearchColumn(int column) | public boolean | canSort(int column, boolean ascending) | public void | clear() This will clear the table of all data. | public void | clearAll() This clears all data and column information for this table. | protected void | clearAllData() This is a helper method to clear all the data without firing a model event. | protected void | clearData() This is a helper method to clear the datastore without firing a model event. | public void | clearFilter() | public Object | clone() Creates a copy of this TableModel.
This method will not copy the existing TableModelListeners to the copied TableModel. | protected boolean | doFilter(Object data, Pattern pattern) | public int | findColumn(String columnName) Returns a column given its name. | public void | fireTableCellUpdated(int row, int column) Notifies all listeners that the value of the cell at [row, column] has been updated. | public void | fireTableChanged(TableModelEvent e) Forwards the given notification event to all TableModelListeners that registered themselves as
listeners for this table model. | public void | fireTableDataChanged() Notifies all listeners that all cell values in the table's rows may have changed. | public void | fireTableRowsDeleted(int firstRow, int lastRow) Notifies all listeners that rows in the range [firstRow, lastRow] , inclusive, have been deleted. | public void | fireTableRowsInserted(int firstRow, int lastRow) Notifies all listeners that rows in the range [firstRow, lastRow] , inclusive, have been inserted. | public void | fireTableRowsUpdated(int firstRow, int lastRow) Notifies all listeners that rows in the range [firstRow, lastRow] , inclusive, have been updated. | public void | fireTableStructureChanged() Notifies all listeners that the table's structure has changed. | public Class> | getColumnClass(int columnIndex) | public int | getColumnCount() | public String | getColumnName(int column) | public String[] | getColumns() | public int | getIndexOfColumnName(String name) | public int | getPageCount() Number of pages this model contains.
This will take the true row count divided by the page size. | public int | getPageOffset() | public int | getPageSize() Current paging size for this model. | protected ArrayList<Object> | getRow(int rowIndex) | public int | getRowCount() | public synchronized Map<String, Object> | getRowMap(int rowIndex) | public Object | getTransferData(DataFlavor flavor) | public DataFlavor[] | getTransferDataFlavors() | public int | getTrueRowCount() | public Object | getValueAt(int rowIndex, int columnIndex) | void | insertRow(int rowIndex, Map<String, Object> rowData) | public boolean | isCellEditable(int rowIndex, int columnIndex) | public boolean | isDataFlavorSupported(DataFlavor flavor) | public boolean | isEmpty() This will determine if there is data contained in this table.
This will return true if there is no data in the underlying data collection. | public boolean | matchesFilter(int rowIndex, int columnIndex) | public boolean | pageDown() Increases the page offset by one. | public boolean | pageUp() Decreases the page offset by one. | public void | removeColumn(int columnIndex) This will remove the desired column from this table model. | public void | removeRow(int rowIndex) Removes the specifed row at the given index. | public void | removeTableModelListener(TableModelListener l) | public void | setClassforColumn(int column, Class clazz) Sets the class type for the given column.
Explicitly declares that the given column is of type clazz, this method a complement to the getColumnClass(int)
method. | public void | setColumnCount(int size) Sets the column size of this table model for all rows.
This will add blanks strings if current column count is less than the given size other wise column items will be
removed to fit the given size.
For each row that doesn't meet the given column count an empty Object will be put in place. | public void | setColumnName(int idx, String name) Updates a column name at a given index.
This will replace the exisitng column name string with the given name at the specified index. | protected void | setColumns(String[] s) Replacing existing column information with the given array of Strings. | protected void | setData(Collection<ArrayList<Object>> c) This assumes a collection of ArrayLists as a way to add a multiple of table rows to the model. | public boolean | setPageSize(int newSize) Sets the current page size for this model. | public void | setRowCount(int size) This will ensure that the underlying data collection can hold the row count. | public void | setValueAt(Object aValue, int rowIndex, int columnIndex) | public void | sort(int column, boolean asc) | public EnhancedTableModel | subModel(int[] rows, int[] columnidxs) | public String | toString() | public int | translateRow(int rowIndex) |
FLAVOR_LOCAL_OBJECT | final public static DataFlavor FLAVOR_LOCAL_OBJECT(Code) | | Default transfer flavor as a java object.
|
FLAVOR_PLAIN_TEXT | final public static DataFlavor FLAVOR_PLAIN_TEXT(Code) | | Transfer flavor for representing plain text.
|
FLAVOR_REMOTE_OBJECT | final public static DataFlavor FLAVOR_REMOTE_OBJECT(Code) | | Default transfer flavor as a java object.
|
FLAVOR_TAB_STRINGS | final public static DataFlavor FLAVOR_TAB_STRINGS(Code) | | Transfer flavor for representing this as tab strings.
This data flavor seems to make DnD to native apps like Excel work.
|
classMappings | protected HashMap<Integer, Class> classMappings(Code) | | Mapping for column class by the column number.
This makes for easier explicit declarations of what class a column rather than based on what it is. This is
paticularly useful when used in conjuction of JTable that is basing a renderer on an interface class.
|
columns | protected ArrayList<String> columns(Code) | | This is the collection of column names required for the TableModel interface.
|
dataStore | protected ArrayList<ArrayList<Object>> dataStore(Code) | | The main data collection this should be an ArrayList where the elements are also ArrayLists.
|
listeners | protected transient ArrayList<TableModelListener> listeners(Code) | | A list of TableModel listeners this will be lazily created when a table model listener is required.
|
pageOffset | protected int pageOffset(Code) | | Current page offset for use in paging methods.
|
pageSize | protected int pageSize(Code) | | A marker to determine the number of rows per page.
|
EnhancedTableModel | public EnhancedTableModel(String[] columns)(Code) | | Creates an TableModel with the given column names.
Creates a table model with the following column names initially, The model will have no rows of any kind though.
This will also poll the SystemConfig object to automatically set the preferred paging size based on the
KEY_TABLE_PAGE_SIZE property key.
Parameters: columns - array of strings to be column names. |
addColumn | protected void addColumn(String name, Collection c)(Code) | | Adds a full column to underlying data collection.
This method will iterate through the given collection c, and for each row in the underlying data store, the item
is added to the each row. If the collection does not contain the correct number of items which should correspond
to the current number of rows, empty object will put in place.
This method will fire a TableStructureChanged() to model listeners.
Parameters: c - a collection of data representing a table column. Parameters: name - of the column represting this collection. |
addRow | public void addRow(ArrayList<? extends Object> lst)(Code) | | This will add a row to this TableModel.
This method will clone the given ArrayList and then add that reference to underlying data collection. If the
given ArrayList is null this method immediately returns.
There is no requirement for the size of the given list as long as it is >= to specified column size you should
not experience any erratic behaviour. So it is ok for the given ArrayList to have a size greater than this
TableModel Column size.
a fireRowsInserted() will be fired to model listeners.
Parameters: lst - Collection of objects to add as row to this table. |
canSearchColumn | protected boolean canSearchColumn(int column)(Code) | | |
canSort | public boolean canSort(int column, boolean ascending)(Code) | | |
clear | public void clear()(Code) | | This will clear the table of all data.
This method should not be confused with the clearAll() method, this will only clear the data, and not the column
information.
This will fire a TableDataChanged event to TableModel listeners.
See Also: EnhancedTableModel.clearAll() |
clearAll | public void clearAll()(Code) | | This clears all data and column information for this table.
This will fire a TableStructureChanged() when done and this table will be completely empty.
See Also: EnhancedTableModel.clear() |
clearAllData | protected void clearAllData()(Code) | | This is a helper method to clear all the data without firing a model event.
If you need to clear the data without sending a potentially misleading event extenders will want to use this
method versus the public clearAll.
See Also: EnhancedTableModel.clearAll() |
clearData | protected void clearData()(Code) | | This is a helper method to clear the datastore without firing a model event.
If you need to clear the data without sending a potentially misleading event extenders will want to use this
method versus the public clear.
See Also: EnhancedTableModel.clear() |
clearFilter | public void clearFilter()(Code) | | |
clone | public Object clone()(Code) | | Creates a copy of this TableModel.
This method will not copy the existing TableModelListeners to the copied TableModel. However all other members
values will copied and cloned.
See Also: java.lang.Object.clone |
findColumn | public int findColumn(String columnName)(Code) | | Returns a column given its name. Implementation is naive so this should be overridden if this method is to be
called often. This method is not in the TableModel interface and is not used by the
JTable .
Parameters: columnName - string containing name of column to be located the column with columnName , or -1 if not found |
fireTableCellUpdated | public void fireTableCellUpdated(int row, int column)(Code) | | Notifies all listeners that the value of the cell at [row, column] has been updated.
Parameters: row - row of cell which has been updated Parameters: column - column of cell which has been updated See Also: TableModelEvent |
fireTableDataChanged | public void fireTableDataChanged()(Code) | | Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also
have changed and the JTable should redraw the table from scratch. The structure of the table (as
in the order of the columns) is assumed to be the same.
See Also: TableModelEvent |
fireTableRowsDeleted | public void fireTableRowsDeleted(int firstRow, int lastRow)(Code) | | Notifies all listeners that rows in the range [firstRow, lastRow] , inclusive, have been deleted.
Parameters: firstRow - the first row Parameters: lastRow - the last row See Also: TableModelEvent |
fireTableRowsInserted | public void fireTableRowsInserted(int firstRow, int lastRow)(Code) | | Notifies all listeners that rows in the range [firstRow, lastRow] , inclusive, have been inserted.
Parameters: firstRow - the first row Parameters: lastRow - the last row See Also: TableModelEvent |
fireTableRowsUpdated | public void fireTableRowsUpdated(int firstRow, int lastRow)(Code) | | Notifies all listeners that rows in the range [firstRow, lastRow] , inclusive, have been updated.
Parameters: firstRow - the first row Parameters: lastRow - the last row See Also: TableModelEvent |
fireTableStructureChanged | public void fireTableStructureChanged()(Code) | | Notifies all listeners that the table's structure has changed. The number of columns in the table, and the names
and types of the new columns may be different from the previous state. If the JTable receives this
event and its autoCreateColumnsFromModel flag is set it discards any table columns that it had and
reallocates default columns in the order they appear in the model. This is the same as calling
setModel(TableModel) on the JTable .
See Also: TableModelEvent |
getIndexOfColumnName | public int getIndexOfColumnName(String name)(Code) | | See Also: org.isqlviewer.util.Sortable.getIndexOfColumnName(String) |
getPageCount | public int getPageCount()(Code) | | Number of pages this model contains.
This will take the true row count divided by the page size. the number returned will always be >= 1
See Also: EnhancedTableModel.setPageSize(int) int |
getPageOffset | public int getPageOffset()(Code) | | |
getPageSize | public int getPageSize()(Code) | | Current paging size for this model.
This the number of rows that determines a *page* this is the number of rows that will show in a JTable at a given
time.
See Also: EnhancedTableModel.getPageCount() int |
getTrueRowCount | public int getTrueRowCount()(Code) | | |
insertRow | void insertRow(int rowIndex, Map<String, Object> rowData)(Code) | | Parameters: rowAffected - Parameters: rowData - |
isDataFlavorSupported | public boolean isDataFlavorSupported(DataFlavor flavor)(Code) | | |
isEmpty | public boolean isEmpty()(Code) | | This will determine if there is data contained in this table.
This will return true if there is no data in the underlying data collection. the number of columns will not
affect the results of this methods returned value.
boolean to determine the emptiness of this tablemodel data. |
matchesFilter | public boolean matchesFilter(int rowIndex, int columnIndex)(Code) | | |
removeColumn | public void removeColumn(int columnIndex)(Code) | | This will remove the desired column from this table model.
This will also ensure that all the
Parameters: columnIndex - |
removeRow | public void removeRow(int rowIndex)(Code) | | Removes the specifed row at the given index.
This will remove the specified data declared at rowIndex, if the rowIndex is out of range this method will return
normally.
upon succesfull removal a fireTableRowsDeleted() will be notified to model listeners.
Parameters: rowIndex - the row to be removed from this table. |
setClassforColumn | public void setClassforColumn(int column, Class clazz)(Code) | | Sets the class type for the given column.
Explicitly declares that the given column is of type clazz, this method a complement to the getColumnClass(int)
method. This method can help when rendering this model correctly within a JTable. Paticularly if you have
configured a custom renderer on an interface class e.g. CLOB/BLOB. The JTable currently doesn't aquire the
correct renderer if an object is just an instance of something.
e.g.
Tablemodel mdl = new EnhancedTableModel();
JTable tab = new JTabel(mdl);
tab.setDefaultRenderer(Clob.class, new ClobRenderer());
mdl.addRow(new ArrayList(Arrays.asList(new MyCLOB[]{new MyClob()})));
Currently the JTable would not get the right render for the MyCLOB class even though it is an instanceof CLOB the
JTable will use the DefaultRenderer for the CLOB object.
mdl.setClassForColumn(0, Clob.class);
invocation will cause the JTable to get the Clob.class for column 0 and get the correct renderer for the object
within the model.
This will be the same effect on CellEditors as well since the JTable, uses similar logic
to aquire the appropriate editor
See Also: javax.swing.JTable.setDefaultRenderer(java.lang.Classjavax.swing.table.TableCellRenderer) See Also: EnhancedTableModel.getColumnClass(int) Parameters: column - id to declare it's class type for. Parameters: clazz - class type based on the column number. |
setColumnCount | public void setColumnCount(int size)(Code) | | Sets the column size of this table model for all rows.
This will add blanks strings if current column count is less than the given size other wise column items will be
removed to fit the given size.
For each row that doesn't meet the given column count an empty Object will be put in place. other wise each row
will be trimmed down to the given size.
This will fire a TableStructureChanged to model listeners.
Parameters: size - the new desired column count. |
setColumnName | public void setColumnName(int idx, String name)(Code) | | Updates a column name at a given index.
This will replace the exisitng column name string with the given name at the specified index. if the index is
invalid it will be silently ignored.
This will fire a TableStructedChanged() to model listeners.
Parameters: idx - the specidex column index to change Parameters: name - is the new column to use, can be null. |
setColumns | protected void setColumns(String[] s)(Code) | | Replacing existing column information with the given array of Strings.
This will clear all the exisiting column information and the new colum count will be the length of the given
String array.
If the given String[] is null a NullPointerException will most likely be thrown.
This will fire a TableStructureChanged() to model listeners.
Parameters: s - is the new set of Columns names for this model. |
setData | protected void setData(Collection<ArrayList<Object>> c)(Code) | | This assumes a collection of ArrayLists as a way to add a multiple of table rows to the model.
If the collection contains an object that cannot be type cast to an ArrayList then the object will be skipped, so
Vector and Stacks can be in the given collection since they are sub-class of the ArrayList.
Note this method does not mess with the column data information so if you are adding a bunch of rows, where the
column counts are off it won't show till you update the column information
This will fire a TableRowsInserted() for the number of ArrayLists actually added.
Parameters: c - is a collection of ArrayLists to be used as the data store for this model. |
setPageSize | public boolean setPageSize(int newSize)(Code) | | Sets the current page size for this model.
|
setRowCount | public void setRowCount(int size)(Code) | | This will ensure that the underlying data collection can hold the row count.
If the given size is less than the current size this will remove any extra rows to get this table model down to
the correct row count.
See Also: ArrayList.ensureCapacity(int) See Also: EnhancedTableModel.setColumnCount(int) Parameters: size - the new desire row count for this table model. |
sort | public void sort(int column, boolean asc)(Code) | | See Also: org.isqlviewer.util.Sortable.sort(intboolean) |
translateRow | public int translateRow(int rowIndex)(Code) | | |
|
|