JIDE 3.5.15

com.jidesoft.database
Class DatabaseTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.database.DatabaseTableModel
All Implemented Interfaces:
AutoFilterTableHeaderAdapter, AutoFilterTableModel, ContextSensitiveTableModel, IFilterableTableModel, ISortableTableModel, Serializable, TableModel
Direct Known Subclasses:
CrudDatabaseTableModel

public class DatabaseTableModel
extends AbstractTableModel
implements ISortableTableModel, IFilterableTableModel, ContextSensitiveTableModel

DatabaseTableModel uses an existing database connection and a SQL from statement to query the record from a database and display them in a table model. The from statement could has one database table or multiple database tables using join statement. The columns in this table model are decided by an optional SQL select statement you specified. If you didn't specify, we will use "*" which means all the available fields.

By default, we use ResultSet.TYPE_SCROLL_SENSITIVE to create a SQL statement to do the query. If your database doesn't support this, we will fall back to TYPE_INSENSITIVE then TYPE_FORWARD_ONLY. If so, the performance could be an issue when you scroll down many pages as we have to skip all records one by one. For

The main feature of this DatabaseTableModel is not just to display the database table but also to sort and filter the data using the built-in sort and filter features provided by the database, however, using the APIs provided by the SortableTableModel and FilterableTableModel provided in JIDE Grids. Usually you get a better performance using the database to do the sorting and filtering.

In DatabaseTableModel, we would try our best to set appropriate cell renderer by using the information from the ResultSetMetaData.

The folowing meta data information will be considered in ConverterContext:

 boolean isCurrency(int column) throws SQLException; // use default currency converter if isConsiderCurrencyField() returns true
 int getScale(int column) throws SQLException;       // show the digit number after decimal point
 int getPrecision(int column) throws SQLException;   // show the integer part no larger than precision
 

The following meta data information will be considered in validate(int, Object):

 int isNullable(int column) throws SQLException;     // check it in validateNullable(int, Object)
 boolean isSigned(int column) throws SQLException;   // check it in validateSigned(int, Object)
 int getPrecision(int column) throws SQLException;   // check it in validatePrecision(int, Object)
 

Other:

 boolean isReadOnly(int column) throws SQLException; // make it not editable in isCellEditable(int, int)
 
The following meta data information will not be considered:
 int getColumnDisplaySize(int column) throws SQLException; // no way to set preferred width to table from table model
 int getColumnCount() throws SQLException;
 boolean isAutoIncrement(int column) throws SQLException;
 boolean isSearchable(int column) throws SQLException;
 String getColumnLabel(int column) throws SQLException;
 String getColumnName(int column) throws SQLException;
 String getSchemaName(int column) throws SQLException;
 String getTableName(int column) throws SQLException;
 String getCatalogName(int column) throws SQLException;
 int getColumnType(int column) throws SQLException;
 String getColumnTypeName(int column) throws SQLException;
 String getColumnClassName(int column) throws SQLException;
 boolean isWritable(int column) throws SQLException; // it's database access related
 boolean isDefinitelyWritable(int column) throws SQLException; // it's database access related
 boolean isCaseSensitive(int column) throws SQLException; // searching case sensitive
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.jidesoft.grid.ISortableTableModel
ISortableTableModel.SortItem
 
Nested classes/interfaces inherited from interface com.jidesoft.grid.IFilterableTableModel
IFilterableTableModel.FilterItem
 
Nested classes/interfaces inherited from interface com.jidesoft.grid.AutoFilterTableHeaderAdapter
AutoFilterTableHeaderAdapter.FilterTitleFormatter
 
Field Summary
protected  Connection _connection
           
protected  ConverterContext[] _converterContexts
          converter context for columns which was configured on refreshData(com.jidesoft.grid.SortItemSupport, com.jidesoft.grid.FilterItemSupport)

After configuration, this field will be used at getConverterContextAt(int, int)

You can either override getConverterContextAt(int, int) or configureConverterContexts() to gain more control on the cell renderers.

protected  FilterItemSupport _filterItemSupport
           
protected  String _fromStatement
           
protected  String _preStatement
           
protected  ResultSetTableModel _resultSetTableModel
           
protected  String _selectStatement
           
protected  SortItemSupport _sortItemSupport
           
protected  Statement _statement
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.grid.ISortableTableModel
SORT_PRIORITY_FIFO, SORT_PRIORITY_FILO
 
Fields inherited from interface com.jidesoft.grid.IFilterableTableModel
ALL_COLUMNS, ANY_COLUMNS, IDENTIFIER_ALL_COLUMNS, IDENTIFIER_ANY_COLUMNS
 
Constructor Summary
DatabaseTableModel(Connection connection, String fromStatement)
          Creates a DatabaseTableModel.
DatabaseTableModel(Connection connection, String selectStatement, String fromStatement)
          Creates a DatabaseTableModel.
DatabaseTableModel(Connection connection, String selectStatement, String fromStatement, boolean updatable)
          Creates a DatabaseTableModel.
DatabaseTableModel(Connection connection, String preStatement, String selectStatement, String fromStatement)
          Creates a DatabaseTableModel.
DatabaseTableModel(Connection connection, String preStatement, String selectStatement, String fromStatement, boolean updatable)
          Creates a DatabaseTableModel.
 
Method Summary
 void addFilter(Filter filter)
          Adds a filter to all columns.
 void addFilter(IFilterableTableModel.FilterItem filterItem)
          Adds a FilterItem.
 void addFilter(int column, Filter filter)
          Adds a filter to the specified column.
 void addFilterableTableModelListener(FilterableTableModelListener l)
          Adds a listener to the list that's notified each time a change to the filter occurs.
 void addSortListener(SortListener l)
          Adds the specified listener to receive SortEvents pane events from this SortableTableModel.
protected  Statement adjustStatement(Statement statement, String sql)
          This method is called before every single sql queries to give subclass a chance to override to create their own statement.
 void clearFilters()
          Removes all filters from all columns.
 void close()
           
 void commit()
           
protected  void configureConverterContexts()
          Configure converter context for columns by the information contained in meta data.
protected  String convertElementToString(Filter filter, Object value)
          Converts the value defined in the filter to String so that it can be used in SQL.
protected  String createCountStatement(FilterItemSupport filterItemSupport)
          Creates the sql statement to find out the row count in the result set.
protected  String createOrderStatement(SortItemSupport sortItemSupport)
          Create order statement from sort item support.
protected  String createPossibleValuesStatement(int columnIndex)
           
protected  Statement createReadonlyStatement()
          Creates a read-only statement.
protected  ResultSetTableModel createResultSetTableModel(ResultSet resultSet, int rowCount)
           
protected  StringBuffer createSqlStatement(String preStatement, String selectStatement, String fromStatement, SortItemSupport sortItemSupport, FilterItemSupport filterItemSupport)
          Creates a full SQL statement.
protected  Statement createStatement()
          Creates a Statement.
protected  String createWhereStatement(FilterItemSupport filterItemSupport)
           
 void fireFilterAdded(int column, Filter filter)
           
 void fireFilterChanged(FilterableTableModelEvent e)
          Forwards the given notification event to all FilterableTableModelListeners that registered themselves as listeners for this table model.
 void fireFilterRemoved(int column, Filter filter)
           
 void fireSortEvent()
          Fires sort event.
 void fireSortingEvent()
          Fires sort event.
 int getActualRowAt(int row)
          Gets the actual row.
 Class<?> getCellClassAt(int rowIndex, int columnIndex)
          Gets the type at cell (row, column).
 Class<?> getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 Map<String,String> getColumnMapping()
           
 String getColumnName(int column)
           
 int getColumnSortRank(int column)
          In the case of sort by multiple columns, this method will return the rank of this column within all sorted columns.
 ConverterContext getConverterContextAt(int rowIndex, int columnIndex)
          Gets the converter context at cell (row, column).
 DynamicTableFilter[] getDynamicTableFilters(int modelIndex)
          Gets all the DynamicTableFilters.
 EditorContext getEditorContextAt(int rowIndex, int columnIndex)
          Gets the editor context at cell (row, column).
 FilterableTableModelListener[] getFilterableTableModelListeners()
          Returns an array of all the FilterableTableModel listeners registered on this filter.
 Icon getFilterIcon(int column)
          Gets the filter icon for a particular column.
 List<IFilterableTableModel.FilterItem> getFilterItems()
          Gets all the FilterItems added to this FilterableTableModel.
 Filter[] getFilters(int column)
          Gets the filters for the specified column.
 AutoFilterTableHeaderAdapter.FilterTitleFormatter getFilterTitleFormatter(int column)
          Gets the formatter that will format the title for the AutoFilterTableHeader.
 ListCellRenderer getListCellRenderer(int column)
          Gets the list cell renderer for the drop down filter list.
 int[] getMasterSortColumns()
          Gets the master sort columns.
 int getMaximumSortColumns()
          Gets the maximum columns can be sorted at once.
 Object[] getPossibleValues(int columnIndex, Comparator comparator)
          Gets all possible values of the table model.
 Object[] getPossibleValuesAndConverters(int columnIndex, Comparator comparator)
           
 int getRowCount()
           
 int getSortedRowAt(int actualRow)
          Gets the visual row.
 List<ISortableTableModel.SortItem> getSortingColumns()
          Gets the sorting columns.
 SortListener[] getSortListeners()
          Returns an array of all the SortListeners added to this SortableTableModel with addSortListener.
 int getSortPriority()
          Gets the sort priority.
 StringConverter getTitleConverter(int column)
          Gets the title converter to convert the column name.
 Object getValueAt(int rowIndex, int columnIndex)
           
 boolean hasFilter()
          Checks if the FilterableTableModel has any filters.
 boolean hasFilter(int columnIndex)
          Checks if the FilterableTableModel has any filters on the specified column.
protected  void initDatabase()
           
 void invalidateCache()
           
 void invalidateCache(int row)
           
 boolean isAdjusting()
          Checks if the FilterableTableModel is adjusting.
 boolean isAllowCustomFilter(int column)
          Checks if the AutoFilterTableHeader allows custom filter.
 boolean isAllowMultipleValues(int column)
          Checks if the AutoFilterTableHeader allows multiple values as the filter for the column index.
 boolean isAndMode()
          Sets the logic of filters on the same column.
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 boolean isColumnAscending(int column)
          Checks if the column is sorted ascendingly.
 boolean isColumnAutoFilterable(int column)
          Checks if the column is auto-filterable.
 boolean isColumnFilterable(int column)
          Checks if the column is filterable for the filters that are added to IFilterableTableModel.ALL_COLUMNS.
 boolean isColumnSortable(int column)
          Check if a certain column is sortable.
 boolean isColumnSorted(int column)
          Checks if the column is sorted.
 boolean isColumnVisible(int column)
          Checks if the column is visible.
 boolean isConsiderCurrencyField()
          Get the flag if you want to consider the isCurrency field in metaData.
 boolean isFilteringPaused()
          Not supported in DatabaseTableModel.
 boolean isFiltersApplied()
          Checks if the filters are in effect.
 boolean isMultiColumnSortable()
          Does this table allow sort by multiple columns.
 boolean isSameConverterAt(int columnIndex)
          Check if each converter in this column for each row is the same.
 boolean isSortable()
          Checks if the sortable table model is sortable.
 boolean isUpdatable()
           
 boolean isUseTableCellRenderer(int column)
          Checks if the table cell renderer will be used for the list.
 boolean isValuePredetermined(int column)
          Checks if the column is type-filterable.
protected  StringBuffer prepareWhereStatement(IFilterableTableModel.FilterItem filterItem)
          Convert the existing filter to where statement string.
 void refresh()
          Reapply all filters after they are changed.
 void refreshData(SortItemSupport sortItemSupport, FilterItemSupport filterItemSupport)
          Resubmit the SQL statement.
 void removeAllFilters()
          Removes all filters that are added using IFilterableTableModel.addFilter(Filter).
 void removeAllFilters(int column)
          Removes all filters from the specified column.
 void removeFilter(Filter filter)
          Removes the filter from all columns.
 void removeFilter(IFilterableTableModel.FilterItem filterItem)
          Removes the filter item.
 void removeFilter(int column, Filter filter)
          Removes the filter from the specified column.
 void removeFilterableTableModelListener(FilterableTableModelListener l)
          Removes a listener from the list that's notified each time a change to the filter occurs.
 void removeSortListener(SortListener l)
          Removes the specified SortListener so that it no longer receives SortEvents from this SortableTableModel .
 void reset()
          Resets.
 void resort()
          Resort the table.
 void reverseColumnSortOrder(int column)
          Reverses the sort order of the column.
 void setAdjusting(boolean adjusting)
          Sets the FilterableTableModel to adjusting mode.
 void setAndMode(boolean andMode)
          Sets the logic among the filters.
 void setColumnMapping(Map<String,String> columnMapping)
          Sets the column name mapping.
 void setColumnSortable(int column, boolean sortable)
          Sets a column sortable or not sortable.
 void setConsiderCurrencyField(boolean considerCurrencyField)
          Set the flag if you want to consider the isCurrency field in metaData.
 void setFilteringPaused(boolean pause)
          Not supported in DatabaseTableModel.
 void setFiltersApplied(boolean apply)
          Applies or unapplies the filters.
 void setMasterSortColumns(int[] masterSortColumns)
          Sets the master sort column.
 void setMaximumSortColumns(int maximumSortColumns)
          Set the maximum number of columns that can be sorted at once.
 void setMultiColumnSortable(boolean multiColumnSortable)
          Set the value if this table allows sort by multiple columns.
 void setSortable(boolean sortable)
          Sets the table model sortable.
 void setSortingColumns(List<ISortableTableModel.SortItem> list)
          Sets the soring columns.
 void setSortPriority(int sortPriority)
          Sets the sort priority.
 void setUpdatable(boolean updatable)
           
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
           
protected  void sort()
           
 void sortColumn(int column)
          Sort the column, equals to sortColumn(column, false).
 void sortColumn(int column, boolean reset)
          If reset is true, it will remove all existing sort-by columns and only sorts by column.
 void sortColumn(int column, boolean reset, boolean ascending)
          Sorts a column.
 void toggleSortOrder(int column, boolean extend)
          Toggles the sort order on the specified column.
 void unsortColumn(int column)
          Unsorts the column.
 boolean validate(int columnIndex, Object value)
          The interface for the table to check if the input value satisfy the request from the meta data of the database.
 boolean validateNullable(int columnIndex, Object value)
          The interface for the table to check if the input value is null and meta data prohibits null value.
 boolean validatePrecision(int columnIndex, Object value)
          The interface for the table to check if the input value exceeds the precision meta data allows.
 boolean validateSigned(int columnIndex, Object value)
          The interface for the table to check if the input value is negative and meta data prohibits negative value.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

_resultSetTableModel

protected ResultSetTableModel _resultSetTableModel

_connection

protected Connection _connection

_statement

protected Statement _statement

_fromStatement

protected String _fromStatement

_selectStatement

protected String _selectStatement

_preStatement

protected String _preStatement

_converterContexts

protected ConverterContext[] _converterContexts
converter context for columns which was configured on refreshData(com.jidesoft.grid.SortItemSupport, com.jidesoft.grid.FilterItemSupport)

After configuration, this field will be used at getConverterContextAt(int, int)

You can either override getConverterContextAt(int, int) or configureConverterContexts() to gain more control on the cell renderers.


_sortItemSupport

protected SortItemSupport _sortItemSupport

_filterItemSupport

protected FilterItemSupport _filterItemSupport
Constructor Detail

DatabaseTableModel

public DatabaseTableModel(Connection connection,
                          String fromStatement)
                   throws SQLException
Creates a DatabaseTableModel.

Parameters:
connection - a database connection.
fromStatement - a SQL from statement. It could be
  • FROM first_table
  • FROM first_table, second_table
  • FROM first_table LEFT JOIN second_table
  • FROM first_table INNER JOIN second_table
Throws:
SQLException - if a database related error happens. It could be because the connection is closed.

DatabaseTableModel

public DatabaseTableModel(Connection connection,
                          String selectStatement,
                          String fromStatement)
                   throws SQLException
Creates a DatabaseTableModel.

Parameters:
connection - a database connection.
selectStatement - a SQL select statement. If null, we default it to "*". If you use AS statement to change the column name, make sure you also call setColumnMapping(java.util.Map) to set the mapping.
fromStatement - a SQL from statement. It could be
  • FROM first_table
  • FROM first_table, second_table
  • FROM first_table LEFT JOIN second_table
  • FROM first_table INNER JOIN second_table
Throws:
SQLException - if a database related error happens. It could be because the connection is closed.

DatabaseTableModel

public DatabaseTableModel(Connection connection,
                          String preStatement,
                          String selectStatement,
                          String fromStatement)
                   throws SQLException
Creates a DatabaseTableModel.

Parameters:
connection - a database connection.
preStatement - a pre-clause. It will appear at the beginning of all sql statements. For example, WITH abc as ( select dummy from dual ) select * from abc. "WITH abc as ( select dummy from dual )" will be the pre statement. "abc" will be the from statement.
selectStatement - a SQL SELECT statement. Do not include the SELECT word in the statement. Just include everything after the SELECT. If null, we default it to "*". If you use AS statement to change the column name, make sure you also call setColumnMapping(java.util.Map) to set the mapping.
fromStatement - a SQL FROM clause. Do not include the FROM word in the statement. Just include everything after the FROM. It could be
  • FROM first_table
  • FROM first_table, second_table
  • FROM first_table LEFT JOIN second_table
  • FROM first_table INNER JOIN second_table
Throws:
SQLException - if a database related error happens. It could be because the connection is closed.

DatabaseTableModel

public DatabaseTableModel(Connection connection,
                          String selectStatement,
                          String fromStatement,
                          boolean updatable)
                   throws SQLException
Creates a DatabaseTableModel.

Parameters:
connection - a database connection.
selectStatement - a SQL SELECT statement. Do not include the SELECT word in the statement. Just include everything after the SELECT. If null, we default it to "*". If you use AS statement to change the column name, make sure you also call setColumnMapping(java.util.Map) to set the mapping.
fromStatement - a SQL FROM clause. Do not include the FROM word in the statement. Just include everything after the FROM. It could be
  • FROM first_table
  • FROM first_table, second_table
  • FROM first_table LEFT JOIN second_table
  • FROM first_table INNER JOIN second_table
updatable - if the table model is updatable (or editable)
Throws:
SQLException - if a database related error happens. It could be because the connection is closed.

DatabaseTableModel

public DatabaseTableModel(Connection connection,
                          String preStatement,
                          String selectStatement,
                          String fromStatement,
                          boolean updatable)
                   throws SQLException
Creates a DatabaseTableModel.

Parameters:
connection - a database connection.
preStatement - a pre-clause. It will appear at the beginning of all sql statements. For example, WITH abc as ( select dummy from dual ) select * from abc. "WITH abc as ( select dummy from dual )" will be the pre statement. "abc" will be the from statement.
selectStatement - a SQL SELECT statement. Do not include the SELECT word in the statement. Just include everything after the SELECT. If null, we default it to "*". If you use AS statement to change the column name, make sure you also call setColumnMapping(java.util.Map) to set the mapping.
fromStatement - a SQL FROM clause. Do not include the FROM word in the statement. Just include everything after the FROM. It could be
  • FROM first_table
  • FROM first_table, second_table
  • FROM first_table LEFT JOIN second_table
  • FROM first_table INNER JOIN second_table
updatable - if the table model is updatable (or editable)
Throws:
SQLException - if a database related error happens. It could be because the connection is closed.
Method Detail

initDatabase

protected void initDatabase()
                     throws SQLException
Throws:
SQLException

setColumnMapping

public void setColumnMapping(Map<String,String> columnMapping)
Sets the column name mapping. It maps from the new column name to the original column name as specified in the SQL select statement. For example if the select statement is "ID, CategoryName as Category, ProductName as Product, Amount, OrderDate as Date", the mapping will be like this.
 Map mapping = new HashMap();
 mapping.put("CATEGORYNAME", "CATEGORY");
 mapping.put("PRODUCTNAME", "PRODUCT");
 mapping.put("ORDERDATE", "DATE");
 
Please note it has to be all upper cases.

Parameters:
columnMapping - the column name mapping.

getColumnMapping

public Map<String,String> getColumnMapping()

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getConverterContextAt

public ConverterContext getConverterContextAt(int rowIndex,
                                              int columnIndex)
Description copied from interface: ContextSensitiveTableModel
Gets the converter context at cell (row, column).

For a special row index like -1, please return the default converter context for the entire column if there is any.

Specified by:
getConverterContextAt in interface ContextSensitiveTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
converter context

getEditorContextAt

public EditorContext getEditorContextAt(int rowIndex,
                                        int columnIndex)
Description copied from interface: ContextSensitiveTableModel
Gets the editor context at cell (row, column).

For a special row index like -1, please return the default editor context for the entire column if there is any.

Specified by:
getEditorContextAt in interface ContextSensitiveTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
editor context

getCellClassAt

public Class<?> getCellClassAt(int rowIndex,
                               int columnIndex)
Description copied from interface: ContextSensitiveTableModel
Gets the type at cell (row, column).

For a special row index like -1, please return the default column class for the entire column if there is any.

Specified by:
getCellClassAt in interface ContextSensitiveTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
type

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Specified by:
getValueAt in interface TableModel

getSortedRowAt

public int getSortedRowAt(int actualRow)
Description copied from interface: ISortableTableModel
Gets the visual row.

Specified by:
getSortedRowAt in interface ISortableTableModel
Parameters:
actualRow - the actual row in actual model.
Returns:
the row on UI. -1 if cannot find the row.

getActualRowAt

public int getActualRowAt(int row)
Description copied from interface: ISortableTableModel
Gets the actual row.

Specified by:
getActualRowAt in interface ISortableTableModel
Parameters:
row - the row on the UI.
Returns:
the actual row in the actual model. It will throw IllegalArgumentException if the row is out of range.

sortColumn

public void sortColumn(int column)
Description copied from interface: ISortableTableModel
Sort the column, equals to sortColumn(column, false).

Specified by:
sortColumn in interface ISortableTableModel
Parameters:
column - column to be sorted

sortColumn

public void sortColumn(int column,
                       boolean reset)
Description copied from interface: ISortableTableModel
If reset is true, it will remove all existing sort-by columns and only sorts by column. If reset is false, it will keep existing sort-by columns and add the column as a new sort-by column.

Specified by:
sortColumn in interface ISortableTableModel
Parameters:
column - the column index.
reset - true to reset all existing sorting columns before sorting the new column.

unsortColumn

public void unsortColumn(int column)
Description copied from interface: ISortableTableModel
Unsorts the column.

Specified by:
unsortColumn in interface ISortableTableModel
Parameters:
column - column to be removed from sort-by columns

reverseColumnSortOrder

public void reverseColumnSortOrder(int column)
Description copied from interface: ISortableTableModel
Reverses the sort order of the column. The column must be one of sorted column, or else the method will do nothing

Specified by:
reverseColumnSortOrder in interface ISortableTableModel
Parameters:
column - the column index.

sortColumn

public void sortColumn(int column,
                       boolean reset,
                       boolean ascending)
Description copied from interface: ISortableTableModel
Sorts a column.

Specified by:
sortColumn in interface ISortableTableModel
Parameters:
column - the column index.
reset - true to reset all existing sorting columns before sorting the new column.
ascending - true to sort ascending. False to sort descending.

isColumnSorted

public boolean isColumnSorted(int column)
Description copied from interface: ISortableTableModel
Checks if the column is sorted.

Specified by:
isColumnSorted in interface ISortableTableModel
Parameters:
column - the column index.
Returns:
true if the column is sorted.

isColumnAscending

public boolean isColumnAscending(int column)
Description copied from interface: ISortableTableModel
Checks if the column is sorted ascendingly.

Specified by:
isColumnAscending in interface ISortableTableModel
Parameters:
column - the column index.
Returns:
true if column is ascendingly sorted. If it's not sorted or sorted but descending, it will return false.

reset

public void reset()
Description copied from interface: ISortableTableModel
Resets. No columns will be sorted. Nothing will be done if the model was not sorted.

Specified by:
reset in interface ISortableTableModel

toggleSortOrder

public void toggleSortOrder(int column,
                            boolean extend)
Description copied from interface: ISortableTableModel
Toggles the sort order on the specified column. By default, it will sort the column if not sorted. If sorted ascending, it will change to descending. If descending, it will unsort.

Specified by:
toggleSortOrder in interface ISortableTableModel
Parameters:
column - the column index.
extend - if true, extend the current sort to add more sorted columns.

getSortingColumns

public List<ISortableTableModel.SortItem> getSortingColumns()
Description copied from interface: ISortableTableModel
Gets the sorting columns. It's a ArrayList. The element in the list is SortItem which has the column index and sorting direction.

Specified by:
getSortingColumns in interface ISortableTableModel
Returns:
an ArrayList of sorting columns.

setSortingColumns

public void setSortingColumns(List<ISortableTableModel.SortItem> list)
Description copied from interface: ISortableTableModel
Sets the soring columns. It will do a sort action automatically.

Specified by:
setSortingColumns in interface ISortableTableModel
Parameters:
list - a list of SortItems.

getColumnSortRank

public int getColumnSortRank(int column)
Description copied from interface: ISortableTableModel
In the case of sort by multiple columns, this method will return the rank of this column within all sorted columns.

Specified by:
getColumnSortRank in interface ISortableTableModel
Parameters:
column - the column index.
Returns:
the rank of this column within all sorted columns. -1 is the column is not sorted. 0 means the first rank and so on.

setMasterSortColumns

public void setMasterSortColumns(int[] masterSortColumns)
Description copied from interface: ISortableTableModel
Sets the master sort column. If the master sort columns are set, the row order will only be changed when the master sort columns have the same value. This is used when there are cell spans in certain column and you don't want the sorting to mess up the cell span as those rows will have to stay together.

Specified by:
setMasterSortColumns in interface ISortableTableModel
Parameters:
masterSortColumns - the new master sort columns.

getMasterSortColumns

public int[] getMasterSortColumns()
Description copied from interface: ISortableTableModel
Gets the master sort columns.

Specified by:
getMasterSortColumns in interface ISortableTableModel
Returns:
the master sort columns.

isMultiColumnSortable

public boolean isMultiColumnSortable()
Description copied from interface: ISortableTableModel
Does this table allow sort by multiple columns.

Specified by:
isMultiColumnSortable in interface ISortableTableModel
Returns:
true if this table allows sort by multiple columns

setMultiColumnSortable

public void setMultiColumnSortable(boolean multiColumnSortable)
Description copied from interface: ISortableTableModel
Set the value if this table allows sort by multiple columns.

Specified by:
setMultiColumnSortable in interface ISortableTableModel
Parameters:
multiColumnSortable - pass in true if this you want this table allows sort by multiple columns

isSortable

public boolean isSortable()
Description copied from interface: ISortableTableModel
Checks if the sortable table model is sortable.

Specified by:
isSortable in interface ISortableTableModel
Returns:
true or false.

setSortable

public void setSortable(boolean sortable)
Description copied from interface: ISortableTableModel
Sets the table model sortable. If the model is not sortable, ISortableTableModel.toggleSortOrder(int,boolean) will have no effect.

Specified by:
setSortable in interface ISortableTableModel
Parameters:
sortable - true or false.

resort

public void resort()
Description copied from interface: ISortableTableModel
Resort the table. When autoResort is false, the table will be out of order after data changes. The method will resort the table while keeping the sorting columns.

Specified by:
resort in interface ISortableTableModel

getSortPriority

public int getSortPriority()
Description copied from interface: ISortableTableModel
Gets the sort priority.

Specified by:
getSortPriority in interface ISortableTableModel
Returns:
the sort priority. It could be either ISortableTableModel.SORT_PRIORITY_FILO (the default) or ISortableTableModel.SORT_PRIORITY_FIFO.

setSortPriority

public void setSortPriority(int sortPriority)
Description copied from interface: ISortableTableModel
Sets the sort priority. This property only has effect when multiple columns are sorted. When sort priority is FILO (first-in-last-out), the first sorted column has the smallest sort rank (with a number "1" on its column header). If there are more columns being sorted, their sort tank are getting higher based on the the order when they are sorted. Oppositely, when sort priority is FIFO (first-in-first-out), the first sorted column has the sort rank 1. But the moment a new column is sorted, it will get sort rank 1 and push the previous sorted column's sort rank to 2. And so on. If you view it as a queue, you will see it's either a FILO queue or FIFO queue. That's why we call it FIFO or FILO.

Specified by:
setSortPriority in interface ISortableTableModel
Parameters:
sortPriority - must be one the following value: SORT_PRIORITY_FILO (the default), or SORT_PRIORITY_FIFO

getMaximumSortColumns

public int getMaximumSortColumns()
Description copied from interface: ISortableTableModel
Gets the maximum columns can be sorted at once. If user tries to sort another columns when maximum count is met, depending on the value of ISortableTableModel.getSortPriority(), the behavior is different. If sort priority is FILO, nothing will happen when user tries to sort one column. If FIFO, it will push the column with the largest sort rank out.

Specified by:
getMaximumSortColumns in interface ISortableTableModel
Returns:
the maximum sorted column number.

setMaximumSortColumns

public void setMaximumSortColumns(int maximumSortColumns)
Description copied from interface: ISortableTableModel
Set the maximum number of columns that can be sorted at once.

Specified by:
setMaximumSortColumns in interface ISortableTableModel
Parameters:
maximumSortColumns - the maximum number of columns that can be sorted at once.

addSortListener

public void addSortListener(SortListener l)
Adds the specified listener to receive SortEvents pane events from this SortableTableModel.

Specified by:
addSortListener in interface ISortableTableModel
Parameters:
l - the SortListener

removeSortListener

public void removeSortListener(SortListener l)
Removes the specified SortListener so that it no longer receives SortEvents from this SortableTableModel .

Specified by:
removeSortListener in interface ISortableTableModel
Parameters:
l - the SortableTableModel listener

getSortListeners

public SortListener[] getSortListeners()
Returns an array of all the SortListeners added to this SortableTableModel with addSortListener.

Specified by:
getSortListeners in interface ISortableTableModel
Returns:
all of the SortListeners added or an empty array if no listeners have been added
See Also:
addSortListener(com.jidesoft.grid.SortListener)

fireSortEvent

public void fireSortEvent()
Fires sort event.


fireSortingEvent

public void fireSortingEvent()
Fires sort event.


isColumnSortable

public boolean isColumnSortable(int column)
Check if a certain column is sortable.

Specified by:
isColumnSortable in interface ISortableTableModel
Parameters:
column - the column index.
Returns:
true if this table column is sortable.
See Also:
setColumnSortable(int, boolean)

setColumnSortable

public void setColumnSortable(int column,
                              boolean sortable)
Sets a column sortable or not sortable. Please note, you will have to set it again if the table model structure is changed. By default, all columns are sortable.

Specified by:
setColumnSortable in interface ISortableTableModel
Parameters:
column - the column index.
sortable - true to make the column sortable.

sort

protected void sort()

createOrderStatement

protected String createOrderStatement(SortItemSupport sortItemSupport)
Create order statement from sort item support.

Parameters:
sortItemSupport - the sorting information stored in sortItemSupport
Returns:
the order statement string. null if there is no sorting at all.

prepareWhereStatement

protected StringBuffer prepareWhereStatement(IFilterableTableModel.FilterItem filterItem)
Convert the existing filter to where statement string.

We now convert the following filter types to where statement string. Will return an empty string for other filter types. OrFilter AndFilter NotFilter LikeFilter EqualFilter BetweenFilter InFilter SingleValueFilter MultipleValuesFilter

Parameters:
filterItem - the filter item to convert
Returns:
the where statement string.

convertElementToString

protected String convertElementToString(Filter filter,
                                        Object value)
Converts the value defined in the filter to String so that it can be used in SQL. By default, we will put a single quote around the string if the value is String or Date type.

Parameters:
filter - the filter where the value is from.
value - the value
Returns:
a String representing the value.

refresh

public void refresh()
Description copied from interface: IFilterableTableModel
Reapply all filters after they are changed.

Specified by:
refresh in interface IFilterableTableModel

createWhereStatement

protected String createWhereStatement(FilterItemSupport filterItemSupport)

isColumnFilterable

public boolean isColumnFilterable(int column)
Description copied from interface: IFilterableTableModel
Checks if the column is filterable for the filters that are added to IFilterableTableModel.ALL_COLUMNS. The column will be excluded if it returns false (same as IFilterableTableModel.isColumnVisible(int) in this case. There is also AutoFilterTableHeaderAdapter.isColumnAutoFilterable(int) which is used for AutoFilterHeader to control if the filter button is visible.

Specified by:
isColumnFilterable in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
true if the column can be filtered.

isColumnVisible

public boolean isColumnVisible(int column)
Description copied from interface: IFilterableTableModel
Checks if the column is visible. Since column visible information is on the JTable, FilterableTableModel has no idea whether a column is visible. So we added this protected method to give user a chance to tell FilterableTableModel whether a column is visible. If it is not visible, it will not be considered when filtering.

Specified by:
isColumnVisible in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
true if the column is visible. Otherwise false.

isColumnAutoFilterable

public boolean isColumnAutoFilterable(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the column is auto-filterable. Please note, this is used in AutoFilterHeader. If it returns false, we will not show the filter button on the header for that column.

Specified by:
isColumnAutoFilterable in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true if the column can be filtered.

isValuePredetermined

public boolean isValuePredetermined(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the column is type-filterable. Please note, this is used in AutoFilterHeader at multiple line mode. If it returns false, we will not show the filter field on the header for that column.

Specified by:
isValuePredetermined in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true if the column can be filtered.

addFilter

public void addFilter(int column,
                      Filter filter)
Description copied from interface: IFilterableTableModel
Adds a filter to the specified column.

Specified by:
addFilter in interface IFilterableTableModel
Parameters:
column - the column index. It could also be two special values - IFilterableTableModel.ALL_COLUMNS or IFilterableTableModel.ANY_COLUMNS. If the value is IFilterableTableModel.ANY_COLUMNS, this method will be the same as IFilterableTableModel.addFilter(Filter).
filter - the filter to be added.

addFilter

public void addFilter(Filter filter)
Description copied from interface: IFilterableTableModel
Adds a filter to all columns. if one of the columns matches the filter, the row will be not be filtered.

You can use AbstractFilter to create new filter. If you need the row index or column index in order to decide if the value should be filtered, you can use AbstractTableFilter and use getRowIndex() and getColumnInde() to find out current row or column index.

Please note, addFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
addFilter in interface IFilterableTableModel
Parameters:
filter - the filter to be added.

addFilter

public void addFilter(IFilterableTableModel.FilterItem filterItem)
Description copied from interface: IFilterableTableModel
Adds a FilterItem.

Specified by:
addFilter in interface IFilterableTableModel
Parameters:
filterItem - the FilterItem

removeFilter

public void removeFilter(int column,
                         Filter filter)
Description copied from interface: IFilterableTableModel
Removes the filter from the specified column. The filter must be added using IFilterableTableModel.addFilter(int, Filter).

Please note, removeFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
removeFilter in interface IFilterableTableModel
Parameters:
column - the column index. It could also be two special values - IFilterableTableModel.ALL_COLUMNS or IFilterableTableModel.ANY_COLUMNS. If the value is IFilterableTableModel.ANY_COLUMNS, this method will be the same as IFilterableTableModel.removeFilter(Filter).
filter - the filter to be removed.

removeFilter

public void removeFilter(Filter filter)
Description copied from interface: IFilterableTableModel
Removes the filter from all columns. The filter must be added using IFilterableTableModel.addFilter(Filter).

Please note, removeFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
removeFilter in interface IFilterableTableModel
Parameters:
filter - the filter to be removed.

removeFilter

public void removeFilter(IFilterableTableModel.FilterItem filterItem)
Description copied from interface: IFilterableTableModel
Removes the filter item.

Please note, removeFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
removeFilter in interface IFilterableTableModel
Parameters:
filterItem - the FilterItem to be removed.

removeAllFilters

public void removeAllFilters(int column)
Description copied from interface: IFilterableTableModel
Removes all filters from the specified column. Those filters are added using IFilterableTableModel.addFilter(int, Filter).

Please note, removeAllFilters will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
removeAllFilters in interface IFilterableTableModel
Parameters:
column - the column index where all filters for that column should be removed.

removeAllFilters

public void removeAllFilters()
Description copied from interface: IFilterableTableModel
Removes all filters that are added using IFilterableTableModel.addFilter(Filter). If you want to remove all filters that either added using IFilterableTableModel.addFilter(int, Filter) or IFilterableTableModel.addFilter(Filter), you should use IFilterableTableModel.clearFilters().

Please note, removeAllFilters will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
removeAllFilters in interface IFilterableTableModel

clearFilters

public void clearFilters()
Description copied from interface: IFilterableTableModel
Removes all filters from all columns.

Please note, clearFilters will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Specified by:
clearFilters in interface IFilterableTableModel

getFilters

public Filter[] getFilters(int column)
Description copied from interface: IFilterableTableModel
Gets the filters for the specified column.

Specified by:
getFilters in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
the filters for the specified column.

getFilterItems

public List<IFilterableTableModel.FilterItem> getFilterItems()
Description copied from interface: IFilterableTableModel
Gets all the FilterItems added to this FilterableTableModel.

Specified by:
getFilterItems in interface IFilterableTableModel
Returns:
all the FilterItems added to this FilterableTableModel.

setFiltersApplied

public void setFiltersApplied(boolean apply)
Description copied from interface: IFilterableTableModel
Applies or unapplies the filters. By default, the filters are not applied. So after user adds several filters, this method should be called to make filters taking effect. When new filter is added or existing is removed, this method should be called as well.

Specified by:
setFiltersApplied in interface IFilterableTableModel
Parameters:
apply - true to apply the filters.

isFiltersApplied

public boolean isFiltersApplied()
Description copied from interface: IFilterableTableModel
Checks if the filters are in effect.

Specified by:
isFiltersApplied in interface IFilterableTableModel
Returns:
true if filters are in effect.

hasFilter

public boolean hasFilter()
Description copied from interface: IFilterableTableModel
Checks if the FilterableTableModel has any filters.

Specified by:
hasFilter in interface IFilterableTableModel
Returns:
true if there are any filters. Otherwise false.

hasFilter

public boolean hasFilter(int columnIndex)
Description copied from interface: IFilterableTableModel
Checks if the FilterableTableModel has any filters on the specified column.

Specified by:
hasFilter in interface IFilterableTableModel
Parameters:
columnIndex - the column index to check if there is a filter on it.
Returns:
true if there are any filters on the specified column. Otherwise false.

isAndMode

public boolean isAndMode()
Description copied from interface: IFilterableTableModel
Sets the logic of filters on the same column. If true, filters are in AND mode, meaning if one of the filters return true in isValueFiltered method, the value will be filtered. If false, filters are in OR mode, meaning if one of the filters return false, the value will NOT be filtered.

The mode only has effect on the filters of the same columns which includes each column of the table model as well as the two special column value IFilterableTableModel.ALL_COLUMNS and IFilterableTableModel.ANY_COLUMNS.

Specified by:
isAndMode in interface IFilterableTableModel
Returns:
the AND/OR mode. Default is true which means AND mode.

setAndMode

public void setAndMode(boolean andMode)
Description copied from interface: IFilterableTableModel
Sets the logic among the filters. If AND is true, Please note, this logic mode will apply for all filters, no matter it's for a column or any column or all columns. You won't be able to do complex expression such as AND some filters and OR some other filters using one FitlerableTableModel. In order to do more complex expression, you would need multiple FilterableTableModel, one wraps the other. You make filters in each FilterableTableModel to be OR logic, then the logic among the pipe of FilterableTableModels will always be AND logic.

Specified by:
setAndMode in interface IFilterableTableModel
Parameters:
andMode - true or false.

isAdjusting

public boolean isAdjusting()
Checks if the FilterableTableModel is adjusting. If it is adjusting, FilterableTableModel will not apply filter when the actual list model changes.

Specified by:
isAdjusting in interface IFilterableTableModel
Returns:
true if adjusting. Otherwise false.

setAdjusting

public void setAdjusting(boolean adjusting)
Sets the FilterableTableModel to adjusting mode. If it is adjusting, FilterableTableModel will not apply filter when the actual table model changes. After you set adjusting to false, FilterableListModel will re-apply the filter.

Specified by:
setAdjusting in interface IFilterableTableModel
Parameters:
adjusting - true or false.

getPossibleValues

public Object[] getPossibleValues(int columnIndex,
                                  Comparator comparator)
Description copied from interface: IFilterableTableModel
Gets all possible values of the table model. If there is filter on this column, the possible values are collected from the actual table model. If there is no filter on this column, the possible values are collected from this filterable table model. After we collected all the values, we will use Arrays.sort method to sort the values.

The possible values are used by AutoFilterTableHeader to populate the drop down filter list.

Specified by:
getPossibleValues in interface IFilterableTableModel
Parameters:
columnIndex - the column index.
comparator - the comparator. It is used to sort the values.
Returns:
an array of all possible values of certain column in the table model.

getPossibleValuesAndConverters

public Object[] getPossibleValuesAndConverters(int columnIndex,
                                               Comparator comparator)
Specified by:
getPossibleValuesAndConverters in interface IFilterableTableModel

isSameConverterAt

public boolean isSameConverterAt(int columnIndex)
Description copied from interface: IFilterableTableModel
Check if each converter in this column for each row is the same.

Specified by:
isSameConverterAt in interface IFilterableTableModel
Parameters:
columnIndex - the column index
Returns:
true if all converters are the same in every row. Otherwise false.

createPossibleValuesStatement

protected String createPossibleValuesStatement(int columnIndex)

setFilteringPaused

public void setFilteringPaused(boolean pause)
Not supported in DatabaseTableModel.

Specified by:
setFilteringPaused in interface IFilterableTableModel
Parameters:
pause - not used.

isFilteringPaused

public boolean isFilteringPaused()
Not supported in DatabaseTableModel.

Specified by:
isFilteringPaused in interface IFilterableTableModel
Returns:
false.

addFilterableTableModelListener

public void addFilterableTableModelListener(FilterableTableModelListener l)
Adds a listener to the list that's notified each time a change to the filter occurs.

Specified by:
addFilterableTableModelListener in interface IFilterableTableModel
Parameters:
l - the FilterableTableModelListener

removeFilterableTableModelListener

public void removeFilterableTableModelListener(FilterableTableModelListener l)
Removes a listener from the list that's notified each time a change to the filter occurs.

Specified by:
removeFilterableTableModelListener in interface IFilterableTableModel
Parameters:
l - the FilterableTableModelListener

getFilterableTableModelListeners

public FilterableTableModelListener[] getFilterableTableModelListeners()
Returns an array of all the FilterableTableModel listeners registered on this filter.

Specified by:
getFilterableTableModelListeners in interface IFilterableTableModel
Returns:
all of this filter's FilterableTableModelListeners or an empty array if no filter listeners are currently registered
See Also:
addFilterableTableModelListener(com.jidesoft.grid.FilterableTableModelListener), removeFilterableTableModelListener(com.jidesoft.grid.FilterableTableModelListener)

fireFilterChanged

public void fireFilterChanged(FilterableTableModelEvent e)
Forwards the given notification event to all FilterableTableModelListeners that registered themselves as listeners for this table model.

Parameters:
e - the event to be forwarded
See Also:
addFilterableTableModelListener(com.jidesoft.grid.FilterableTableModelListener), FilterableTableModelEvent, EventListenerList

fireFilterAdded

public void fireFilterAdded(int column,
                            Filter filter)

fireFilterRemoved

public void fireFilterRemoved(int column,
                              Filter filter)

getFilterIcon

public Icon getFilterIcon(int column)
Gets the filter icon for a particular column.

Specified by:
getFilterIcon in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
the icon.

createStatement

protected Statement createStatement()
                             throws SQLException
Creates a Statement. This instance will be reused to run all queries but the "select count(*)" sql. We will try to create ResultSet.TYPE_SCROLL_SENSITIVE Statement if possible. If failed, we will create a ResultSet.TYPE_SCROLL_INSENSITIVE. If failed again, we will create ResultSet.TYPE_FORWARD_ONLY statement.

Returns:
a Statement.
Throws:
SQLException - if it fails to create a ResultSet.TYPE_FORWARD_ONLY statement after failed to create the other two types.

createReadonlyStatement

protected Statement createReadonlyStatement()
                                     throws SQLException
Creates a read-only statement. This statement is used to execute the "select count(*)" sql statement. We will try to create ResultSet.TYPE_SCROLL_INSENSITIVE statement first. It it failed, we will create an ResultSet.TYPE_FORWARD_ONLY statement.

Returns:
a read-only statement.
Throws:
SQLException - if it fails to create a ResultSet.TYPE_FORWARD_ONLY statement after failed to create the ResultSet.TYPE_SCROLL_INSENSITIVE statement.

adjustStatement

protected Statement adjustStatement(Statement statement,
                                    String sql)
                             throws SQLException
This method is called before every single sql queries to give subclass a chance to override to create their own statement. By default, we will create a read-only statement for "select count(*)" statement.

Parameters:
statement - the default Statement.
sql - the sql statement to be executed.
Returns:
null if we will use the default Statement. Otherwise you can create a new Statement and return. It will be used to execute this sql statement only.
Throws:
SQLException - when failed to create a statement.

refreshData

public void refreshData(SortItemSupport sortItemSupport,
                        FilterItemSupport filterItemSupport)
                 throws SQLException
Resubmit the SQL statement.

Comparing with refresh(), this method will throw SQLException. If you would like to handle those exception, you would better invoke this method.

Parameters:
sortItemSupport - the information for sort items.
filterItemSupport - the information for filter items.
Throws:
SQLException - if a database access error occurs, this method is called on a closed Statement or the given SQL statement produces anything other than a single ResultSet object

createResultSetTableModel

protected ResultSetTableModel createResultSetTableModel(ResultSet resultSet,
                                                        int rowCount)
                                                 throws SQLException
Throws:
SQLException

configureConverterContexts

protected void configureConverterContexts()
                                   throws SQLException
Configure converter context for columns by the information contained in meta data.

_converterContexts will be configured here. You can override this method if you need more precise control over the cell renderer.

Throws:
SQLException - if it encounters any database access issue.

createCountStatement

protected String createCountStatement(FilterItemSupport filterItemSupport)
Creates the sql statement to find out the row count in the result set.

Parameters:
filterItemSupport - the filterItemSupport which contains the filter information.
Returns:
the SQl statement to count the rows

createSqlStatement

protected StringBuffer createSqlStatement(String preStatement,
                                          String selectStatement,
                                          String fromStatement,
                                          SortItemSupport sortItemSupport,
                                          FilterItemSupport filterItemSupport)
Creates a full SQL statement.

Parameters:
preStatement - a pre-clause. It will appear at the beginning of all sql statements. For example, WITH abc as ( select dummy from dual ) select * from abc. "WITH abc as ( select dummy from dual )" will be the pre statement. "abc" will be the from statement.
selectStatement - a SQL SELECT statement. Do not include the SELECT word in the statement. Just include everything after the SELECT. If null, we default it to "*". If you use AS statement to change the column name, make sure you also call setColumnMapping(java.util.Map) to set the mapping.
fromStatement - a SQL FROM clause. Do not include the FROM word in the statement. Just include everything after the FROM. It could be
  • FROM first_table
  • FROM first_table, second_table
  • FROM first_table LEFT JOIN second_table
  • FROM first_table INNER JOIN second_table
sortItemSupport - the SortItemSupport which contains the column sorting information.
filterItemSupport - the FilterItemSupport which contains the filtering information.

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

invalidateCache

public void invalidateCache(int row)

invalidateCache

public void invalidateCache()

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

setUpdatable

public void setUpdatable(boolean updatable)

isUpdatable

public boolean isUpdatable()

commit

public void commit()
            throws SQLException
Throws:
SQLException

close

public void close()
           throws SQLException
Throws:
SQLException

validate

public boolean validate(int columnIndex,
                        Object value)
The interface for the table to check if the input value satisfy the request from the meta data of the database. You have to install a JideCellEditorListener to invoke this method promptly. Otherwise this method will not take effect.

So far we did three kinds of check int this method, including:

 public boolean nullCheck(int columnIndex, Object value) throws SQLException;
 public boolean signCheck(int columnIndex, Object value) throws SQLException;
 public boolean precisionCheck(int columnIndex, Object value) throws SQLException;
 

Parameters:
columnIndex - the column index to be check in
value - the value to be check
Returns:
true if the value satisfies the request of meta data. Otherwise false.

validateNullable

public boolean validateNullable(int columnIndex,
                                Object value)
                         throws SQLException
The interface for the table to check if the input value is null and meta data prohibits null value.

Parameters:
columnIndex - the column index to be check in
value - the value to be check
Returns:
false if the value is null and meta data prohibits null value. Otherwise true.
Throws:
SQLException - if it encounters database access issue.

validateSigned

public boolean validateSigned(int columnIndex,
                              Object value)
                       throws SQLException
The interface for the table to check if the input value is negative and meta data prohibits negative value.

Parameters:
columnIndex - the column index to be check in
value - the value to be check
Returns:
false if the value is negative and meta data prohibits negative value. Otherwise true.
Throws:
SQLException - if it encounters database access issue.

validatePrecision

public boolean validatePrecision(int columnIndex,
                                 Object value)
                          throws SQLException
The interface for the table to check if the input value exceeds the precision meta data allows.

Parameters:
columnIndex - the column index to be check in
value - the value to be check
Returns:
false if the value exceeds the precision meta data allows. Otherwise true.
Throws:
SQLException - if it encounters database access issue.

isConsiderCurrencyField

public boolean isConsiderCurrencyField()
Get the flag if you want to consider the isCurrency field in metaData.

The reason we do this is that some database, like Derby, does not support this field and always return true. In that case, it could ruin the original format setting and makes our table renderer a normal decimal as a currency which is not as expected.

The default value is false. You can call setConsiderCurrencyField(boolean) to switch it to true if you make sure that the database supports this field.

Returns:
true if you want to consider isCurrency field in metaData. Otherwise false.

setConsiderCurrencyField

public void setConsiderCurrencyField(boolean considerCurrencyField)
Set the flag if you want to consider the isCurrency field in metaData.

Parameters:
considerCurrencyField - the flag if you want to consider isCurrency field in metaData

getDynamicTableFilters

public DynamicTableFilter[] getDynamicTableFilters(int modelIndex)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets all the DynamicTableFilters.

DynamicTableFilter allows to add your own customize filter to the drop down filter list. Any DynamicTableFilter will become an entry in the list. If user clicks on that entry, the filter will be used to filter the column. What's special about DynamicTableFilter is it allows to to create a filter on fly. For example, in initializeFilter method of DynamicTableFilter, you can pop up a dialog to allow user to select certain information and you return a filter based on user selection. If returning null, no filter will be added. If not null, the filter you just created will be added to the IFilterableTableModel.

Specified by:
getDynamicTableFilters in interface AutoFilterTableHeaderAdapter
Parameters:
modelIndex - the column in the model to add the DynamicTableFilter
Returns:
an array of DynamicTableFilters.

isAllowMultipleValues

public boolean isAllowMultipleValues(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the AutoFilterTableHeader allows multiple values as the filter for the column index. The difference will be to use a CheckBoxList or a regular JList as the popup panel when clicking on the filter button.

Specified by:
isAllowMultipleValues in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true or false.

getTitleConverter

public StringConverter getTitleConverter(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets the title converter to convert the column name. The converter will be used when isShowFilterName() returns true.

Specified by:
getTitleConverter in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index
Returns:
the title converter. null if no converter is needed.

getFilterTitleFormatter

public AutoFilterTableHeaderAdapter.FilterTitleFormatter getFilterTitleFormatter(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets the formatter that will format the title for the AutoFilterTableHeader. This formatter will be used, when isShowFilterName() returns true, to format the title including column name and filter names.

Specified by:
getFilterTitleFormatter in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index
Returns:
the title converter. null if no converter is needed.

getListCellRenderer

public ListCellRenderer getListCellRenderer(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets the list cell renderer for the drop down filter list.

Specified by:
getListCellRenderer in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column in the model to add the DynamicTableFilter
Returns:
an array of DynamicTableFilters.

isUseTableCellRenderer

public boolean isUseTableCellRenderer(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the table cell renderer will be used for the list.

Specified by:
isUseTableCellRenderer in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true or false.

isAllowCustomFilter

public boolean isAllowCustomFilter(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the AutoFilterTableHeader allows custom filter. The difference is there will be a (Custom...) item in the drop down list.when clicking on the filter button. The value is only considered when AutoFilterTableHeader.isAllowMultipleValues() returns false.

Specified by:
isAllowCustomFilter in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true or false.

JIDE 3.5.15