|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.models.SortableTableModelAdapter
public class SortableTableModelAdapter
A sorter for javax.swing.TableModels. The sorter has a model and itself implements TableModel. SortableTableModelAdapter does not store or copy the data in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. When the model changes it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the SortableTableModelAdapter appears to hold another copy of the table with the rows in a different order. The sorting algorthm used is stable which means that it does not move around rows when its comparison function returns 0 to denote that they are equivalent.
Field Summary | |
---|---|
protected boolean |
autoResort
|
protected boolean |
caseSensitive
|
protected java.util.Map |
columnComparators
|
protected java.util.Comparator |
defaultComparator
|
protected boolean |
defaultModelAttached
|
protected int[] |
indexes
|
protected javax.swing.table.TableModel |
model
|
protected javax.swing.event.SwingPropertyChangeSupport |
propertyChangeSupport
|
protected boolean |
sortAllowed
|
protected java.lang.String[] |
sortedColumns
|
protected int[] |
sortedDirections
|
protected java.lang.String[] |
sortingColumns
|
protected int[] |
sortingDirections
|
protected boolean |
staticRowLabelOrder
|
Fields inherited from interface com.sas.util.SortDirectionInterface |
---|
ASCENDING, DESCENDING, NOT_SORTED |
Fields inherited from interface com.sas.table.InsertRowInterface |
---|
DEFAULT_INDEX |
Constructor Summary | |
---|---|
SortableTableModelAdapter()
Default Constructor, calls this(null) . |
|
SortableTableModelAdapter(javax.swing.table.TableModel model)
Constructs a SortableTableModelAdapter with the given model as the model to sort. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the adapter. |
void |
cancelUncommittedRow()
If an uncommited row is present, this will cancel the row insertion and remove the uncommitted row from the model. |
void |
commitUncommittedRow()
If an uncommitted row is present, this will commit the row into the model. |
int |
convertRowIndexToModel(int viewIndex)
Returns the true model index for a given viewer row index. |
int |
convertRowIndexToView(int modelIndex)
Returns the true 0 based viewer index for a given model row index. |
void |
deleteRow(int rowIndex)
Deletes the given row from the model. |
protected void |
firePropertyChange(java.beans.PropertyChangeEvent evt)
Send a PropertyChangeEvent to any listeners added to the adapter. |
protected void |
firePropertyChange(java.lang.String propName,
java.lang.Object oldValue,
java.lang.Object newValue)
Send a PropertyChangeEvent to any listeners added to the adapter. |
java.lang.Class |
getColumnClass(int columnIndex)
Returns the column class for the given column index. |
java.util.Comparator |
getColumnComparator(java.lang.String column)
Return the current comparator on the given column, which can be null and is null by default. |
int |
getColumnCount()
Returns the column count of the model. |
java.lang.String |
getColumnName(int columnIndex)
Returns the column name for the given column index. |
java.util.Comparator |
getDefaultComparator()
Returns the comparator that is used by default when sorting on a column occurs. |
javax.swing.table.TableModel |
getModel()
Returns the model that is being sorted, this method will never return null. |
int |
getRowCount()
Returns the row count of the model. |
java.lang.Object |
getRowLabel(int row)
Returns a row label for the given index. |
java.lang.Object[] |
getRowLabels(int startIndex,
int count)
Returns an array of row labels for the given index and count. |
java.lang.String[] |
getSortedColumns()
Returns an array of strings that are the column names that have been sorted. |
int[] |
getSortedDirections()
Returns an array of ints that indicate which direction each column in the sortedColumns array has been sorted. |
int |
getUncommittedRowNumber()
Returns the uncommitted row number if one is present. |
java.lang.Object |
getValueAt(int aRow,
int aColumn)
Returns the value a the given row and column index. |
void |
insertUncommittedRow(int rowIndex)
Inserts an uncommitted row into the model, the actual model does not receive notice that a row has been inserted. |
boolean |
isAccurateRowCountAvailable()
Indicates whether an accurate row count is available. |
boolean |
isAutoResortEnabled()
Returns true if the adapter will call a resort when it receives a TableModelEvent of any kind. |
boolean |
isCaseSensitive()
Indicate if the comparison is case sensitive or not if the values being compared are both Strings. |
boolean |
isCellEditable(int row,
int column)
Returns whether the model set on this adapter has an editable cell at the given indices. |
boolean |
isColumnSortable(java.lang.String columnName)
Returns a boolean indicating whether the columnName is allowed to be sorted. |
boolean |
isDefaultModelAttached()
Returns whether the default model is attached, which in this case is a DefaultTableModel with no rows or columns. |
boolean |
isRowDeletionAllowed()
Returns whether the model set on the adapter supports row deletion or not. |
boolean |
isRowInsertionAllowed()
Returns whether rows are allowed to be inserted into the model or not. |
boolean |
isRowLabelsSupported()
Returns true, row labels are supported. |
boolean |
isRowsLabelSupported()
Returns true, row labels are supported. |
boolean |
isRowUpdateAllowed()
Returns whether rows in the model set on this adapter are allowed to be updated or not. |
boolean |
isSortAllowed()
Returns a boolean indicating whether sorting is allowed. |
boolean |
isStaticRowLabelOrder()
Returns whether calls to getRowLabel or getRowLabels with return labels that reflect the sort order or whether they return labels that are in the default order. |
boolean |
isTableExtendOnly()
Returns whether rows are only allowed to be appended to the model or not. |
boolean |
isTrueRowCountCalculated()
Indicates whether the actual row count should be calculated. |
boolean |
isUncommittedRowPresent()
Returns true if the adapter has an uncommitted row present, false otherwise. |
protected javax.swing.table.TableModel |
newDefaultModel()
Create a new default model, which by default is a |
void |
reallocateIndexes()
Refreshes the sorted indices back to their original order, this method gets called whenever the underlying model fires a TableModelEvent with the HEADER_ROW
as the first row. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the adapter. |
void |
resort()
Resorts the table using the last sorted columns and directions. |
void |
setAutoResortEnabled(boolean useAutoResort)
Sets whether the table will automatically call a resort whenever this adapter receives any TableModelEvent. |
void |
setCaseSensitive(boolean caseSensitive)
Set the case sensitivity of the comparisons made. |
void |
setColumnComparator(java.lang.String column,
java.util.Comparator comparator)
Sets the comparator on the given column. |
void |
setDefaultComparator(java.util.Comparator comparator)
Sets the comparator that is used by default when sorting on a column occurs. |
protected void |
setDefaultModelAttached(boolean defaultModelUsed)
Sets whether the default model is attached or not. |
void |
setModel(javax.swing.table.TableModel newModel)
Sets the model on the adapter, if null, a DefaultTableModel will be used. |
void |
setSortAllowed(boolean allowSorting)
Sets whether sorting is enabled or not, by default it is. |
void |
setStaticRowLabelOrder(boolean useStaticRowLabelOrder)
Sets whether the row labels returned from calls to getRowLabel or getRowLabels will always return the same row index for a given row or whether the row index will reflect the new row position due to a sort. |
void |
setTrueRowCountCalculated(boolean trueRowCountCalculated)
Sets whether the actual row count should be calculated. |
void |
setValueAt(java.lang.Object aValue,
int aRow,
int aColumn)
Sets the value for the given row and column on the model set on this adapter. |
void |
sort(java.lang.String[] columnNames,
int[] direction)
Each columnName must have a matching direction. |
void |
sortColumn(java.lang.String column)
Sorts the given column ascending |
void |
sortColumn(java.lang.String column,
int direction)
Sorts the given column in the given direction. |
void |
sortColumns(java.lang.String[] columns,
int[] directions)
Sorts the columns in the the directions specified. |
void |
tableChanged(javax.swing.event.TableModelEvent e)
Signals the adapter that the underlying TableModel has changed and that the adapter may need to update or refesh. |
Field Detail |
---|
protected boolean defaultModelAttached
protected int[] indexes
protected java.lang.String[] sortingColumns
protected java.lang.String[] sortedColumns
protected int[] sortingDirections
protected int[] sortedDirections
protected javax.swing.table.TableModel model
protected java.util.Comparator defaultComparator
protected java.util.Map columnComparators
protected javax.swing.event.SwingPropertyChangeSupport propertyChangeSupport
protected boolean sortAllowed
protected boolean staticRowLabelOrder
protected boolean autoResort
protected boolean caseSensitive
Constructor Detail |
---|
public SortableTableModelAdapter()
this(null)
.
SortableTableModelAdapter(TableModel)
public SortableTableModelAdapter(javax.swing.table.TableModel model)
DefaultTableModel
will be used as
the model. The com.sas.util.GenericComparator.defaultInstance
will be
used as the default comparator for sorting the data.
model
- the model whose data will be sorted. If the model is null, a
DefaultTableModel
will be used as the model.GenericComparator
,
DefaultTableModel
Method Detail |
---|
public javax.swing.table.TableModel getModel()
setModel(TableModel)
public void setModel(javax.swing.table.TableModel newModel)
DefaultTableModel
will be used.
newModel
- the new model for the adapter to sortgetModel()
protected javax.swing.table.TableModel newDefaultModel()
public boolean isDefaultModelAttached()
isDefaultModelAttached
in interface ViewDefaultModel
setDefaultModelAttached(boolean)
protected void setDefaultModelAttached(boolean defaultModelUsed)
defaultModelUsed
- true if a default model is attached, false otherwiseisDefaultModelAttached()
public java.lang.Object getValueAt(int aRow, int aColumn)
getValueAt
in interface javax.swing.table.TableModel
aRow
- the row index of the value to retrieveaColumn
- the column index of the value to retrieve
public void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.AbstractTableModel
aValue
- the value to setaRow
- the row index the value will get set onaColumn
- the column index the value will get set onpublic int convertRowIndexToModel(int viewIndex)
viewIndex
- the 0 based viewer index of the rowpublic int convertRowIndexToView(int modelIndex)
modelIndex
- the 0 based model index of the row
public int getRowCount()
getRowCount
in interface javax.swing.table.TableModel
public int getColumnCount()
getColumnCount
in interface javax.swing.table.TableModel
public java.lang.String getColumnName(int columnIndex)
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.AbstractTableModel
columnIndex
- a zero based column index
public java.lang.Class getColumnClass(int columnIndex)
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
columnIndex
- a zero based column index
public boolean isCellEditable(int row, int column)
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.AbstractTableModel
row
- the zero based row indexcolumn
- the zero based column index
public void setDefaultComparator(java.util.Comparator comparator)
com.sas.util.GenericComparator
.
comparator
- the comparator to use for all columns on the model for which a specific comparator
is not set on a column, the comparator is used for sortinggetDefaultComparator()
public java.util.Comparator getDefaultComparator()
com.sas.util.GenericComparator
.
setDefaultComparator(Comparator)
public java.util.Comparator getColumnComparator(java.lang.String column)
column
- the name of the column whose comparator is to be returned
public void setColumnComparator(java.lang.String column, java.util.Comparator comparator)
column
- the name of the column to set the comparator oncomparator
- comparator to be set on the column, null to remove the comparatorpublic void reallocateIndexes()
TableModelEvent
with the HEADER_ROW
as the first row.
public void tableChanged(javax.swing.event.TableModelEvent e)
reallocateIndexes()
if the TableModelEvent
has a first row param of HEADER_ROW
.
tableChanged
in interface javax.swing.event.TableModelListener
e
- the table model eventpublic void sortColumn(java.lang.String column)
column
- the name of the column to sort, will be sorted ascendingpublic void sortColumn(java.lang.String column, int direction)
column
- the name of the column to sortdirection
- the integer value that represents the direction the
column will be sortedpublic void sortColumns(java.lang.String[] columns, int[] directions)
columns
- an array of strings that match up to column names in the modeldirections
- an array of ints that signal which direction to sort the corresponding
columnpublic void sort(java.lang.String[] columnNames, int[] direction) throws com.sas.table.SortException
sort
in interface com.sas.table.SortableInterface
columnNames
- The names of the columns in the order that the columns will be sorted.direction
- The direction in which to sort the columns. Valid values are
SortDirectionInterface.ASCENDING and SortDirectionInterface.DESCENDING.
com.sas.table.SortException
public java.lang.String[] getSortedColumns()
getSortedColumns
in interface com.sas.table.SortableInterface
public int[] getSortedDirections()
getSortedDirections
in interface com.sas.table.SortableInterface
public boolean isColumnSortable(java.lang.String columnName)
isColumnSortable
in interface com.sas.table.SortableInterface
columnName
- The name of the column to query about whether it is allowed to be
sorted.
public boolean isSortAllowed()
isSortAllowed
in interface com.sas.table.SortableInterface
setSortAllowed(boolean)
public void setSortAllowed(boolean allowSorting)
setSortAllowed
in interface com.sas.table.SortableInterface
allowSorting
- true to enable sorting, false otherwise.isSortAllowed()
public boolean isCaseSensitive()
false
if the comparison ignores case by comparing
only the String.toLowerCase()
version of strings.public void setCaseSensitive(boolean caseSensitive)
caseSensitive
- if true, the comparator will
honor the case of the strings; if false, comparisons
are done on the toLowerCase()
results.public void insertUncommittedRow(int rowIndex) throws com.sas.util.UncheckedException
insertUncommittedRow
in interface InsertRowInterface
rowIndex
- the index to insert the uncommitted row at
com.sas.util.UncheckedException
public void commitUncommittedRow() throws com.sas.util.UncheckedException
InsertRowInterface
or be an instance of
a javax.swing.DefaultTableModel
.
commitUncommittedRow
in interface InsertRowInterface
com.sas.util.UncheckedException
public void cancelUncommittedRow() throws com.sas.util.UncheckedException
cancelUncommittedRow
in interface InsertRowInterface
com.sas.util.UncheckedException
public boolean isUncommittedRowPresent()
isUncommittedRowPresent
in interface InsertRowInterface
public int getUncommittedRowNumber()
getUncommittedRowNumber
in interface InsertRowInterface
public boolean isRowInsertionAllowed()
InsertRowInterface
or be an instance of
a javax.swing.DefaultTableModel
.
isRowInsertionAllowed
in interface InsertRowInterface
public boolean isTableExtendOnly()
InsertRowInterface
as all other model
types will return false.
isTableExtendOnly
in interface InsertRowInterface
public boolean isRowUpdateAllowed()
isRowUpdateAllowed
in interface UpdateRowInterface
public void deleteRow(int rowIndex)
DeleteRowInterface
and allow row deletion or be an instance of a
deleteRow
in interface DeleteRowInterface
rowIndex
- the index of the row to delete from the model if deletion is supportedpublic boolean isRowDeletionAllowed()
DeleteRowInterface
or be an instance of a
isRowDeletionAllowed
in interface DeleteRowInterface
public boolean isAccurateRowCountAvailable()
AccurateRowCountInterface
isAccurateRowCountAvailable
in interface AccurateRowCountInterface
public boolean isTrueRowCountCalculated()
TrueRowCountCalculatedInterface
isTrueRowCountCalculated
in interface TrueRowCountCalculatedInterface
public void setTrueRowCountCalculated(boolean trueRowCountCalculated)
TrueRowCountCalculatedInterface
setTrueRowCountCalculated
in interface TrueRowCountCalculatedInterface
trueRowCountCalculated
- true if the actual row count should be calculatedpublic void setStaticRowLabelOrder(boolean useStaticRowLabelOrder)
useStaticRowLabelOrder
- true if the row labels will be constants, false if the
row labels reflect the sort orderisStaticRowLabelOrder()
public boolean isStaticRowLabelOrder()
setStaticRowLabelOrder(boolean)
public void setAutoResortEnabled(boolean useAutoResort)
useAutoResort
- true if the adapter should resort its data whenever it receive a TableModelEvent,
false otherwiseisAutoResortEnabled()
public boolean isAutoResortEnabled()
setAutoResortEnabled(boolean)
public void resort()
public java.lang.Object getRowLabel(int row)
getRowLabel
in interface com.sas.table.StaticRowLabelInterface
row
- the index of th row label to return
public java.lang.Object[] getRowLabels(int startIndex, int count)
getRowLabels
in interface com.sas.table.StaticRowLabelInterface
startIndex
- the first row label to return in the arraycount
- the number of row labels to return
public boolean isRowLabelsSupported()
isRowLabelsSupported
in interface com.sas.table.StaticRowLabelInterface
public boolean isRowsLabelSupported()
isRowsLabelSupported
in interface com.sas.table.StaticRowLabelInterface
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- the PropertyChangeListener to be notified when a PropertyChangeEvent occurspublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- the PropertyChangeListener to stop being notified when a PropertyChangeEvent occursprotected void firePropertyChange(java.beans.PropertyChangeEvent evt)
protected void firePropertyChange(java.lang.String propName, java.lang.Object oldValue, java.lang.Object newValue)
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |