JIDE 3.5.15

com.jidesoft.pivot
Class HeaderTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.pivot.HeaderTableModel
All Implemented Interfaces:
ColumnIdentifierTableModel, ContextSensitiveTableModel, SpanModel, StyleModel, PivotConstants, Serializable, TableModel
Direct Known Subclasses:
CalculatedHeaderTableModel

public class HeaderTableModel
extends AbstractTableModel
implements ColumnIdentifierTableModel, SpanModel, ContextSensitiveTableModel, PivotConstants, StyleModel

TableModel for the row header and column header of the pivot table.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.pivot.PivotConstants
AREA_COLUMN, AREA_DATA, AREA_FILTER, AREA_NAMES, AREA_NOT_ASSIGNED, AREA_ROW, COMPARE_TO_NEXT, COMPARE_TO_PREVIOUS, HEADER_SELECTION_DATA_TABLE_ONLY, HEADER_SELECTION_HEADER_TABLE_ONLY, RANGE_IN_TOTAL, RUNNING_SUMMARY_DIFFERENCE, RUNNING_SUMMARY_PERCENTAGE_FROM, RUNNING_SUMMARY_PERCENTAGE_OF, RUNNING_SUMMARY_PERCENTAGE_TOTAL, RUNNING_SUMMARY_TOTAL, STATISTICS_CALCULATION_DEFAULT, STATISTICS_CALCULATION_RUNNING, STATISTICS_CALCULATION_RUNNING_IN_COLUMN, STATISTICS_CALCULATION_RUNNING_LEAF, SUBTOTAL_AUTOMATIC, SUBTOTAL_CUSTOM, SUBTOTAL_NONE, SUMMARY_COUNT, SUMMARY_CUSTOM, SUMMARY_MAX, SUMMARY_MEAN, SUMMARY_MIN, SUMMARY_NAMES, SUMMARY_NONE, SUMMARY_RESERVED_MAX, SUMMARY_STDDEV, SUMMARY_SUM, SUMMARY_VAR
 
Constructor Summary
HeaderTableModel(IPivotDataModel pivotDataModel, CompoundKey[] rows, boolean rowHeader)
           
 
Method Summary
 void collapse(int index)
           
 void collapse(int rowIndex, int columnIndex)
          Collapses the cell at the specified row and column index is expandable.
 void collapseAll()
          Collapses all expandable level cells.
 void collapseAll(int[] noActionFieldIndices)
          Collapses all expandable level cells without touching those PivotFields in the array.
protected  List<Values> createList()
          Creates the List used internally.
 void expand(int index)
          Expands the whole column if if it is the row header or expands the whole row if it is the column header.
 void expand(int rowIndex, int columnIndex)
          Expands the cell at the specified row and column index is expandable.
 void expandAll()
          Expands all expandable cells.
 void expandAll(int[] noActionFieldIndices)
          Expands all expandable level cells without touching those PivotFields in the array.
 void fireTableStructureChanged()
           
 Class getCellClassAt(int row, int column)
          Gets the type at cell (row, column).
 CellSpan getCellSpanAt(int rowIndex, int columnIndex)
          Gets the cell span at the specified row and column.
 CellStyle getCellStyleAt(int rowIndex, int columnIndex)
          Gets the cell style at the specified cell.
 int getColumnCount()
          Gets the column count.
 Object getColumnIdentifier(int columnIndex)
          Returns the identifier of the column in the model.
 String getColumnName(int column)
           
 ConverterContext getConverterContextAt(int row, int column)
          Gets the converter context at cell (row, column).
 EditorContext getEditorContextAt(int row, int column)
          Gets the editor context at cell (row, column).
 Expandable getExpandable(int rowIndex, int columnIndex)
          Gets the Expandable object at specified row index and column index.
 Map<String,Boolean> getExpansionState()
          Gets the expansion sate of the HeaderTableModel.
 PivotField getFieldAt(int rowIndex, int columnIndex)
          Gets the pivot field associated with the cell.
 Object[] getKeyValuesAt(int index)
           
protected  int getNumberOfDataFields()
           
 IPivotDataModel getPivotDataModel()
          Gets the pivot data model.
 int getRowCount()
          Gets the row count.
 Class<?> getRowValueClass(int rowIndex)
           
 int getSummaryColumn(int rowIndex)
           
 int getSummaryType(int rowIndex)
           
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 String getValueAtInString(Locale locale, int rowIndex, int columnIndex)
          Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.
 String getValueAtInString(Locale locale, Object value, int rowIndex, int columnIndex)
          Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.
 String getValueAtInString(PivotTablePane pane, int rowIndex, int columnIndex)
          Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.
 String getValueAtInString(PivotTablePane pane, Object value, int rowIndex, int columnIndex)
          Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.
 Values getValuesAt(int index)
          Returns the Values at the row specified by row.
 int indexOf(Object[] keys)
          Index of the Objects in the HeaderTableModel.
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 boolean isCellSpanOn()
          Checks if the cell span is on for this table model.
 boolean isCellStyleOn()
          Checks if the style is on.
 boolean isCollapsed(int rowIndex, int columnIndex)
          Checks if the cell at the specified row and column index is collapsed.
 boolean isDataCell(int rowIndex, int columnIndex)
           
protected  boolean isDataFieldAdded()
          Should date fields added to this field table model.
 boolean isExpandable(int rowIndex, int columnIndex)
          Checks if the cell at the specified row and column index is expandable.
 boolean isExpanded(int rowIndex, int columnIndex)
          Checks if the cell at the specified row and column index is expanded.
 boolean isGrandTotalRowOrColumn(int index)
          Checks if the row or column at the index is a grand total row or column.
 boolean isRowHeader()
          Checks if the table model is for row header.
 boolean isRunningSummaryRowOrColumn(int index)
          Checks if the row or column at the index is a running summary row or column.
 boolean isSubtotalRowOrColumn(int index)
          Checks if the row or column at the index is a sub total row or column.
 void refreshAfterUpdateExpandable(int oldColumnCount)
          Refresh the header table model after updating expandable.
 void setCellSpanOn(boolean cellSpanOn)
          Sets the cell span on or off.
 void setExpansionState(Map<String,Boolean> expandedMap)
          Sets the expansion state.
protected  void setRows(CompoundKey[] rows)
           
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
           
protected  void setValueExpanded(Expandable value, boolean expanded)
          Update the value's expandable status.
protected  boolean shouldOptimize(int changedKeyCount, int totalKeyCount)
          Check if the refresh process should be optimized.
 void toggle(int rowIndex, int columnIndex)
          Toggles the cell at the specified row and column index is expandable.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, getColumnClass, 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, removeTableModelListener
 

Constructor Detail

HeaderTableModel

public HeaderTableModel(IPivotDataModel pivotDataModel,
                        CompoundKey[] rows,
                        boolean rowHeader)
Parameters:
pivotDataModel - the PivotDataModel.
rows - the compound keys.
rowHeader - true if it is the row header. False if it is the column header.
Method Detail

shouldOptimize

protected boolean shouldOptimize(int changedKeyCount,
                                 int totalKeyCount)
Check if the refresh process should be optimized.

The default implementation is check if changed compound key count is not more than 10.

Parameters:
changedKeyCount - changed CompoundKey counts
totalKeyCount - the total CompoundKey counts
Returns:
true if the process should be optimized. Otherwise false.

setRows

protected void setRows(CompoundKey[] rows)

getNumberOfDataFields

protected int getNumberOfDataFields()

refreshAfterUpdateExpandable

public void refreshAfterUpdateExpandable(int oldColumnCount)
Refresh the header table model after updating expandable.

By default, this method will recreate the table model and fire table data change or structure change event according to the scope which was impacted.

This is a single point method for any kind of collapse/expand, which means, you could override this method to customize your behavior upon expanding/collapsing. When this method is invoked, all expandable have been updated.

Parameters:
oldColumnCount - the column count before updating

setValueExpanded

protected void setValueExpanded(Expandable value,
                                boolean expanded)
Update the value's expandable status.

This is a single point method for any kind of collapse/expand, which means, you could override this method to customize your behavior upon expanding/collapsing. Comparing to refreshAfterUpdateExpandable(int), when this method is invoked, the expandable has not been updated. However, this method could be invoked many times if collapseAll() or expandAll() is invoked.

Parameters:
value - the expandable value
expanded - the new expanded status

fireTableStructureChanged

public void fireTableStructureChanged()
Overrides:
fireTableStructureChanged in class AbstractTableModel

createList

protected List<Values> createList()
Creates the List used internally. By default, we created CachedArrayList instance so that we get a faster indexOf performance.

Returns:
a List.

isRowHeader

public boolean isRowHeader()
Checks if the table model is for row header.

Returns:
true if the table model is for row header.

getRowCount

public int getRowCount()
Gets the row count.

Specified by:
getRowCount in interface TableModel
Returns:
the row count.

getColumnIdentifier

public Object getColumnIdentifier(int columnIndex)
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:
columnIndex - the index of the column
Returns:
the unique identifier of the column.

getColumnName

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

getColumnCount

public int getColumnCount()
Gets the column count.

Specified by:
getColumnCount in interface TableModel
Returns:
the column count.

getValuesAt

public Values getValuesAt(int index)
Returns the Values at the row specified by row.

Parameters:
index - the row whose row is to be queried
Returns:
the row at the specified row index

getKeyValuesAt

public Object[] getKeyValuesAt(int index)

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface TableModel
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

getRowValueClass

public Class<?> getRowValueClass(int rowIndex)

getSummaryType

public int getSummaryType(int rowIndex)

getSummaryColumn

public int getSummaryColumn(int rowIndex)

getExpandable

public Expandable getExpandable(int rowIndex,
                                int columnIndex)
Gets the Expandable object at specified row index and column index.

Parameters:
rowIndex - the row index of the cell.
columnIndex - the column index of the cell
Returns:
expandable.

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.

setCellSpanOn

public void setCellSpanOn(boolean cellSpanOn)
Sets the cell span on or off.

Parameters:
cellSpanOn - true or false.

isCellSpanOn

public boolean isCellSpanOn()
Checks if the cell span is on for this table model.

Specified by:
isCellSpanOn in interface SpanModel
Returns:
true or false.

getFieldAt

public PivotField getFieldAt(int rowIndex,
                             int columnIndex)
Gets the pivot field associated with the cell.

Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
the pivot field associated with the cell.

getConverterContextAt

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

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

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

getEditorContextAt

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

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

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

getCellClassAt

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

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

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

isExpandable

public boolean isExpandable(int rowIndex,
                            int columnIndex)
Checks if the cell at the specified row and column index is expandable.

Parameters:
rowIndex - the row index of the cell
columnIndex - the column index of the cell
Returns:
true or false.

isExpanded

public boolean isExpanded(int rowIndex,
                          int columnIndex)
Checks if the cell at the specified row and column index is expanded. It will return true only when it has children and expanded. If it doesn't have children, it will return false.

Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
true or false.

isCollapsed

public boolean isCollapsed(int rowIndex,
                           int columnIndex)
Checks if the cell at the specified row and column index is collapsed. It will return true only when it has children and not expanded. If it doesn't have children, it will return false.

Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
true or false.

expand

public void expand(int rowIndex,
                   int columnIndex)
Expands the cell at the specified row and column index is expandable.

Parameters:
rowIndex - the row index.
columnIndex - the column index.

expand

public void expand(int index)
Expands the whole column if if it is the row header or expands the whole row if it is the column header.

Parameters:
index - the row index if it is the column header or the column index if it is the row header.

collapse

public void collapse(int index)

collapse

public void collapse(int rowIndex,
                     int columnIndex)
Collapses the cell at the specified row and column index is expandable.

Parameters:
rowIndex - the row index.
columnIndex - the column index.

toggle

public void toggle(int rowIndex,
                   int columnIndex)
Toggles the cell at the specified row and column index is expandable.

Parameters:
rowIndex - the row index.
columnIndex - the column index.

expandAll

public void expandAll()
Expands all expandable cells.


expandAll

public void expandAll(int[] noActionFieldIndices)
Expands all expandable level cells without touching those PivotFields in the array.

Parameters:
noActionFieldIndices - those fields that should not be collapsed

collapseAll

public void collapseAll()
Collapses all expandable level cells.


collapseAll

public void collapseAll(int[] noActionFieldIndices)
Collapses all expandable level cells without touching those PivotFields in the array.

Parameters:
noActionFieldIndices - those fields that should not be collapsed

isDataFieldAdded

protected boolean isDataFieldAdded()
Should date fields added to this field table model.

Returns:
true or false.

isDataCell

public boolean isDataCell(int rowIndex,
                          int columnIndex)

getCellStyleAt

public final CellStyle getCellStyleAt(int rowIndex,
                                      int columnIndex)
Gets the cell style at the specified cell. This method is final. Please use PivotDataModel.setCellStyleProvider(PivotCellStyleProvider) to provide cell style for HeaderTable.

Specified by:
getCellStyleAt in interface StyleModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
the cell style at the specified cell.

isCellStyleOn

public final boolean isCellStyleOn()
Description copied from interface: StyleModel
Checks if the style is on. The CellStyleTable will ignore all the CellStyles defined in this model if this method returns false.

Specified by:
isCellStyleOn in interface StyleModel
Returns:
true if style is on. Otherwise false.

isRunningSummaryRowOrColumn

public boolean isRunningSummaryRowOrColumn(int index)
Checks if the row or column at the index is a running summary row or column.

Parameters:
index - the row index if the HeaderTableModel is used in row header of the pivot table. If the HeaderTableModel is used as column header, the rowIndex should be the column index.
Returns:
true if the row or column at the index is a sub total row or column.

isSubtotalRowOrColumn

public boolean isSubtotalRowOrColumn(int index)
Checks if the row or column at the index is a sub total row or column.

Parameters:
index - the row index if the HeaderTableModel is used in row header of the pivot table. If the HeaderTableModel is used as column header, the rowIndex should be the column index.
Returns:
true if the row or column at the index is a sub total row or column.

isGrandTotalRowOrColumn

public boolean isGrandTotalRowOrColumn(int index)
Checks if the row or column at the index is a grand total row or column.

Parameters:
index - the row index if the HeaderTableModel is used in row header of the pivot table. If the HeaderTableModel is used as column header, the rowIndex should be the column index.
Returns:
true if the row or column at the index is a grant total row or column.

getPivotDataModel

public IPivotDataModel getPivotDataModel()
Gets the pivot data model.

Returns:
the pivot data model.

setValueAt

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

isCellEditable

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

indexOf

public int indexOf(Object[] keys)
Index of the Objects in the HeaderTableModel. In the case of row HeaderTableModel, the index will be the row index. In the case of column HeaderTableModel, the index will be the column index.

Parameters:
keys - the Objects array
Returns:
the index.

getValueAtInString

@Deprecated
public String getValueAtInString(PivotTablePane pane,
                                            int rowIndex,
                                            int columnIndex)
Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.

Gets the string value with summary name or the total/grand total. For example, if the stringValue parameter is "Aug", this method will return "Aug Sum" if the cell is a subtotal row/column of "Sum". If the cell is a grand total row or column, this method will return "Grand Total" which is defined in pivot.properties.

This method will invoke getValueAt first to get the value, then invoke getValueAtInString(PivotTablePane, Object, int, int)

Parameters:
pane - the PivotTablePane
rowIndex - the row index of the cell
columnIndex - the column index of the cell
Returns:
the string including the summary, total or grand total.

getValueAtInString

@Deprecated
public String getValueAtInString(Locale locale,
                                            int rowIndex,
                                            int columnIndex)
Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.

Gets the string value with summary name or the total/grand total. For example, if the stringValue parameter is "Aug", this method will return "Aug Sum" if the cell is a subtotal row/column of "Sum". If the cell is a grand total row or column, this method will return "Grand Total" which is defined in pivot.properties.

This method will invoke getValueAt first to get the value, then invoke getValueAtInString(PivotTablePane, Object, int, int)

Parameters:
locale - the locale to get the correct string.
rowIndex - the row index of the cell
columnIndex - the column index of the cell
Returns:
the string including the summary, total or grand total.

getValueAtInString

@Deprecated
public String getValueAtInString(PivotTablePane pane,
                                            Object value,
                                            int rowIndex,
                                            int columnIndex)
Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.

Gets the string value with summary name or the total/grand total. For example, if the stringValue parameter is "Aug", this method will return "Aug Sum" if the cell is a subtotal row/column of "Sum". If the cell is a grand total row or column, this method will return "Grand Total" which is defined in pivot.properties.

Parameters:
pane - the PivotTablePane
value - the value
rowIndex - the row index of the cell
columnIndex - the column index of the cell
Returns:
the string including the summary, total or grand total.

getValueAtInString

@Deprecated
public String getValueAtInString(Locale locale,
                                            Object value,
                                            int rowIndex,
                                            int columnIndex)
Deprecated. replaced by HeaderTable.getValueAtInString(int, int, com.jidesoft.hssf.HssfTableUtils.CellValueConverter) in PivotTablePane scenario or AggregateTable.getValueAtInString(int, int, com.jidesoft.grid.ValueConverter) in AggregateTable scenario.

Gets the string value with summary name or the total/grand total. For example, if the stringValue parameter is "Aug", this method will return "Aug Sum" if the cell is a subtotal row/column of "Sum". If the cell is a grand total row or column, this method will return "Grand Total" which is defined in pivot.properties.

Parameters:
locale - the locale to get the correct string.
value - the value
rowIndex - the row index of the cell
columnIndex - the column index of the cell
Returns:
the string including the summary, total or grand total.

getExpansionState

public Map<String,Boolean> getExpansionState()
Gets the expansion sate of the HeaderTableModel. You can call it to save it somewhere. After the header table is changed (reloaded for example), you can call setExpansionState(java.util.Map) to restore the expansion state.

In high performance mode, it will always return null to avoid going through the tree hierarchy.

Returns:
the expansion state in a map.

setExpansionState

public void setExpansionState(Map<String,Boolean> expandedMap)
Sets the expansion state.

Parameters:
expandedMap - the expansion state.

JIDE 3.5.15