|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.table.AbstractTableModel com.jidesoft.grid.TreeTableModel<T>
public abstract class TreeTableModel<T extends Row>
TreeTableModel
is the table model used by TreeTable
.
TreeTableModel
has to have a list of rows. We called it original
rows. You can either specify it by using constructor TreeTableModel(java.util.List)
or call setOriginalRows(java.util.List)
. The items in this list should be an instance of Row
.
Once you create the list of Rows and set it to TreeTableModel, you can set the model to TreeTable
. That's
pretty much all you need to do if you just want to view it.
There are also a few methods for changing the table data. addRow(Row)
will add a new Row to the end. addRow(int,Row)
will add the Row after the specified index. Or addRow(int,Row,boolean)
will give you a
chance to add before or after a certain index. In addition, addRow(Row,Row)
adds a row to the specified
parent row. There are two remove methods. removeRow(Row)
can remove any Row from the table model, no matter
if it is in nested children. removeRow(int)
will remove the Row as long as it's visible because the index
passed in has to be a valid index on the table.
You can also move up and move down the row within its current level using moveUpRow(Row)
and moveDownRow(Row)
respectively.
If those modification methods above still can't get what you want, you can always change the original rows. After you
are done with the change, call refresh()
method once to refresh the table.
Field Summary | |
---|---|
protected boolean |
_filtersApplied
A flag to turn on/off filters. |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Fields inherited from interface com.jidesoft.grid.MultiTableModel |
---|
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN |
Constructor Summary | |
---|---|
TreeTableModel()
Creates an empty TreeTableModel. |
|
TreeTableModel(List<? extends T> rows)
Creates TreeTableModel from a list of rows. |
Method Summary | |
---|---|
void |
addIndexChangeListener(IndexChangeListener l)
Add IndexChangelistener. |
void |
addRow(int index,
T row)
Adds a row at the specified index. |
void |
addRow(int index,
T row,
boolean before)
Adds a row at the specified index. |
void |
addRow(T row)
Adds a row to the root level of the table model. |
void |
addRow(T parentRow,
int position,
T row)
Adds row to the parentRow. |
void |
addRow(T parentRow,
T row)
Adds row to the parentRow. |
void |
addRows(int index,
List<? extends T> rows)
Adds a row at the specified index. |
void |
addRows(int index,
List<? extends T> rows,
boolean before)
Adds a row at the specified index. |
void |
addRows(List<? extends T> rows)
Adds a row to the root level of the table model. |
void |
addRows(T parentRow,
int position,
List<? extends T> rows)
Adds row to the parentRow. |
void |
addRows(T parentRow,
List<? extends T> rows)
Adds row to the parentRow. |
protected List<T> |
buildRows(List<? extends T> rows)
Rebuilds the displayed rows from the original rows. |
protected void |
cacheAll(int deleteOrInsert,
int startRowIndex,
int rowCount)
Caches all. |
void |
collapseAll()
Collapse all rows which have children. |
void |
collapseFirstLevel()
Collapses all top level rows only. |
void |
collapseLastLevel()
Collapses all top level rows only. |
void |
collapseRows(List<? extends T> rows,
boolean digIn)
Collapse the rows in the list. |
protected CompoundTableModelEvent |
createCompoundTableModelEvent()
Creates a CompoundTableModelEvent. |
protected ExpandableRow |
createRoot()
Creates ExpandableRow which will be used as the root row. |
protected List<T> |
createRows()
Creates the List to contain the rows. |
void |
expandAll()
Expands all rows which have children. |
void |
expandFirstLevel()
Expands all root level rows. |
void |
expandNextLevel()
Expands one more level of rows. |
void |
expandRow(ExpandableRow row,
boolean expanded)
Expands or collapses the row. |
void |
expandRows(List<? extends T> rows,
boolean digIn)
Expand the rows in the list. |
void |
expandTreePath(TreePath path)
Expands all the rows contained in the tree path |
void |
fireTableRowsUpdated(int firstRow,
int lastRow)
|
Class<?> |
getCellClassAt(int rowIndex,
int columnIndex)
Gets the type at cell (row, column). |
Object |
getChild(Object parent,
int index)
Returns the child of parent at index index in the parent's child array. |
int |
getChildCount(Object parent)
Returns the number of children of parent . |
int |
getColumnType(int columnIndex)
Checks if the column at the columnIndex is a header column or footer column or just regular column. |
ConverterContext |
getConverterContextAt(int rowIndex,
int columnIndex)
Gets the converter context at cell (row, column). |
EditorContext |
getEditorContextAt(int rowIndex,
int columnIndex)
Gets the editor context at cell (row, column). |
Map<Object,Boolean> |
getExpansionState()
Gets the expansion state of all expansion state of tree table model. |
IndexChangeListener[] |
getIndexChangeListeners()
Returns an array of all the IndexChangeListener s |
int |
getIndexOfChild(Object parent,
Object child)
Returns the index of child in parent. |
List<T> |
getOriginalRows()
Gets the list of rows used by the table model. |
Object |
getRoot()
Gets the root expandable row which has the original rows as children. |
T |
getRowAt(int rowIndex)
Returns the row at row specified by row . |
int |
getRowCount()
Returns the number of rows in the model. |
int |
getRowCount(boolean includeChildren)
Gets the total count of the rows in the tree table model, including all the children. |
int |
getRowIndex(T row)
Gets the index of the row. |
List<T> |
getRows()
Gets a flatten list of all the rows that is currently displayed in the table. |
List<T> |
getRows(boolean includeChildren)
Gets the list of rows used by the table model. |
int |
getTableIndex(int columnIndex)
Gets the table index that this column belongs to. |
Object |
getValueAt(int rowIndex,
int columnIndex)
Returns the value for the cell at columnIndex and rowIndex . |
protected void |
invalidateCache(int deleteOrInsert,
int startRowIndex,
int rowCount)
Caches all. |
boolean |
isAdjusting()
|
boolean |
isAutoExpand()
Check if the parent will expand automatically when a child is added to it. |
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns false if column is 0 and return the isEditable of the row if column is 1. |
boolean |
isFilterParent()
|
boolean |
isFiltersApplied()
Checks if the filters are in effect. |
boolean |
isInitialized()
Checks if setOriginalRows is called. |
boolean |
isLeaf(Object node)
Returns true if node is a leaf. |
void |
moveDownRow(T row)
Moves down the row within its same level. |
void |
moveUpRow(T row)
Moves up the row within its same level. |
void |
refresh()
Rebuilds the displayed rows from the original rows and fire table data changed event. |
void |
removeIndexChangeListener(IndexChangeListener l)
Remove IndexChangelistener. |
void |
removeRow(int rowIndex)
Removes the row at the row index. |
void |
removeRow(T row)
Removes the row from tree table model. |
void |
setAdjusting(boolean adjusting)
|
void |
setAutoExpand(boolean autoExpand)
Sets the autoExpand flag. |
void |
setChildren(T parentRow,
List<? extends T> children)
Changes a row's children. |
void |
setExpansionState(Map<Object,Boolean> state)
Restores the expansion state of all rows in tree table model. |
void |
setFilterParent(boolean filterParent)
|
void |
setFiltersApplied(boolean apply)
Applies or unapplies the filters. |
void |
setOriginalRows(List<? extends T> rows)
Sets the original row list. |
void |
setValueAt(Object aValue,
int rowIndex,
int columnIndex)
Sets the value the underlying row of that cell. |
protected boolean |
shouldBeFiltered(T row)
|
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableStructureChanged, getColumnClass, getColumnName, 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, getColumnClass, getColumnCount, getColumnName, removeTableModelListener |
Field Detail |
---|
protected boolean _filtersApplied
setFiltersApplied(boolean)
with true will turn it on and setFiltersApplied(boolean)
with false will turn it off.
Constructor Detail |
---|
public TreeTableModel()
public TreeTableModel(List<? extends T> rows)
rows
- list of rowsMethod Detail |
---|
public void setOriginalRows(List<? extends T> rows)
Row
. Otherwise
IllegalArgumentException will be thrown.
rows
- a list of Row
s
IllegalArgumentException
- if any element in the list is not an instance of Row.protected List<T> buildRows(List<? extends T> rows)
rows
- the original rows.
protected List<T> createRows()
public void refresh()
protected boolean shouldBeFiltered(T row)
public void setChildren(T parentRow, List<? extends T> children)
parentRow
- the parent row.children
- the childrenpublic void addRow(T parentRow, T row)
parentRow
- the parent row.row
- the row to be added.public void addRow(T parentRow, int position, T row)
parentRow
- the parent row.position
- the insert position relative to the parent row.row
- the row to be added.public void addRow(T row)
row
- row to be added.public void addRow(int index, T row)
addRow(int,Row,boolean)
and set the
last boolean to true. The new row will be at the same level as the row at the index.
index
- the row index where the row will be added.row
- the row to be added.public void addRow(int index, T row, boolean before)
index
- the row index. The index can be -1. If it is -1 and before == false, it will be append at the end.
If it is -1 or 0, and before == true, it will insert at the first position.row
- row to be added.before
- if it should be added before index or after index.public void addRows(T parentRow, List<? extends T> rows)
parentRow
- the parent row.rows
- the row to be added.public void addRows(T parentRow, int position, List<? extends T> rows)
parentRow
- the parent row.position
- the insert position relative to the parent row.rows
- the rows to be added.public void addRows(List<? extends T> rows)
rows
- row to be added.public void addRows(int index, List<? extends T> rows)
addRows(int,java.util.List,boolean)
and set the last boolean to false. The new row will be at the same level as the row at the index.
index
- the row index where the row will be added.rows
- the row to be added.public void addRows(int index, List<? extends T> rows, boolean before)
index
- the row index. The index can be -1. If it is -1 and before == false, it will be append at the end.
If before == true, it will insert at the first position.rows
- row to be added.before
- if it should be added before index or after index.public void removeRow(T row)
row
- the row to be removedpublic void removeRow(int rowIndex)
rowIndex
- the row index of the row to be removedpublic void moveUpRow(T row)
row
- the row to be moved up.public void moveDownRow(T row)
row
- the row to be moved down.public List<T> getRows()
public boolean isInitialized()
public List<T> getOriginalRows()
getRows()
, this method returns the
original rows that is passed to constructor or setOriginalRows(java.util.List)
.
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
aValue
- value to assign to cellrowIndex
- row of cellcolumnIndex
- column of cellpublic boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
rowIndex
- the row being queriedcolumnIndex
- the column being queried
public int getRowCount()
JTable
uses this method to determine how many rows it
should display. This method should be quick, as it is called frequently during rendering.
getRowCount
in interface TableModel
TableModel.getColumnCount()
public int getRowCount(boolean includeChildren)
includeChildren
- true to include collapsed children as part of the count. Otherwise getRowCount() will be returned.
public Object getValueAt(int rowIndex, int columnIndex)
columnIndex
and rowIndex
.
getValueAt
in interface TableModel
rowIndex
- the row whose value is to be queriedcolumnIndex
- the column whose value is to be queried
public T getRowAt(int rowIndex)
row
.
getRowAt
in interface ITreeTableModel<T extends Row>
rowIndex
- the row whose row is to be queried
public int getRowIndex(T row)
getRowIndex
in interface ITreeTableModel<T extends Row>
row
- row
public void expandTreePath(TreePath path)
path
- the tree pathprotected CompoundTableModelEvent createCompoundTableModelEvent()
public void expandRow(ExpandableRow row, boolean expanded)
row
- the row to be expanded or collapsedexpanded
- true to expand, false to collapse.protected void cacheAll(int deleteOrInsert, int startRowIndex, int rowCount)
deleteOrInsert
- TableModelEvent.DELETE or TableModelEvent.INSERTstartRowIndex
- the start row index that was impactedrowCount
- the row count that was impactedprotected void invalidateCache(int deleteOrInsert, int startRowIndex, int rowCount)
deleteOrInsert
- TableModelEvent.DELETE or TableModelEvent.INSERTstartRowIndex
- the start row index that was impactedrowCount
- the row count that was impactedpublic void fireTableRowsUpdated(int firstRow, int lastRow)
fireTableRowsUpdated
in class AbstractTableModel
public void expandAll()
public void expandFirstLevel()
public void expandNextLevel()
public void expandRows(List<? extends T> rows, boolean digIn)
rows
- the target rows to be expanded.digIn
- if the expand will be extended to the leaf level or just this levelpublic void collapseAll()
public void collapseFirstLevel()
public void collapseLastLevel()
public void collapseRows(List<? extends T> rows, boolean digIn)
rows
- the target rows to be expanded.digIn
- if the expand will be extended to the leaf level or just this levelpublic ConverterContext getConverterContextAt(int rowIndex, int columnIndex)
ContextSensitiveTableModel
getConverterContextAt
in interface ContextSensitiveTableModel
rowIndex
- the row indexcolumnIndex
- the column index
public EditorContext getEditorContextAt(int rowIndex, int columnIndex)
ContextSensitiveTableModel
getEditorContextAt
in interface ContextSensitiveTableModel
rowIndex
- the row indexcolumnIndex
- the column index
public Class<?> getCellClassAt(int rowIndex, int columnIndex)
ContextSensitiveTableModel
getCellClassAt
in interface ContextSensitiveTableModel
rowIndex
- the row indexcolumnIndex
- the column index
public Object getRoot()
getRoot
in interface ITreeTableModel<T extends Row>
protected ExpandableRow createRoot()
ExpandableRow
which will be used as the root row.
RootExpandableRow
.public Object getChild(Object parent, int index)
parent
at index index
in the parent's child array.
parent
must be a node previously obtained from this data source. This should not return
null
if index
is a valid index for parent
(that is index >= 0 &&
index < getChildCount(parent
)).
parent
- a node in the tree, obtained from this data sourceindex
- the index of the child
parent
at index index
public int getChildCount(Object parent)
parent
. Returns 0 if it has no children.
parent
- a node in the tree model
parent
public int getIndexOfChild(Object parent, Object child)
parent
or child
is null
,
returns -1. If either parent
or child
don't belong to this tree model, returns -1.
parent
- a node in the treechild
- the node we are interested in
child
or parent
are
null
or don't belong to this tree table modelpublic boolean isLeaf(Object node)
true
if node
is a leaf. As long as the node is not an instance of Expandable,
it is a leaf. It is possible for this method to return false
even if node
has no
children. A directory in a filesystem, for example, may contain no files; the node representing the directory is
not a leaf, but it also has no children.
node
- a node in the tree table model
node
is a leafpublic boolean isFilterParent()
public void setFilterParent(boolean filterParent)
public void setFiltersApplied(boolean apply)
apply
- true to apply the filters.public boolean isFiltersApplied()
public boolean isAutoExpand()
public void setAutoExpand(boolean autoExpand)
autoExpand
- true or false.public int getColumnType(int columnIndex)
MultiTableModel
getColumnType
in interface MultiTableModel
columnIndex
- the column index
public int getTableIndex(int columnIndex)
MultiTableModel
getTableIndex
in interface MultiTableModel
columnIndex
- the column index
public List<T> getRows(boolean includeChildren)
includeChildren
- true to include collapsed children as part of the list. Otherwise getRows() will be returned.
public boolean isAdjusting()
public void setAdjusting(boolean adjusting)
public Map<Object,Boolean> getExpansionState()
setExpansionState(java.util.Map)
to restore the tree table expansion state after the TreeTableModel is
recreated.
public void setExpansionState(Map<Object,Boolean> state)
state
- a map of the expansion state.public void addIndexChangeListener(IndexChangeListener l)
IndexChangeEventGenerator
addIndexChangeListener
in interface IndexChangeEventGenerator
l
- the listenerpublic void removeIndexChangeListener(IndexChangeListener l)
IndexChangeEventGenerator
removeIndexChangeListener
in interface IndexChangeEventGenerator
l
- the listenerpublic IndexChangeListener[] getIndexChangeListeners()
IndexChangeEventGenerator
IndexChangeListener
s
getIndexChangeListeners
in interface IndexChangeEventGenerator
IndexChangeListener
s added or an empty array if no listeners have been addedIndexChangeEventGenerator.addIndexChangeListener(com.jidesoft.grid.IndexChangeListener)
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |