Class JXTable.TableAdapter
- java.lang.Object
-
- org.jdesktop.swingx.decorator.ComponentAdapter
-
- org.jdesktop.swingx.JXTable.TableAdapter
-
- Direct Known Subclasses:
JXTreeTable.TreeTableDataAdapter
- Enclosing class:
- JXTable
protected static class JXTable.TableAdapter extends ComponentAdapter
-
-
Field Summary
-
Fields inherited from class org.jdesktop.swingx.decorator.ComponentAdapter
column, DEFAULT_COLUMN_IDENTIFIER, row, target
-
-
Constructor Summary
Constructors Constructor Description TableAdapter(JXTable component)
Constructs aTableDataAdapter
for the specified target component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.swing.table.TableColumn
getColumnByModelIndex(int modelColumn)
int
getColumnCount()
Returns the number of columns in the target's data model.java.lang.Object
getColumnIdentifierAt(int columnIndex)
Returns logical identifier of the column at columnIndex in model coordinates.int
getColumnIndex(java.lang.Object identifier)
Returns the column index in model coordinates for the logical identifier.java.lang.String
getColumnName(int columnIndex)
Returns the column's display name (= headerValue) of the column at columnIndex in model coordinates.java.lang.String
getFilteredStringAt(int row, int column)
Returns the String representation of the filtered value of the cell identified by the row in view coordinate and the column in model coordinates.java.lang.Object
getFilteredValueAt(int row, int column)
Returns the filtered value of the cell identified by the row in view coordinate and the column in model coordinates.int
getRowCount()
Returns the number of rows in the target's data model.java.lang.String
getString()
Returns the String representation of the value of the cell identified by this adapter.java.lang.String
getStringAt(int row, int column)
Returns the String representation of the value of the cell identified by the row specified row and column in model coordinates.JXTable
getTable()
Typesafe accessor for the target component.java.lang.Object
getValue()
Returns the value of the cell identified by this adapter.java.lang.Object
getValueAt(int row, int column)
Returns the value of the target component's cell identified by the specified row and column in model coordinates.boolean
hasFocus()
Returns true if the cell identified by this adapter currently has focus.boolean
isCellEditable(int row, int column)
Determines whether this cell is editable.boolean
isEditable()
Returnstrue
if the cell identified by this adapter is editable,false
otherwise.boolean
isSelected()
Returns true if the cell identified by this adapter is currently selected.boolean
isTestable(int column)
Returns true if the column should be included in testing.int
modelToView(int columnIndex)
For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from model coordinates to view coordinates.void
setValueAt(java.lang.Object aValue, int row, int column)
Sets the value of the target component's cell identified by the specified row and column in model coordinates.int
viewToModel(int columnIndex)
For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from view coordinates to model coordinates.-
Methods inherited from class org.jdesktop.swingx.decorator.ComponentAdapter
getComponent, getDepth, getString, getValue, isExpanded, isHierarchical, isLeaf, refresh
-
-
-
-
Constructor Detail
-
TableAdapter
public TableAdapter(JXTable component)
Constructs aTableDataAdapter
for the specified target component.- Parameters:
component
- the target component
-
-
Method Detail
-
getTable
public JXTable getTable()
Typesafe accessor for the target component.- Returns:
- the target component as a
JTable
-
getColumnName
public java.lang.String getColumnName(int columnIndex)
Returns the column's display name (= headerValue) of the column at columnIndex in model coordinates. Used f.i. in SearchPanel to fill the field with the column name.Note: it's up to the implementation to decide for which columns it returns a name - most will do so for the subset with isTestable = true. This implementation delegates to getColumnIdentifierAt and returns it's toString or null.
- Overrides:
getColumnName
in classComponentAdapter
- Parameters:
columnIndex
- in model coordinates- Returns:
- column name or null if not found
-
getColumnByModelIndex
protected javax.swing.table.TableColumn getColumnByModelIndex(int modelColumn)
-
getColumnIdentifierAt
public java.lang.Object getColumnIdentifierAt(int columnIndex)
Returns logical identifier of the column at columnIndex in model coordinates. Note: it's up to the implementation to decide for which columns it returns an identifier - most will do so for the subset with isTestable = true.This implementation returns DEFAULT_COLUMN_IDENTIFIER. PENDING JW: This method replaces the old getColumnIdentifier(int) which returned a String which is overly restrictive. The only way to gently replace this method was to add this with a different name - which makes this name suboptimal. Probably should rename again once the old has died out ;-)
- Overrides:
getColumnIdentifierAt
in classComponentAdapter
- Parameters:
columnIndex
- in model coordinates, must be valid.- Returns:
- the identifier of the column at columnIndex or null if it has none.
- See Also:
ComponentAdapter.getColumnIndex(Object)
-
getColumnIndex
public int getColumnIndex(java.lang.Object identifier)
Returns the column index in model coordinates for the logical identifier.This implementation returns 0 if the identifier is the same as the one known identifier returned from getColumnIdentifierAt(0), or -1 otherwise. So subclasses with one column and a customizable identifier need not override. Subclasses which support multiple columns must override this as well to keep the contract as in (assuming that the lookup succeeded):
Object id = getColumnIdentifierAt(index); assertEquals(index, getColumnIndex(index); // and the reverse int column = getColumnIndex(identifier); assertEquals(identifier, getColumnIdentifierAt(column));
- Overrides:
getColumnIndex
in classComponentAdapter
- Parameters:
identifier
- the column's identifier, must not be null- Returns:
- the index of the column identified by identifier in model coordinates or -1 if no column with the given identifier is found.
- See Also:
ComponentAdapter.getColumnIdentifierAt(int)
-
getColumnCount
public int getColumnCount()
Returns the number of columns in the target's data model.- Overrides:
getColumnCount
in classComponentAdapter
- Returns:
- the number of columns in the target's data model.
-
getRowCount
public int getRowCount()
Returns the number of rows in the target's data model.- Overrides:
getRowCount
in classComponentAdapter
- Returns:
- the number of rows in the target's data model.
-
getValueAt
public java.lang.Object getValueAt(int row, int column)
Returns the value of the target component's cell identified by the specified row and column in model coordinates.- Specified by:
getValueAt
in classComponentAdapter
- Parameters:
row
- in model coordinatescolumn
- in model coordinates- Returns:
- the value of the target component's cell identified by the specified row and column
-
setValueAt
public void setValueAt(java.lang.Object aValue, int row, int column)
Sets the value of the target component's cell identified by the specified row and column in model coordinates.- Specified by:
setValueAt
in classComponentAdapter
- Parameters:
aValue
- the value to setrow
- in model coordinatescolumn
- in model coordinates
-
isCellEditable
public boolean isCellEditable(int row, int column)
Determines whether this cell is editable.- Specified by:
isCellEditable
in classComponentAdapter
- Parameters:
row
- the row to query in model coordinatescolumn
- the column to query in model coordinates- Returns:
true
if the cell is editable,false
otherwise
-
isTestable
public boolean isTestable(int column)
Returns true if the column should be included in testing.Here: returns true if visible (that is modelToView gives a valid view column coordinate).
- Overrides:
isTestable
in classComponentAdapter
- Parameters:
column
- the column index in model coordinates- Returns:
- true if the column should be included in testing
-
getFilteredValueAt
public java.lang.Object getFilteredValueAt(int row, int column)
Returns the filtered value of the cell identified by the row in view coordinate and the column in model coordinates. Note: the asymetry of the coordinates is intentional - clients like Highlighters are interested in view values but might need to access non-visible columns for testing. While it is possible to access row coordinates different from the current (that is this.row) it is not safe to do so for row > this.row because the adapter doesn't allow to query the count of visible rows.- Specified by:
getFilteredValueAt
in classComponentAdapter
- Parameters:
row
- the row of the cell in view coordinatescolumn
- the column of the cell in model coordinates.- Returns:
- the filtered value of the cell identified by the row in view coordinate and the column in model coordiantes
-
getValue
public java.lang.Object getValue()
Returns the value of the cell identified by this adapter. That is, for the at position (adapter.row, adapter.column) in view coordinates.NOTE: this implementation assumes that view coordinates == model coordinates, that is simply calls getValueAt(this.row, this.column). It is up to subclasses to override appropriately is they support model/view coordinate transformation.
- Overrides:
getValue
in classComponentAdapter
- Returns:
- the value of the cell identified by this adapter
- See Also:
ComponentAdapter.getValueAt(int, int)
,ComponentAdapter.getFilteredValueAt(int, int)
,ComponentAdapter.getValue(int)
-
getFilteredStringAt
public java.lang.String getFilteredStringAt(int row, int column)
Returns the String representation of the filtered value of the cell identified by the row in view coordinate and the column in model coordinates.Note: the asymetry of the coordinates is intentional - clients like Highlighters are interested in view values but might need to access non-visible columns for testing. While it is possible to access row coordinates different from the current (that is this.row) it is not safe to do so for row > this.row because the adapter doesn't allow to query the count of visible rows.
This implementation messages the StringValue.TO_STRING with the filteredValue, subclasses should re-implement and use the api appropriate for the target component type.
PENDING JW: what about null cell values? StringValue has a contract to return a empty string then, would that be okay here as well?
PENDING JW: this is implemented to duplicate this table's lookup code if the column is not visible. That's not good enough if subclasses implemented a different strategy! We do it anyway for now, mostly we will be lucky and improve the situation against using toString always.
- Overrides:
getFilteredStringAt
in classComponentAdapter
- Parameters:
row
- the row of the cell in view coordinatescolumn
- the column of the cell in model coordinates.- Returns:
- the String representation of the filtered value of the cell identified by the row in view coordinate and the column in model coordiantes
-
getString
public java.lang.String getString()
Returns the String representation of the value of the cell identified by this adapter. That is, for the at position (adapter.row, adapter.column) in view coordinates.NOTE: this implementation assumes that view coordinates == model coordinates, that is simply calls getValueAt(this.row, this.column). It is up to subclasses to override appropriately is they support model/view coordinate transformation.
This implementation messages the StringValue.TO_STRING with the getValue, subclasses should re-implement and use the api appropriate for the target component type.
- Overrides:
getString
in classComponentAdapter
- Returns:
- the String representation of value of the cell identified by this adapter
- See Also:
ComponentAdapter.getValueAt(int, int)
,ComponentAdapter.getFilteredValueAt(int, int)
,ComponentAdapter.getValue(int)
-
getStringAt
public java.lang.String getStringAt(int row, int column)
Returns the String representation of the value of the cell identified by the row specified row and column in model coordinates.This implementation messages the StringValue.TO_STRING with the valueAt, subclasses should re-implement and use the api appropriate for the target component type.
PENDING JW: this is implemented to duplicate this table's lookup code if either the row or the column is not visible. That's not good enough if subclasses implemented a different strategy! We do it anyway for now, mostly we will be lucky and improve the situation against using toString always.
- Overrides:
getStringAt
in classComponentAdapter
- Parameters:
row
- in model coordinatescolumn
- in model coordinates- Returns:
- the value of the target component's cell identified by the specified row and column
-
isEditable
public boolean isEditable()
Returnstrue
if the cell identified by this adapter is editable,false
otherwise.- Specified by:
isEditable
in classComponentAdapter
- Returns:
true
if the cell is editable,false
otherwise
-
isSelected
public boolean isSelected()
Returns true if the cell identified by this adapter is currently selected. Otherwise, it returns false.- Specified by:
isSelected
in classComponentAdapter
- Returns:
- true if the cell identified by this adapter is currently selected; Otherwise, return false
-
hasFocus
public boolean hasFocus()
Returns true if the cell identified by this adapter currently has focus. Otherwise, it returns false.- Specified by:
hasFocus
in classComponentAdapter
- Returns:
- true if the cell identified by this adapter currently has focus; Otherwise, return false
-
modelToView
public int modelToView(int columnIndex)
For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from model coordinates to view coordinates. For all other types of target components, this method returns the columnIndex unchanged.- Overrides:
modelToView
in classComponentAdapter
- Parameters:
columnIndex
- index of a column in model coordinates- Returns:
- index of the specified column in view coordinates
-
viewToModel
public int viewToModel(int columnIndex)
For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from view coordinates to model coordinates. For all other types of target components, this method returns the columnIndex unchanged.- Overrides:
viewToModel
in classComponentAdapter
- Parameters:
columnIndex
- index of a column in view coordinates- Returns:
- index of the specified column in model coordinates
-
-