JIDE 3.5.15

com.jidesoft.grid
Class DefaultGroupTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.grid.TreeTableModel
          extended by com.jidesoft.grid.AbstractGroupTableModel
              extended by com.jidesoft.grid.DefaultGroupTableModel
All Implemented Interfaces:
ColumnDraggableSupport, ColumnIdentifierTableModel, ColumnTableModelWrapper, ContextSensitiveTableModel, EditorStyleTableModel, GroupModelProvider, IndexChangeEventGenerator, ITreeTableModel, MultiTableModel, RowTableModelWrapper, SpanModel, TableModelWrapper, Serializable, TableModel

public class DefaultGroupTableModel
extends AbstractGroupTableModel
implements ColumnIdentifierTableModel, SpanModel, RowTableModelWrapper, ColumnTableModelWrapper, GroupModelProvider, EditorStyleTableModel, ColumnDraggableSupport

See Also:
Serialized Form

Nested Class Summary
static interface DefaultGroupTableModel.ColumnComparatorContextProvider
          An interface used by SortableTableModel.setColumnComparatorContextProvider(com.jidesoft.grid.SortableTableModel.ColumnComparatorContextProvider).
 
Field Summary
static int SORT_GROUP_COLUMN_ASCENDING
          Ascending order on the group column, which means the groups row will be sorted in an ascending order.
static int SORT_GROUP_COLUMN_DESCENDING
          Descending order on the group column, which means the groups row will be sorted in an descending order.
static int SORT_GROUP_COLUMN_NO_SORT
          No sort on the group column, which means the group rows will be displayed in a first-come-first-display order by the order it appears in the original table model.
 
Fields inherited from class com.jidesoft.grid.TreeTableModel
_filtersApplied
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.grid.EditorStyleTableModel
EDITOR_STYLE_EDITABLE, EDITOR_STYLE_NORMAL, EDITOR_STYLE_READ_ONLY, EDITOR_STYLE_SELECT_ONLY
 
Fields inherited from interface com.jidesoft.grid.MultiTableModel
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN
 
Constructor Summary
DefaultGroupTableModel(TableModel tableModel)
          The constructor.
 
Method Summary
 void addGroupColumn(int columnIndex)
          Adds a group column with default ascending order.
 void addGroupColumn(int columnIndex, int order)
          Adds a group column with designated sort order.
 DefaultGroupRow addGroupRow(Expandable parentRow, DefaultGroupRow groupRow)
          Adds GroupRow to a parent row.
protected  void cacheComparators()
          For performance, all comparators for each column should be cached first.
 void clearGroupColumns()
          Clears all group columns.
 void collapseAll()
          Collapse all rows which have children.
 void collapseFirstLevel()
          Collapses all top level rows only.
 void collapseGroupColumn(int groupColumnIndex)
          Collapse all rows that corresponding to the group column.
protected  int compare(int row1, int row2)
          Compares two rows.
protected  int compare(Object o1, Object o2, int column)
          Compares two objects in a column.
protected  CompoundTableModelEvent createCompoundTableModelEvent()
          Creates a CompoundTableModelEvent.
protected  DefaultGroupRow createGroupRow()
          Creates DefaultGroupRow.
protected  ReferenceRow createReferenceRow(TableModel tableModel, int row)
          Creates ReferenceRow.
protected  void ensureGroupColumnsCreated()
          Makes sure internal used fields are created.
 void expandAll()
          Expands all rows which have children.
protected  void expandAll(boolean fireDataChangedEvent)
          Expands all rows.
 void expandFirstLevel()
          Expands all root level rows.
 void expandGroupColumn(int groupColumnIndex)
          Expand all rows that corresponding to the group column.
 void expandRow(ExpandableRow row, boolean expanded)
          Expands or collapses the row.
 DefaultGroupRow findGroupRow(Expandable parent, TableModel tableModel, int rowIndex)
          Finds a group row to hold the row in the original table model.
 DefaultGroupRow findGroupRow(Row row, int columnIndex)
          Finds a group row to hold the row in this group table model.
 DefaultGroupRow findParentGroupRow(Expandable parent, GroupCondition condition)
          Finds a group row based on the ancestor row and the group condition.
 int getActualColumnAt(int column)
          Gets the actual column index in the underlying table that corresponds the specified column index.
 TableModel getActualModel()
          Gets the underlying table model.
 int getActualRowAt(int visualRow)
          Gets the actual row index in the underlying table that corresponds the specified row index.
 Class<?> getCellClassAt(int rowIndex, int columnIndex)
          Gets the type at cell (row, column).
 CellSpan getCellSpanAt(int rowIndex, int columnIndex)
          Gets the cell span at the specified row and column.
 Class<?> getColumnClass(int column)
           
protected  ComparatorContext getColumnComparatorContext(int column)
          Gets the column comparator context.
 DefaultGroupTableModel.ColumnComparatorContextProvider getColumnComparatorContextProvider()
          Gets the ColumnComparatorContextProvider.
 int getColumnCount()
           
 Object getColumnIdentifier(int column)
          Returns the identifier of the column in the model.
 int[] getColumnMapping()
          Gets column mapping.
 String getColumnName(int column)
           
 int getColumnType(int columnIndex)
          Checks if the column at the columnIndex is a header column or footer column or just regular column.
 Comparator getComparator(int columnIndex)
          Gets the column comparator.
 ConverterContext getConverterContextAt(int rowIndex, int columnIndex)
          Gets the converter context at cell (row, column).
protected  String getCountColumnName()
          Gets the column name for the count column.
 EditorContext getEditorContextAt(int rowIndex, int columnIndex)
          Gets the editor context at cell (row, column).
 int getEditorStyleAt(int rowIndex, int columnIndex)
          Gets editor style at the cell.
 Map<Object,Boolean> getExpansionState()
          Gets the expansion state of all expansion state of tree table model.
 int getGroupColumnAt(int index)
          Gets the group column index.
 int getGroupColumnCount()
          Gets the total count of group columns.
 Object getGroupColumnIdentifier(int groupColumnIndex)
          Gets the identifier of the group column index.
 int getGroupColumnOrder(int index)
          Gets the group column order.
 ReferenceRow getReferenceRow(int rowIndex)
           
 Row getRowAt(int rowIndex)
          Returns the row at row specified by row.
 int getRowCount()
          Returns the number of rows in the model.
 int getRowIndex(Row row)
          Gets the index of the row.
protected  String getSeparateGroupColumnName()
          Gets the column name for the separate group column.
 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.
 int getVisualColumnAt(int actualColumn)
          Gets the visual column index representing the specified actual column.
 int getVisualRowAt(int actualRow)
          Gets the visual row index representing the specified actual row.
 void groupAndRefresh()
          Do grouping and fire table structure changed event.
 boolean groupColumnsFirst()
          Gets the flag indicating if group columns should always be displayed at the begging when displayed.
 boolean hasGroupColumns()
          Checks if it has grouped columns.
 boolean isAlwaysUseComparators()
          Checks if the alwaysUseComparators flag value.
 boolean isAscendingGroupOrder()
          Deprecated. replaced by addGroupColumn(int, int), sorting is the second parameter.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false if column is 0 and return the isEditable of the row if column is 1.
 boolean isCellSpanOn()
          Checks if the span is on.
 boolean isColumnDraggable(int columnIndex)
          Checks if the column is draggable.
 boolean isColumnGroupable(int columnIndex)
          Checks if the specific column is groupable.
 boolean isColumnGrouped(int columnIndex)
          Is the column grouped.
 boolean isDisplayCountColumn()
          Gets the flag indicating if a separate count column should be created to represent the count.
 boolean isDisplayGroupColumns()
          Gets the flag indicating if the GroupTable should display group columns.
 boolean isDisplayGroupRowsFirst()
          Gets the flag indicating if the group rows will be put ahead of the other reference rows when isRemoveNullGrouper() returns true.
 boolean isDisplaySeparateGroupColumn()
          Gets the flag indicating if a separate group column should be created to represent the grouped columns.
 boolean isGroupEnabled()
          Gets if the group feature is enabled.
 boolean isKeepColumnOrder()
          Gets the flag indicating if the original column order in original table model should be kept.
 boolean isKeepGroupingOnStructureChange()
          Gets the flag indicating if previous grouping columns should be kept on receiving table structure changed event.
 boolean isKeepPreviousExpandStatus()
          Gets the flag indicating if the previous expand status should be kept on data changing, adding/removing group columns.
 boolean isRemoveNullGrouper()
          Gets the flag indicating if the row will be moved to upper level if the last grouper values are null.
 boolean isSingleLevelGrouping()
          Gets the flag if the group rows will be created in a single level or multiple levels mode.
 void removeGroupColumn(int columnIndex)
          Removes a group column.
 void setAlwaysUseComparators(boolean alwaysUseComparators)
          Sets the alwaysUseComparators flag.
 void setAscendingGroupOrder(boolean order)
          Deprecated. replaced by addGroupColumn(int, int), sorting is the second parameter.
 void setColumnComparatorContextProvider(DefaultGroupTableModel.ColumnComparatorContextProvider columnComparatorContextProvider)
          Sets the ColumnComparatorContextProvider.
 void setDisplayCountColumn(boolean displayCountColumn)
          Sets the flag indicating if a separate count column should be created to represent the count.
 void setDisplayGroupColumns(boolean displayGroupColumns)
          Sets the flag indicating if the GroupTable should display group columns.
 void setDisplayGroupRowsFirst(boolean groupRowsFirst)
          Sets the flag indicating if the group rows will be put ahead of the other reference rows when isRemoveNullGrouper() returns true.
 void setDisplaySeparateGroupColumn(boolean displaySeparateGroupColumn)
          Sets the flag indicating if a separate group column should be created to represent the grouped columns.
 void setExpansionState(Map state)
          Restores the expansion state of all rows in tree table model.
 void setGroupColumns(int[] columnIndices)
          Sets group columns in a batch mode with default order as ascending.
 void setGroupColumns(int[] columnIndices, int[] columnSorting)
          Sets group columns in a batch mode.
 void setKeepColumnOrder(boolean keepColumnOrder)
          Sets the flag indicating if the original column order in original table model should be kept.
 void setKeepGroupingOnStructureChange(boolean keepGroupingOnStructureChange)
          Sets the flag indicating if previous grouping columns should be kept on receiving table structure changed event.
 void setKeepPreviousExpandStatus(boolean keepPreviousExpandStatus)
          Sets the flag indicating if the previous expand status should be kept on data changing, adding/removing group columns.
 void setRemoveNullGrouper(boolean removeNullGrouper)
          Sets the flag indicating if the row will be moved to upper level if the last grouper values are null.
 void setSingleLevelGrouping(boolean singleLevelGrouping)
          Sets the flag if the group rows will be created in a single level or multiple levels mode.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Sets the value the underlying row of that cell.
protected  void sort(int[] from, int[] to, int low, int high)
          Sorts the rows.
protected  void tableCellsUpdated(int column, int firstRow, int lastRow)
          The handler to handle tableCellsUpdated event.
protected  void tableDataChanged()
          The handler to handle tableDataChanged event.
protected  void tableRowsDeleted(int firstRow, int lastRow)
          The handler to handle tableRowsDeleted event.
protected  void tableRowsInserted(int firstRow, int lastRow)
          The handler to handle tableRowsInserted event.
protected  void tableRowsUpdated(int firstRow, int lastRow)
          The handler to handle tableRowsUpdated event.
protected  void tableStructureChanged()
          The handler to handle tableStructureChanged event.
protected  void updateReference(int index, int inc)
          Updates the row index field of IndexReferenceRow.
 
Methods inherited from class com.jidesoft.grid.TreeTableModel
addIndexChangeListener, addRow, addRow, addRow, addRow, addRow, addRows, addRows, addRows, addRows, addRows, buildRows, cacheAll, collapseLastLevel, collapseRows, createRoot, createRows, expandNextLevel, expandRows, expandTreePath, fireTableRowsUpdated, getChild, getChildCount, getIndexChangeListeners, getIndexOfChild, getOriginalRows, getRoot, getRowCount, getRows, getRows, invalidateCache, isAdjusting, isAutoExpand, isFilterParent, isFiltersApplied, isInitialized, isLeaf, moveDownRow, moveUpRow, refresh, removeIndexChangeListener, removeRow, removeRow, setAdjusting, setAutoExpand, setChildren, setFilterParent, setFiltersApplied, setOriginalRows, shouldBeFiltered
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, 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

SORT_GROUP_COLUMN_NO_SORT

public static final int SORT_GROUP_COLUMN_NO_SORT
No sort on the group column, which means the group rows will be displayed in a first-come-first-display order by the order it appears in the original table model.

See Also:
Constant Field Values

SORT_GROUP_COLUMN_ASCENDING

public static final int SORT_GROUP_COLUMN_ASCENDING
Ascending order on the group column, which means the groups row will be sorted in an ascending order.

See Also:
Constant Field Values

SORT_GROUP_COLUMN_DESCENDING

public static final int SORT_GROUP_COLUMN_DESCENDING
Descending order on the group column, which means the groups row will be sorted in an descending order.

See Also:
Constant Field Values
Constructor Detail

DefaultGroupTableModel

public DefaultGroupTableModel(TableModel tableModel)
The constructor.

Parameters:
tableModel - the original table model embedded in the DefaultGroupTableModel.
Method Detail

isColumnGroupable

public boolean isColumnGroupable(int columnIndex)
Checks if the specific column is groupable. By default it simply returns true for all columns. You could override this method to make some columns non-groupable.

Specified by:
isColumnGroupable in interface GroupModelProvider
Parameters:
columnIndex - the column index in the wrapped table model of this DefaultGroupTableModel
Returns:
true if the column is groupable. Otherwise false.
Since:
3.2.3 changed to public

createCompoundTableModelEvent

protected CompoundTableModelEvent createCompoundTableModelEvent()
Creates a CompoundTableModelEvent. It is created when a CompoundTableModelEvent is required.

Overrides:
createCompoundTableModelEvent in class TreeTableModel
Returns:
the CompoundTableModelEvent instance.

groupAndRefresh

public void groupAndRefresh()
Do grouping and fire table structure changed event.

Specified by:
groupAndRefresh in interface GroupModelProvider

createGroupRow

protected DefaultGroupRow createGroupRow()
Creates DefaultGroupRow. This is to create a non-leaf row in GroupTable.

The row created will be expanded if TreeTableModel.isAutoExpand() returns true. Otherwise collapsed.

Returns:
the DefaultGroupRow instance.

createReferenceRow

protected ReferenceRow createReferenceRow(TableModel tableModel,
                                          int row)
Creates ReferenceRow. This is to create a leaf row in GroupTable.

Parameters:
tableModel - the original table model
row - the row index in the original table model
Returns:
the ReferenceRow instance.

isKeepColumnOrder

public boolean isKeepColumnOrder()
Gets the flag indicating if the original column order in original table model should be kept.

Returns:
true if the orignal column order should be kept. Otherwise false.
See Also:
setKeepColumnOrder(boolean)

setKeepColumnOrder

public void setKeepColumnOrder(boolean keepColumnOrder)
Sets the flag indicating if the original column order in original table model should be kept.

By default, the flag is false.

If you set the flag to true, the GroupTable will simply use the column order of the original table model. Hence, isDisplayCountColumn(), isDisplayGroupColumns() and isDisplaySeparateGroupColumn() would not be honored.

Parameters:
keepColumnOrder - the flag

isColumnDraggable

public boolean isColumnDraggable(int columnIndex)
Description copied from interface: ColumnDraggableSupport
Checks if the column is draggable.

Specified by:
isColumnDraggable in interface ColumnDraggableSupport
Parameters:
columnIndex - the column index
Returns:
true if the column is draggable. Otherwise false.

addGroupRow

public DefaultGroupRow addGroupRow(Expandable parentRow,
                                   DefaultGroupRow groupRow)
Adds GroupRow to a parent row.

In most scenarios, you don't have to call this method explicitly because groupAndRefresh() will invoke it automatically.

Parameters:
parentRow - the parent row, which should also be a group row or a root row
groupRow - the group row to be added to the parent row
Returns:
the groupRow added.

findParentGroupRow

public DefaultGroupRow findParentGroupRow(Expandable parent,
                                          GroupCondition condition)
Finds a group row based on the ancestor row and the group condition.

Parameters:
parent - the ancestor row
condition - the group condition
Returns:
the group row which represents the group condition exactly. Otherwise null.

ensureGroupColumnsCreated

protected void ensureGroupColumnsCreated()
Makes sure internal used fields are created.


isGroupEnabled

public boolean isGroupEnabled()
Description copied from class: AbstractGroupTableModel
Gets if the group feature is enabled.

Specified by:
isGroupEnabled in class AbstractGroupTableModel
Returns:
true if group is enabled. Otherwise false.

isColumnGrouped

public boolean isColumnGrouped(int columnIndex)
Is the column grouped.

Parameters:
columnIndex - the column index. It is the column index as in the original table model.
Returns:
true if the column is grouped. Otherwise false.

hasGroupColumns

public boolean hasGroupColumns()
Checks if it has grouped columns.

Returns:
true if it has grouped columns. Otherwise false.

getGroupColumnCount

public int getGroupColumnCount()
Gets the total count of group columns. You can use this method to get the count then use getGroupColumnAt(int) method to find out each group column index.

Specified by:
getGroupColumnCount in interface GroupModelProvider
Returns:
the total count of group columns.

getGroupColumnAt

public int getGroupColumnAt(int index)
Gets the group column index.

Specified by:
getGroupColumnAt in interface GroupModelProvider
Parameters:
index - the column index.
Returns:
the group column index.

getGroupColumnOrder

public int getGroupColumnOrder(int index)
Gets the group column order.

The return value would be SORT_GROUP_COLUMN_NO_SORT, SORT_GROUP_COLUMN_ASCENDING or SORT_GROUP_COLUMN_DESCENDING

Specified by:
getGroupColumnOrder in interface GroupModelProvider
Parameters:
index - the column index
Returns:
the order.

addGroupColumn

public void addGroupColumn(int columnIndex)
Adds a group column with default ascending order.

This method is just to manage the group columns. To make the group happen in the table, please invoke groupAndRefresh().

Parameters:
columnIndex - the column index in the original table model

addGroupColumn

public void addGroupColumn(int columnIndex,
                           int order)
Adds a group column with designated sort order.

This method is just to manage the group columns. To make the group happen in the table, please invoke groupAndRefresh().

Parameters:
columnIndex - the column index in the original table model
order - the sort mode, one of SORT_GROUP_COLUMN_NO_SORT, SORT_GROUP_COLUMN_ASCENDING or SORT_GROUP_COLUMN_DESCENDING

removeGroupColumn

public void removeGroupColumn(int columnIndex)
Removes a group column.

This method is just to manage the group columns. To make the ungroup happen in the table, please invoke groupAndRefresh().

Parameters:
columnIndex - the column index in the original table model

setGroupColumns

public void setGroupColumns(int[] columnIndices)
Sets group columns in a batch mode with default order as ascending.

This method is just to manage the group columns. To make the group happen in the table, please invoke groupAndRefresh().

Parameters:
columnIndices - the new group column indices in original table model

setGroupColumns

public void setGroupColumns(int[] columnIndices,
                            int[] columnSorting)
Sets group columns in a batch mode.

This method is just to manage the group columns. To make the group happen in the table, please invoke groupAndRefresh().

Specified by:
setGroupColumns in interface GroupModelProvider
Parameters:
columnIndices - the new group column indices in original table model
columnSorting - the sort order of each group column

clearGroupColumns

public void clearGroupColumns()
Clears all group columns.

This method is just to manage the group columns. To make the ungroup happen in the table, please invoke groupAndRefresh().


getColumnName

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

getColumnIdentifier

public Object getColumnIdentifier(int column)
Description copied from interface: ColumnIdentifierTableModel
Returns the identifier of the column in the model. A JideTable uses this method to get the unique identifier of this column.

Specified by:
getColumnIdentifier in interface ColumnIdentifierTableModel
Parameters:
column - the index of the column
Returns:
the unique identifier of the column.

getGroupColumnIdentifier

public Object getGroupColumnIdentifier(int groupColumnIndex)
Gets the identifier of the group column index.

Specified by:
getGroupColumnIdentifier in interface GroupModelProvider
Parameters:
groupColumnIndex - the group column index
Returns:
the identifier.
Since:
3.3.0

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
Overrides:
getEditorContextAt in class TreeTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
editor context

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
Overrides:
getConverterContextAt in class TreeTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
converter 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
Overrides:
getCellClassAt in class TreeTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
type

getColumnClass

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

getRowCount

public int getRowCount()
Description copied from class: TreeTableModel
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class TreeTableModel
Returns:
the number of rows in the model
See Also:
TableModel.getColumnCount()

getColumnCount

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

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Description copied from class: TreeTableModel
Returns false if column is 0 and return the isEditable of the row if column is 1.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class TreeTableModel
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
false

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Description copied from class: TreeTableModel
Sets the value the underlying row of that cell.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class TreeTableModel
Parameters:
aValue - value to assign to cell
rowIndex - row of cell
columnIndex - column of cell

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Description copied from class: TreeTableModel
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class TreeTableModel
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell

isSingleLevelGrouping

public boolean isSingleLevelGrouping()
Gets the flag if the group rows will be created in a single level or multiple levels mode.

Returns:
true if the group rows are created in one single level. Otherwise false.
See Also:
setSingleLevelGrouping(boolean)

setSingleLevelGrouping

public void setSingleLevelGrouping(boolean singleLevelGrouping)
Sets the flag if the group rows will be created in a single level or multiple levels mode.

By default, the value is false, which means multiple level GroupRows will be created. If you want only one level group row even if you have multiple group columns, please set this flag to true.

Parameters:
singleLevelGrouping - the flag

getCellSpanAt

public CellSpan getCellSpanAt(int rowIndex,
                              int columnIndex)
Description copied from interface: SpanModel
Gets the cell span at the specified row and column. To avoid creating many instances of CellSpan, you can return the same instance by changing its values only. For example, the code below is a good example.

 private final CellSpan span = new CellSpan(0,0,1,1);
 public CellSpan getCellSpanAt(int row, int col) {
     span.setRow(...);
     span.setColumn(...);
     span.setRowSpan(...);
     span.setColumnSpan(...);
     return span;
 }
 
For performance consideration, if the cell span has 1 row span and 1 column span, it is better to return null instead of new CellSpan(row, column, 1, 1).

Specified by:
getCellSpanAt in interface SpanModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
CellSpan object.

findGroupRow

public DefaultGroupRow findGroupRow(Expandable parent,
                                    TableModel tableModel,
                                    int rowIndex)
Finds a group row to hold the row in the original table model.

Parameters:
parent - the parent row
tableModel - the original table model
rowIndex - the row index
Returns:
the group row existed. null if not existing.

findGroupRow

public DefaultGroupRow findGroupRow(Row row,
                                    int columnIndex)
Finds a group row to hold the row in this group table model.

Parameters:
row - the row instance inside the group table model
columnIndex - the group column to find
Returns:
the group row existed. null if not existing.

getRowAt

public Row getRowAt(int rowIndex)
Description copied from class: TreeTableModel
Returns the row at row specified by row.

Specified by:
getRowAt in interface ITreeTableModel
Overrides:
getRowAt in class TreeTableModel
Parameters:
rowIndex - the row whose row is to be queried
Returns:
the row at the specified row index

getRowIndex

public int getRowIndex(Row row)
Description copied from class: TreeTableModel
Gets the index of the row.

Specified by:
getRowIndex in interface ITreeTableModel
Overrides:
getRowIndex in class TreeTableModel
Parameters:
row - row
Returns:
the index of the row. If the row is displayed in the table, it will return the index. Otherwise, it will return -1. So -1 could mean two things - the row is not displayed or the row is not in the tree hierarchy at all.

getReferenceRow

public ReferenceRow getReferenceRow(int rowIndex)

isCellSpanOn

public boolean isCellSpanOn()
Description copied from interface: SpanModel
Checks if the span is on. The CellSpanTable will ignore all the CellSpans defined in this model if this method returns false.

Since 3.5.12, please fire table data changed event if the returned value of this method is changed. Otherwise the CellSpanTable might still use the cached value to improve performance.

Specified by:
isCellSpanOn in interface SpanModel
Returns:
true if span is on. Otherwise false.

getColumnType

public int getColumnType(int columnIndex)
Description copied from interface: MultiTableModel
Checks if the column at the columnIndex is a header column or footer column or just regular column. Header columns will be displayed at the left side of the table. Footer columns will be on the right side. Regular columns will in the middle and will have horizontal scroll bar if there are a lot of columns.

Specified by:
getColumnType in interface MultiTableModel
Overrides:
getColumnType in class TreeTableModel
Parameters:
columnIndex - the column index
Returns:
column type. The possible values are REGULAR_COLUMN, HEADER_COLUMN, or FOOTER_COLUMN.

getTableIndex

public int getTableIndex(int columnIndex)
Description copied from interface: MultiTableModel
Gets the table index that this column belongs to. As convention, the table index starts from 0. So all columns that return 0 in this method will be grouped into the first table. Those return 1 will be on the second table, and so on.

Specified by:
getTableIndex in interface MultiTableModel
Overrides:
getTableIndex in class TreeTableModel
Parameters:
columnIndex - the column index
Returns:
the table index.

tableRowsInserted

protected void tableRowsInserted(int firstRow,
                                 int lastRow)
The handler to handle tableRowsInserted event.

Parameters:
firstRow - the first row inserted
lastRow - the last row inserted

tableRowsDeleted

protected void tableRowsDeleted(int firstRow,
                                int lastRow)
The handler to handle tableRowsDeleted event.

Parameters:
firstRow - the first row deleted
lastRow - the last row deleted

updateReference

protected void updateReference(int index,
                               int inc)
Updates the row index field of IndexReferenceRow. Should be invoked only inside the table model event handlers.

Parameters:
index - the row index
inc - the gap to be updated

tableRowsUpdated

protected void tableRowsUpdated(int firstRow,
                                int lastRow)
The handler to handle tableRowsUpdated event.

Parameters:
firstRow - the first row updated
lastRow - the last row updated

tableCellsUpdated

protected void tableCellsUpdated(int column,
                                 int firstRow,
                                 int lastRow)
The handler to handle tableCellsUpdated event.

Parameters:
column - the column updated
firstRow - the first row updated
lastRow - the last row updated

tableStructureChanged

protected void tableStructureChanged()
The handler to handle tableStructureChanged event.


tableDataChanged

protected void tableDataChanged()
The handler to handle tableDataChanged event.


getColumnMapping

public int[] getColumnMapping()
Gets column mapping.

Returns:
the column mapping array which contains the map from the column index in this DefaultGroupTableModel to the original table model.

getActualModel

public TableModel getActualModel()
Description copied from interface: TableModelWrapper
Gets the underlying table model.

Specified by:
getActualModel in interface TableModelWrapper
Returns:
the underlying table model.

getActualRowAt

public int getActualRowAt(int visualRow)
Description copied from interface: RowTableModelWrapper
Gets the actual row index in the underlying table that corresponds the specified row index.

Specified by:
getActualRowAt in interface RowTableModelWrapper
Parameters:
visualRow - the visual row index.
Returns:
the actual row. If the actual row doesn't exist, return -1.

getVisualRowAt

public int getVisualRowAt(int actualRow)
Description copied from interface: RowTableModelWrapper
Gets the visual row index representing the specified actual row.

Specified by:
getVisualRowAt in interface RowTableModelWrapper
Parameters:
actualRow - the actual row index.
Returns:
the visual row index. -1 if there is no visual row representing it.

getActualColumnAt

public int getActualColumnAt(int column)
Description copied from interface: ColumnTableModelWrapper
Gets the actual column index in the underlying table that corresponds the specified column index.

Specified by:
getActualColumnAt in interface ColumnTableModelWrapper
Returns:
the actual column. If the actual column doesn't exist, return -1.

getVisualColumnAt

public int getVisualColumnAt(int actualColumn)
Description copied from interface: ColumnTableModelWrapper
Gets the visual column index representing the specified actual column.

Specified by:
getVisualColumnAt in interface ColumnTableModelWrapper
Returns:
the visual column index. -1 if there is no visual column representing it.

isDisplayGroupColumns

public boolean isDisplayGroupColumns()
Gets the flag indicating if the GroupTable should display group columns.

By default, the value is false to not show the group columns.

Specified by:
isDisplayGroupColumns in interface GroupModelProvider
Returns:
true if the GroupTable should display group columns. Otherwise false.

groupColumnsFirst

public boolean groupColumnsFirst()
Description copied from interface: GroupModelProvider
Gets the flag indicating if group columns should always be displayed at the begging when displayed.

Specified by:
groupColumnsFirst in interface GroupModelProvider
Returns:
true if the group columns should be displayed in the beginning in the native table header. Otherwise false.

setDisplayGroupColumns

public void setDisplayGroupColumns(boolean displayGroupColumns)
Sets the flag indicating if the GroupTable should display group columns.

Parameters:
displayGroupColumns - the flag
See Also:
isDisplayGroupColumns()

isDisplaySeparateGroupColumn

public boolean isDisplaySeparateGroupColumn()
Gets the flag indicating if a separate group column should be created to represent the grouped columns.

By default, the value is false to not show the separate group column. This flag only takes effect while isDisplayGroupColumns() returns false and isKeepColumnOrder() returns false.

Returns:
true if a separate group column is displayed. Otherwise false.
See Also:
setDisplayGroupColumns(boolean), setKeepColumnOrder(boolean)

setDisplaySeparateGroupColumn

public void setDisplaySeparateGroupColumn(boolean displaySeparateGroupColumn)
Sets the flag indicating if a separate group column should be created to represent the grouped columns.

Parameters:
displaySeparateGroupColumn - the flag
See Also:
isDisplaySeparateGroupColumn()

getCountColumnName

protected String getCountColumnName()
Gets the column name for the count column.

Returns:
the column name. By default "Count".
Since:
3.4.6

getSeparateGroupColumnName

protected String getSeparateGroupColumnName()
Gets the column name for the separate group column.

Returns:
the column name. By default "Grouped Columns".

isDisplayCountColumn

public boolean isDisplayCountColumn()
Gets the flag indicating if a separate count column should be created to represent the count.

By default, the value is false to not show the separate count column. This flag only takes effect while isDisplayGroupColumns() returns true.

Returns:
true if a separate count column is displayed. Otherwise false.
See Also:
setDisplayGroupColumns(boolean)

setDisplayCountColumn

public void setDisplayCountColumn(boolean displayCountColumn)
Sets the flag indicating if a separate count column should be created to represent the count.

Parameters:
displayCountColumn - the flag
See Also:
isDisplayCountColumn()

expandRow

public void expandRow(ExpandableRow row,
                      boolean expanded)
Description copied from class: TreeTableModel
Expands or collapses the row.

Overrides:
expandRow in class TreeTableModel
Parameters:
row - the row to be expanded or collapsed
expanded - true to expand, false to collapse.

expandAll

public void expandAll()
Description copied from class: TreeTableModel
Expands all rows which have children.

Overrides:
expandAll in class TreeTableModel

expandAll

protected void expandAll(boolean fireDataChangedEvent)
Expands all rows.

Parameters:
fireDataChangedEvent - the flag to indicating if a data changed event should be fired after expanding all.

expandFirstLevel

public void expandFirstLevel()
Description copied from class: TreeTableModel
Expands all root level rows.

Overrides:
expandFirstLevel in class TreeTableModel

collapseAll

public void collapseAll()
Description copied from class: TreeTableModel
Collapse all rows which have children.

Overrides:
collapseAll in class TreeTableModel

collapseFirstLevel

public void collapseFirstLevel()
Description copied from class: TreeTableModel
Collapses all top level rows only. The children level rows are still expanded if they were. But they can't be seen anymore as the root rows are collapsed. If you expand the root rows after this call, you will see the children rows remain expanded.

Overrides:
collapseFirstLevel in class TreeTableModel

expandGroupColumn

public void expandGroupColumn(int groupColumnIndex)
Expand all rows that corresponding to the group column.

Parameters:
groupColumnIndex - the group column index
Since:
3.3.1

collapseGroupColumn

public void collapseGroupColumn(int groupColumnIndex)
Collapse all rows that corresponding to the group column.

Parameters:
groupColumnIndex - the group column index
Since:
3.3.1

sort

protected void sort(int[] from,
                    int[] to,
                    int low,
                    int high)
Sorts the rows.

Subclass can override this method to implement their own algorithm to sort. When doing comparison in the algorithm, use the compare(int, int) method defined in this class.

Parameters:
from - an int array of row indices to be sorted
to - an int array of row indices to store the result after sorting
low - the start index of the row in the array to be sorted
high - the end index of the row in the array to be sorted

compare

protected int compare(int row1,
                      int row2)
Compares two rows.

Parameters:
row1 - the first row index
row2 - the second row index
Returns:
0 if the order of those two rows doesn't matter. -1 to keep current order. 1 to switch those two rows.

compare

protected int compare(Object o1,
                      Object o2,
                      int column)
Compares two objects in a column.

Parameters:
o1 - the first object
o2 - the second object
column - the column index
Returns:
0 if the order of those two objects doesn't matter. -1 to keep current order. 1 to switch those two objects.

cacheComparators

protected void cacheComparators()
For performance, all comparators for each column should be cached first.


getComparator

public Comparator getComparator(int columnIndex)
Gets the column comparator. Subclass can override it to return a comparator for a particular column. By default, SortableTableModel will look up for a comparator from ObjectComparatorManager based on getColumnClass return value and getColumnComparatorContext return value. Please note, for the performance reason, if both objects are Comparable of the same type, we will use Comparable#compareTo method to compare the two objects. Then we will use the Comparator. If you want to always use Comparator to compare, you can call setAlwaysUseComparators(boolean) and set it to true.

Parameters:
columnIndex - the column index in the actual table model. It's NOT the column index in the group table model.
Returns:
the comparator for the specified column.

getColumnComparatorContext

protected ComparatorContext getColumnComparatorContext(int column)
Gets the column comparator context. Subclass can override it to return a comparator context. By default it will return null. It should only be used when the column class for two columns are the same but you want to compare them differently. First you need to register two different comparators using ObjectComparatorManager using different comparator context in ObjectComparatorManager.registerComparator(Class, java.util.Comparator, com.jidesoft.comparator.ComparatorContext) method. Then return the corresponding context when overriding this method.

We also add a setter for this. You can call setColumnComparatorContextProvider(com.jidesoft.grid.DefaultGroupTableModel.ColumnComparatorContextProvider) to provide a ColumnComparatorContextProvider. This provider will return a ComparatorContext for each column. This will be helpful when it's hard to override SortableTableModel.

Parameters:
column - the column index in the actual table model. It's NOT the column index in the group table model.
Returns:
the comparator context for the column.

isRemoveNullGrouper

public boolean isRemoveNullGrouper()
Gets the flag indicating if the row will be moved to upper level if the last grouper values are null.

Returns:
true if the row will be moved to upper level. Otherwise false.
See Also:
setRemoveNullGrouper(boolean)

setRemoveNullGrouper

public void setRemoveNullGrouper(boolean removeNullGrouper)
Sets the flag indicating if the row will be moved to upper level if the last grouper values are null.

The default value is false to keep original behavior.

Parameters:
removeNullGrouper - the flag

isDisplayGroupRowsFirst

public boolean isDisplayGroupRowsFirst()
Gets the flag indicating if the group rows will be put ahead of the other reference rows when isRemoveNullGrouper() returns true.

Returns:
true if the group rows will be laid out first. Otherwise false.
Since:
3.5.0
See Also:
setDisplayGroupRowsFirst(boolean)

setDisplayGroupRowsFirst

public void setDisplayGroupRowsFirst(boolean groupRowsFirst)
Sets the flag indicating if the group rows will be put ahead of the other reference rows when isRemoveNullGrouper() returns true.

The default value is false to keep backward compatibility. This method would only take effect if isRemoveNullGrouper() returns true.

Parameters:
groupRowsFirst - the flag
Since:
3.5.0
See Also:
isRemoveNullGrouper()

getColumnComparatorContextProvider

public DefaultGroupTableModel.ColumnComparatorContextProvider getColumnComparatorContextProvider()
Gets the ColumnComparatorContextProvider.

Returns:
the ColumnComparatorContextProvider.

setColumnComparatorContextProvider

public void setColumnComparatorContextProvider(DefaultGroupTableModel.ColumnComparatorContextProvider columnComparatorContextProvider)
Sets the ColumnComparatorContextProvider. This provider will provide a ComparatorContext for each column. If this table model has several columns that have the same types in getColumnClass method but you want to use different comparators to compare and sort them, you would need to register several comparators on ObjectComparatorManager using different ComparatorContext. Then you can this provider to return different contexts so that SortableTableModel can find the correct comparator registered on ObjectComparatorManager. If you call this method with a non-null provider, we will automatically call setAlwaysUseComparators(boolean) and set it to true.

Parameters:
columnComparatorContextProvider - the columnComparatorContextProvider

isAlwaysUseComparators

public boolean isAlwaysUseComparators()
Checks if the alwaysUseComparators flag value.

Returns:
true if alwaysUseComparators is true. Otherwise false.

setAlwaysUseComparators

public void setAlwaysUseComparators(boolean alwaysUseComparators)
Sets the alwaysUseComparators flag. By default, we will check if the two values are Comparable. If they both are, we will use Comparable.compareTo(Object) to compare. This is the default preferred way because this gives developer a finer control of the comparison result. People also sometimes forgot to implement getColumnClass and getColumnComparatorContext. If so, a wrong comparator could be used. If this flag is set to true, we will always use Comparators to compare which you means you must implement getColumnClass and optionally implement getColumnComparatorContext or use setColumnComparatorContextProvider(com.jidesoft.grid.DefaultGroupTableModel.ColumnComparatorContextProvider) so that the correct comparator will be used for each column.

Parameters:
alwaysUseComparators - true or false.

getExpansionState

public Map<Object,Boolean> getExpansionState()
Description copied from class: TreeTableModel
Gets the expansion state of all expansion state of tree table model. You can use this method along with TreeTableModel.setExpansionState(java.util.Map) to restore the tree table expansion state after the TreeTableModel is recreated.

Overrides:
getExpansionState in class TreeTableModel
Returns:
a map contains the expansion state of all rows. To save memory, we only save the expanded tree path so far.

setExpansionState

public void setExpansionState(Map state)
Description copied from class: TreeTableModel
Restores the expansion state of all rows in tree table model. You can use this method to restore the expansion state after the TreeTableModel is created but rows remain. For newly added rows, this method will not change their expansion state.

Overrides:
setExpansionState in class TreeTableModel
Parameters:
state - a map of the expansion state.

getEditorStyleAt

public int getEditorStyleAt(int rowIndex,
                            int columnIndex)
Description copied from interface: EditorStyleTableModel
Gets editor style at the cell.

Specified by:
getEditorStyleAt in interface EditorStyleTableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
the editor style.

isAscendingGroupOrder

@Deprecated
public boolean isAscendingGroupOrder()
Deprecated. replaced by addGroupColumn(int, int), sorting is the second parameter.

While grouping, the rows are sorted first according the grouping columns. You could use this method to get current sorting direction.

Returns:
true if the sorting is ascending, false if the sorting is descending.

setAscendingGroupOrder

@Deprecated
public void setAscendingGroupOrder(boolean order)
Deprecated. replaced by addGroupColumn(int, int), sorting is the second parameter.

While grouping, the rows are sorted first according the grouping columns. You could use this method to set current sorting direction.

Parameters:
order - true to make later sorting ascending, false to make later sorting descending.

isKeepPreviousExpandStatus

public boolean isKeepPreviousExpandStatus()
Gets the flag indicating if the previous expand status should be kept on data changing, adding/removing group columns.

Returns:
true if previous expand status should be kept. Otherwise false.
See Also:
setKeepPreviousExpandStatus(boolean)

setKeepPreviousExpandStatus

public void setKeepPreviousExpandStatus(boolean keepPreviousExpandStatus)
Sets the flag indicating if the previous expand status should be kept on data changing, adding/removing group columns.

This flag has higher priority of TreeTableModel.setAutoExpand(boolean), which means if the new group row could be found in previous status, it will take the expand status from auto expanding.

By default, the flag is true. You could set it to false to return to original behavior.

Parameters:
keepPreviousExpandStatus - the flag

isKeepGroupingOnStructureChange

public boolean isKeepGroupingOnStructureChange()
Gets the flag indicating if previous grouping columns should be kept on receiving table structure changed event.

Returns:
true if previous grouping should be kept. Otherwise false.
See Also:
setKeepGroupingOnStructureChange(boolean)

setKeepGroupingOnStructureChange

public void setKeepGroupingOnStructureChange(boolean keepGroupingOnStructureChange)
Sets the flag indicating if previous grouping columns should be kept on receiving table structure changed event.

By default, the flag is false. You could set it to true to return to original behavior.

Parameters:
keepGroupingOnStructureChange - the flag

JIDE 3.5.15