JIDE 3.5.15

com.jidesoft.pivot
Class PivotDataModel

java.lang.Object
  extended by com.jidesoft.pivot.PivotDataModel
All Implemented Interfaces:
IPivotDataModel, PivotConstants, PivotValueProvider
Direct Known Subclasses:
AggregateTableModel.AggregateTablePivotDataModel, CalculatedPivotDataModel

public class PivotDataModel
extends Object
implements IPivotDataModel, PivotValueProvider

The model that contains the data for pivot table. It takes any table model as input. Then you can getField(String) method to get the PivotField to specify different settings such as which ones are row fields, column fields, filter fields or data fields, do you want to calculate subtotals, the sort order. There are also a few settings on PivotDataModel itself such as grand total. Once you setup everything, you can call calculate() to generate pivot data.


Nested Class Summary
static interface PivotDataModel.RowMerger
          An interface to merge the rows when they have the same row and column fields.
 
Field Summary
protected  PivotDataSource _dataSource
           
protected  EventListenerList listenerList
           
static String PROPERTY_HIDE_REDUNDANT_SUBTOTAL
           
static String PROPERTY_HIDE_SINGLE_DATA_FIELD
           
static String PROPERTY_SHOW_GRAND_TOTAL_FOR_COLUMN
           
static String PROPERTY_SHOW_GRAND_TOTAL_FOR_ROW
           
static String PROPERTY_SHOW_SUBTOTAL_AS_CHILD
           
 
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
PivotDataModel()
           
PivotDataModel(PivotDataSource dataSource)
          Creates a PivotDataModel using PivotDataSource interface.
PivotDataModel(TableModel tableModel)
          Creates a PivotDataModel using table model as the data source.
 
Method Summary
 void addHiddenColumn(Values values, PivotField field)
          Adds the designated column defined by values and PivotField to the hidden values.
 void addHiddenColumn(Values values, PivotField dataField, String width)
          Adds the designated column defined by values and PivotField to the hidden values.
 void addHiddenValues(Values values)
          Adds the values to the hidden values.
 void addPivotValueProviderListener(PivotValueProviderListener l)
          Add PivotValueProviderListener so that the listener could know when calculation starts or ends.
protected  boolean addPrefixRowIndex(CompoundKey rowKey, CompoundKey columnKey, int rowIndex)
           
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
protected  boolean addRowIndex(CompoundKey rowKey, CompoundKey columnKey, int rowIndex)
           
 void calculate()
          Calculates the pivot data.
protected  Object calculateStatistics(PivotField field, int rowIndex, int columnIndex, int summaryType, Object[] objects)
          Deprecated. replaced by calculateStatistics(PivotField, Values, Values, int, Object[])
protected  Object calculateStatistics(PivotField field, Values rowValues, Values columnValues, int summaryType, Object[] objects)
          Calculate statistics for the cell with the same rowValues and the same columnValues in DataTable.
 void clearHiddenColumns()
          Clears the hidden columns.
 void clearHiddenValues()
          Clears the hidden values.
protected  Object[] collectValuesForCell(PivotField field, int rowIndex, int columnIndex, int summaryType)
           
protected  Object[] collectValuesForCell(PivotField field, Values rowKeys, Values columnKeys, int summaryType)
           
protected  HeaderTableModel createColumnHeaderTableModel(CompoundKey[] keys)
          Creates the column header table model.
protected  DataTableModel createDataTableModel()
          Creates DataTableModel.
protected  TableModelPivotDataSource createDefaultPivotDataSource(TableModel tableModel)
          Creates default PivotDataSource which is TableModelPivotDataSource.
protected  com.jidesoft.pivot.PivotDataCube createPivotDataCube()
           
protected  PivotField createPivotField(PivotDataSource dataSource, int columnIndex)
          Creates the PivotField.
protected  HeaderTableModel createRowHeaderTableModel(CompoundKey[] keys)
          Creates the row header table model.
 void firePivotValueProviderChanged(int type)
           
 void firePivotValueProviderChanged(int type, Object object)
           
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Support for reporting property changes for boolean properties.
 void forceCalculate()
          Ask PivotValueProvider to start calculate.
 PivotCellStyleProvider getCellStyleProvider()
          Gets the PivotCellStyleProvider.
 int getColumnAt(int actualRow)
          Gets the closest column index in DataTable that includes the actual row index in the original table model.
 int[] getColumnFieldIndices()
          Gets the model indices for the column fields.
 PivotField[] getColumnFields()
          Gets the column fields.
 int getColumnHeaderColumnIndexAt(int rowIndex)
          Gets the column index in the column header table which has the data from the original table model at the specified rowIndex.
 PivotDataEditingProvider getColumnHeaderEditingProvider()
          Gets the PivotDataEditingProvider for the column header table.
 HeaderTableModel getColumnHeaderTableModel()
          Gets the column header table model.
 CompoundKey[] getColumnKeys()
          Get column key array.
protected  CompoundKey getCompoundKeyAt(int rowIndex, int areaType)
          Gets the designated compound key from the row index in the data source.
 TableModel getCornerTableModel()
          Gets the corner table model.
 List<Integer> getDataAt(CompoundKey rowKey, CompoundKey columnKey)
          Gets the row index list that matches with the rowKey and columnKey.
 List<Integer> getDataAt(int rowIndex, int columnIndex)
          Gets the row index list at the specified row index and column index.
 PivotDataEditingProvider getDataEditingProvider()
          Gets the PivotDataEditingProvider for the data table.
 int[] getDataFieldIndices()
          Gets the model indices for the data fields.
 PivotField[] getDataFields()
          Gets the data fields.
 PivotDataSource getDataSource()
          Gets the data source.
 TableModel getDataTableModel()
          Gets the data table model.
 PivotField getField(int index)
          Gets the PivotField by the index.
 PivotField getField(String name)
          Gets the PivotField by the name.
protected  int[] getFieldIndices(PivotField[] fields)
           
 PivotField[] getFields()
          Gets all the PivotFields.
 int[] getFilterFieldIndices()
          Gets the model indices for the filter fields.
 PivotField[] getFilterFields()
          Gets the filter fields.
 Object[][] getHiddenColumns()
          Get the hidden columns array.
 Values[] getHiddenValues()
          Gets all the hidden values.
 PivotValueProviderListener[] getPivotValueProviderListeners()
           
 Object[] getPossibleValues(int columnIndex)
          Deprecated. the order of the possible values returned from this method is not clear. Please use getPossibleValues(int, java.util.Comparator) instead. We didn't use this method anymore in our code.
 Object[] getPossibleValues(int columnIndex, Comparator comparator)
          Gets the possible values of the specified columnIndex.
 Object[] getPossibleValues(PivotField field)
          Retrieve the possible values for the designated field.
 int getRowAt(int actualRow)
          Gets the closest row index in DataTable that includes the actual row index in the original table model.
 int[] getRowFieldIndices()
          Gets the model indices for the row fields.
 PivotField[] getRowFields()
          Gets the row fields.
 PivotDataEditingProvider getRowHeaderEditingProvider()
          Gets the PivotDataEditingProvider for the row header table.
 int getRowHeaderRowIndexAt(int rowIndex)
          Gets the row index in the row header table which has the data from the original table model at the specified rowIndex.
 HeaderTableModel getRowHeaderTableModel()
          Gets the row header table model.
 CompoundKey[] getRowKeys()
          Get row key array.
 PivotDataModel.RowMerger getRowMerger()
          Gets the row merger.
 int getStatisticsType(Values rowValues, Values columnValues, PivotField dataField)
          Get the statistics layer.
 SummaryCalculator getSummaryCalculator()
          Gets the statistics calculator used to calculate all the statistics for the pivot data model.
 SummaryCalculatorFactory getSummaryCalculatorFactory()
          Gets the summary calculator factory which will create summary calculator to calculate all the statistics for the pivot data model.
 TableModel getTableModel()
          Gets the table model.
 int[] getUnassignedFieldIndices()
          Gets the model indices for the unassigned fields.
 PivotField[] getUnassignedFields()
          Gets the unassigned fields.
 Object getValueAt(PivotField field, Values rowKeys, Values columnKeys)
          Get the value to be compared.
protected  void handleFieldPropertyEvent(PropertyChangeEvent evt)
           
 boolean hasHiddenColumns()
          Checks if there are hidden columns.
 boolean hasHiddenValues()
          Checks if there are hidden values.
 void initialize()
          Initializes the PivotDataModel.
 void invalidateColumnHeaderTableModel()
          Invalidate column header table model before calculate.
 void invalidateCornerTableModel()
          Invalidate corner table model before calculate.
 void invalidateDataTableModel()
          Invalidate data table model before calculate.
 void invalidateRowHeaderTableModel()
          Invalidate row header table model before calculate.
 boolean isAdjusting()
          Checks if the PivotDataModel is adjusting.
 boolean isAggregateMode()
          Checks if the pivot data model works in aggregate mode.
 boolean isAllowEmptyColumnHeader()
          Gets the flag if empty headers are allowed.
 boolean isAllowEmptyRowHeader()
          Gets the flag if empty headers are allowed.
 boolean isAlwaysColumnDataFields()
          Checks if the data fields will always displayed on the column header area.
 boolean isAlwaysRowDataFields()
          Is the data field always displayed on the row header area.
 boolean isAutoSortKeys()
          Checks whether the CompoundKeys automatically are sorted.
 boolean isAutoUpdate()
          Checks if the pivot data will be automatically updated when the underlying table model data changes.
 boolean isCalculated()
          Checks if calculate() is called on this pivot data model.
 boolean isCalculating()
          Returns if PivotValueProvider is calculating.
 boolean isColumnDataFields()
          Checks if the data field displayed on the column header area.
 boolean isColumnVisible(Values values, PivotField field)
          Checks if the Values is visible.
 boolean isComputeAffectedCellOnUpdate()
          Get the flag indicating that if the PivotValueProviderEvent will contain the affected cells information on original data model change scenario.
 boolean isDisplayGrandTotalFirst()
          Checks if the grand total is displayed as the first column (row).
 boolean isDisplayGrandTotalFirstForColumn()
          Checks if the grand total is displayed as the first column.
 boolean isDisplayGrandTotalFirstForRow()
          Checks if the grand total is displayed as the first row.
 boolean isExpandByDefault()
          Checks the flag whether the pivot table expands to show all the values.
 boolean isHideExpandIconOnSingleRow()
          Get the flag indicating if the expand/collapse icon will be hidden if there is only one row as its child.
 boolean isHideRedundantSubtotal()
          When the subtotal is configured as automatically and there is only one item, the subtotal is redundant.
 boolean isHideSingleDataField()
           
 boolean isHideSummaryValues()
          Get the flag that indicating if summary values should be hidden if all its children values are hidden.
 boolean isHighPerformanceMode()
          Gets the flag indicating if the IPivotDataModel should work on high performance mode.
 boolean isKeepRowChildrenOnSummaryFilter()
          Get the flag indicating that if all its row children in row header table should be kept if the summary row is kept on data field filter.
 boolean isLayoutDataFieldsFirst()
          Gets the flag indicating if the data field should be laid out in the first level or not.
 boolean isRowDataFields()
          Is the data field displayed on the row header area.
 boolean isShowGrandTotalForColumn()
          Checks if grand total column is visible.
 boolean isShowGrandTotalForRow()
          Checks if grand total row is visible.
 boolean isShowSubtotalAsChild()
          Get the flag.
 boolean isSingleValueMode()
          The cells in the data table are actually summary of multiple rows in the original table model.
 boolean isSummaryLayer()
          Gets the flag indicating if it's a summary layer.
 boolean isSummaryMode()
          Checks if the pivot data model works in summary mode.
static boolean isUseComparable()
          Checks the useComparable flag.
static boolean isValueImmutable()
          Checks the valueImmutable flag.
 boolean isValuesVisible(Values values)
          Checks if the Values is visible.
protected  void manageCompoundKeys()
          Manages CompoundKeys after calculation to fill in some necessary CompoundKeys without adding dummy records in the original table model or removing some unnecessary CompoundKeys without removing records in the original table model.
protected  void removeColumnKey(CompoundKey columnKey)
          Removes the CompoundKey in column header area.
 String removeHiddenColumn(Values values, PivotField field)
          Removes the column from the hidden columns.
 void removeHiddenValues(Values values)
          Removes the values from the hidden values.
 void removePivotValueProviderListener(PivotValueProviderListener l)
          Remove registered PivotValueProviderListener.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
protected  void removeRowKey(CompoundKey rowKey)
          Removes the CompoundKey in row header area.
 void resetDataFields()
          Reset data fields based on the values in every PivotField.
 void setAdjusting(boolean adjusting)
          Sets the PivotDataModel to adjusting mode.
 void setAllowEmptyColumnHeader(boolean allowEmptyColumnHeader)
          Sets the flag if empty column header is allowed.
 void setAllowEmptyRowHeader(boolean allowEmptyRowHeader)
          Sets the flag if empty row header is allowed.
 void setAlwaysColumnDataFields(boolean alwaysColumnDataFields)
          Sets the flag whether the data fields will always be displayed on the column header area.
 void setAlwaysRowDataFields(boolean alwaysRowDataFields)
          Sets the flag whether the data fields will always be displayed on the row header area.
 void setAutoSortKeys(boolean autoSortKeys)
          Sets the flag whether the CompoundKeys should be automatically sorted when calcuate() is called.
 void setAutoUpdate(boolean autoUpdate)
          Sets the flag if the pivot data will be automatically updated when the underlying table model data changes.
 void setCellStyleProvider(PivotCellStyleProvider cellStyleProvider)
          Sets the PivotCellStyleProvider.
 void setColumnHeaderEditingProvider(PivotDataEditingProvider columnHeaderEditingProvider)
          Sets the PivotDataEditingProvider that is used for the column header table.
 void setComputeAffectedCellOnUpdate(boolean computeAffectedCellOnUpdate)
          Set the flag indicating that if the PivotValueProviderEvent will contain the affected cells information on original data model change scenario.
 void setDataEditingProvider(PivotDataEditingProvider dataEditingProvider)
          Sets the PivotDataEditingProvider for the data table.
 void setDataSource(PivotDataSource dataSource)
          Sets the data source.
 void setDisplayGrandTotalFirst(boolean displayGrandTotalFirst)
          Deprecated. replaced by setDisplayGrandTotalFirstForRow(boolean) and setDisplayGrandTotalFirstForColumn(boolean)
 void setDisplayGrandTotalFirstForColumn(boolean displayGrandTotalFirstForColumn)
          By default, grand total is displayed at the last column in the pivot table.
 void setDisplayGrandTotalFirstForRow(boolean displayGrandTotalFirstForRow)
          By default, grand total is displayed at the last row in the pivot table.
 void setExpandByDefault(boolean expandByDefault)
          Sets the flag whether the pivot table should expand to show all the values.
 void setHideExpandIconOnSingleRow(boolean hideExpandIconOnSingleRow)
          Set the flag indicating if the expand/collapse icon will be hidden if there is only one row as its child.
 void setHideRedundantSubtotal(boolean hideRedundantSubtotal)
          Sets the hideRedundantSubtotal flag.
 void setHideSingleDataField(boolean hideSingleDataField)
           
 void setHideSummaryValues(boolean hideSummaryValues)
          Set the flag that indicating if summary values should be hidden if all its children values are hidden.
 void setHighPerformanceMode(boolean highPerformanceMode)
          Sets the flag indicating if the IPivotDataModel should work on high performance mode.
 void setKeepRowChildrenOnSummaryFilter(boolean keepRowChildrenOnSummaryFilter)
          Set the flag indicating that if all its row children in row header table should be kept if the summary row is kept on data field filter.
 void setLayoutDataFieldsFirst(boolean layoutDataFieldsFirst)
          Sets the flag indicating if the data field should be laid out in the first level or not.
 void setOriginalTableModel(TableModel tableModel)
          Sets the original table model.
 void setPivotFields(PivotField[] rowFields, PivotField[] columnFields, PivotField[] dataFields, PivotField[] filterFields)
          Pass fields information to PivotValueProvider for calculation.
 void setRowHeaderEditingProvider(PivotDataEditingProvider rowHeaderEditingProvider)
          Sets the PivotDataEditingProvider that is used for the row header table.
 void setRowMerger(PivotDataModel.RowMerger rowMerger)
          Sets the row merger.
 void setShowGrandTotalForColumn(boolean showGrandTotalForColumn)
          Shows grand total column.
 void setShowGrandTotalForRow(boolean showGrandTotalForRow)
          Shows grand total row.
 void setShowSubtotalAsChild(boolean showSubtotalAsChild)
          By default, the subtotal rows/columns are at the same level as the values.
 void setSingleValueMode(boolean singleValueMode)
          Sets the single value mode.
 void setSummaryCalculator(SummaryCalculator summaryCalculator)
          Sets the statistics calculator.
 void setSummaryCalculatorFactory(SummaryCalculatorFactory summaryCalculatorFactory)
          Sets the statistics calculator factory.
 void setSummaryLayer(boolean summaryLayer)
          Sets the flag indicating if it's a summary layer.
 void setSummaryMode(boolean summaryMode)
          Sets the flag for the summary mode.
static void setUseComparable(boolean useComparable)
          Sets the flag of useComparable.
static void setValueImmutable(boolean valueImmutable)
          Sets the valueImmutable flag.
protected  boolean shouldCalculateSummary(int rowIndex, int columnIndex)
          Check if the cell in the DataTable need calculate summary.
protected  CompoundKey[] sortCompoundKeys(CompoundKey[] keys, PivotField[] fields)
          Sorts the compound keys based on the sort order in the fields.
protected  boolean tableCellsUpdated(int column, int firstRow, int lastRow)
           
protected  boolean tableRowsDeleted(int firstRow, int lastRow)
           
protected  boolean tableRowsInserted(int firstRow, int lastRow)
           
protected  boolean tableRowsUpdated(int firstRow, int lastRow)
           
 void updateFields()
           
protected  void updateFilters()
           
 boolean verify()
          This method is for debugging purpose, not a public API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_dataSource

protected PivotDataSource _dataSource

listenerList

protected EventListenerList listenerList

PROPERTY_SHOW_GRAND_TOTAL_FOR_ROW

public static final String PROPERTY_SHOW_GRAND_TOTAL_FOR_ROW
See Also:
Constant Field Values

PROPERTY_SHOW_GRAND_TOTAL_FOR_COLUMN

public static final String PROPERTY_SHOW_GRAND_TOTAL_FOR_COLUMN
See Also:
Constant Field Values

PROPERTY_HIDE_REDUNDANT_SUBTOTAL

public static final String PROPERTY_HIDE_REDUNDANT_SUBTOTAL
See Also:
Constant Field Values

PROPERTY_SHOW_SUBTOTAL_AS_CHILD

public static final String PROPERTY_SHOW_SUBTOTAL_AS_CHILD
See Also:
Constant Field Values

PROPERTY_HIDE_SINGLE_DATA_FIELD

public static final String PROPERTY_HIDE_SINGLE_DATA_FIELD
See Also:
Constant Field Values
Constructor Detail

PivotDataModel

public PivotDataModel()

PivotDataModel

public PivotDataModel(TableModel tableModel)
Creates a PivotDataModel using table model as the data source.

Parameters:
tableModel - the table model.

PivotDataModel

public PivotDataModel(PivotDataSource dataSource)
Creates a PivotDataModel using PivotDataSource interface.

Parameters:
dataSource - the PivotDataSource.
Method Detail

createPivotDataCube

protected com.jidesoft.pivot.PivotDataCube createPivotDataCube()

initialize

public void initialize()
Initializes the PivotDataModel. Whenever your original table model structured changed (column added, removed or changed), you need to call this method then calculate(). If only the data is changed, just calculate() is enough.

Specified by:
initialize in interface IPivotDataModel

setOriginalTableModel

public void setOriginalTableModel(TableModel tableModel)
Sets the original table model.

Parameters:
tableModel - the new original table model.

createDefaultPivotDataSource

protected TableModelPivotDataSource createDefaultPivotDataSource(TableModel tableModel)
Creates default PivotDataSource which is TableModelPivotDataSource.

Parameters:
tableModel - the table model.
Returns:
TableModelPivotDataSource.

setDataSource

public void setDataSource(PivotDataSource dataSource)
Sets the data source.

Specified by:
setDataSource in interface IPivotDataModel
Parameters:
dataSource - the new data source.

tableCellsUpdated

protected boolean tableCellsUpdated(int column,
                                    int firstRow,
                                    int lastRow)

addRowIndex

protected boolean addRowIndex(CompoundKey rowKey,
                              CompoundKey columnKey,
                              int rowIndex)

addPrefixRowIndex

protected boolean addPrefixRowIndex(CompoundKey rowKey,
                                    CompoundKey columnKey,
                                    int rowIndex)

tableRowsUpdated

protected boolean tableRowsUpdated(int firstRow,
                                   int lastRow)

tableRowsInserted

protected boolean tableRowsInserted(int firstRow,
                                    int lastRow)

tableRowsDeleted

protected boolean tableRowsDeleted(int firstRow,
                                   int lastRow)

createPivotField

protected PivotField createPivotField(PivotDataSource dataSource,
                                      int columnIndex)
Creates the PivotField.

Parameters:
dataSource - the data source.
columnIndex - the column index.
Returns:
the PivotField.

getTableModel

public TableModel getTableModel()
Gets the table model. This is the table model after filtering.

Please note, we introduced PivotDataSource concept in 2.2.2 release. With the help of PivotDataSource, PivotDataModel doesn't have to use TableModel as the data source. Although this method will still return the table model in the default case when the data source is the default TableModelPivotDataSource, it is not guaranteed. If you set your own PivotDataSource which doesn't depend on any table model, this getTableModel will return null.

Returns:
the table model .

getDataSource

public PivotDataSource getDataSource()
Gets the data source.

Specified by:
getDataSource in interface IPivotDataModel
Returns:
the data source.

getField

public PivotField getField(String name)
Gets the PivotField by the name.

Specified by:
getField in interface IPivotDataModel
Parameters:
name - the field name
Returns:
the PivotField by the name.

getField

public PivotField getField(int index)
Gets the PivotField by the index.

Specified by:
getField in interface IPivotDataModel
Parameters:
index - the field index
Returns:
the PivotField by the index.

getFields

public PivotField[] getFields()
Gets all the PivotFields.

Specified by:
getFields in interface IPivotDataModel
Returns:
all the PivotFields.

setPivotFields

public void setPivotFields(PivotField[] rowFields,
                           PivotField[] columnFields,
                           PivotField[] dataFields,
                           PivotField[] filterFields)
Description copied from interface: PivotValueProvider
Pass fields information to PivotValueProvider for calculation.

Specified by:
setPivotFields in interface PivotValueProvider
Parameters:
rowFields - the row fields array
columnFields - the column fields array
dataFields - the data fields array
filterFields - the filter fields array

handleFieldPropertyEvent

protected void handleFieldPropertyEvent(PropertyChangeEvent evt)

updateFields

public void updateFields()
Specified by:
updateFields in interface IPivotDataModel

calculate

public void calculate()
Calculates the pivot data. Whenever you are done updating PivotField settings or the data in the original table model is changed, you should call this method to use the new settings or new data. If you call this method after the PivotDataModel has been set on PivotTablePane, you also need to call PivotTablePane.fieldsUpdated() method in order for the change to take effect.

Specified by:
calculate in interface IPivotDataModel

forceCalculate

public void forceCalculate()
Description copied from interface: PivotValueProvider
Ask PivotValueProvider to start calculate. The calculation could be done in a separate thread so it does not mean that the calculation has completed after invoking this method. The pivot value user will wait for the PivotValueProviderEvent to get the information that the calculation has completed.

The upper level could call this method in any time. You need consider the performance on this scenario.

Specified by:
forceCalculate in interface PivotValueProvider

manageCompoundKeys

protected void manageCompoundKeys()
Manages CompoundKeys after calculation to fill in some necessary CompoundKeys without adding dummy records in the original table model or removing some unnecessary CompoundKeys without removing records in the original table model.

Please construct row keys or column keys then invoke addRowIndex(CompoundKey, CompoundKey, int) with the third parameter as -1 to fill in the extra compound keys. Please invoke removeColumnKey(CompoundKey) or removeRowKey(CompoundKey) to remove unnecessary CompoundKeys.

Please make sure you will check the getRowFields() and getColumnFields() first to construct correct CompoundKeys. Otherwise, the behavior might be very odd.

 // assume the first column field is year, the second is quarter and the third is month.
 for (int year = 1993; year <= 1997; year++) {
     for (int quarter = 0; quarter <= 3; quarter++) {
         for (int month = quarter * 3; month <= quarter * 3 + 2; month++) {
             addRowIndex(CompoundKey.newInstance(new Object[0]), CompoundKey.newInstance(new Object[]{year, quarter, month}), -1);
         }
     }
 }
 

Since:
3.4.6

removeRowKey

protected void removeRowKey(CompoundKey rowKey)
Removes the CompoundKey in row header area.

You could invoke this method in manageCompoundKeys() to remove some unnecessary row keys as you wish.

Parameters:
rowKey - the CompoundKey
Since:
3.4.6

removeColumnKey

protected void removeColumnKey(CompoundKey columnKey)
Removes the CompoundKey in column header area.

You could invoke this method in manageCompoundKeys() to remove some unnecessary column keys as you wish.

Parameters:
columnKey - the CompoundKey
Since:
3.4.6

isCalculating

public boolean isCalculating()
Description copied from interface: PivotValueProvider
Returns if PivotValueProvider is calculating.

Specified by:
isCalculating in interface PivotValueProvider
Returns:
true if it is calculating. Otherwise false.

updateFilters

protected void updateFilters()

isCalculated

public boolean isCalculated()
Checks if calculate() is called on this pivot data model. There is no setter for this flag. Only calculate() will set it to true.

Specified by:
isCalculated in interface IPivotDataModel
Returns:
true if calculate() is already called.

getCompoundKeyAt

protected CompoundKey getCompoundKeyAt(int rowIndex,
                                       int areaType)
Gets the designated compound key from the row index in the data source.

Parameters:
rowIndex - the row index in the data source.
areaType - AREA_ROW or AREA_COLUMN
Returns:
the compound key.
Since:
3.3.7

getRowAt

public int getRowAt(int actualRow)
Gets the closest row index in DataTable that includes the actual row index in the original table model.

There might be many rows that represents the actual row in the original table model. If this is the case, the closest one will be returned. If there are multiple data fields, the top-most row will be returned.

Parameters:
actualRow - the actual row index in the original table model
Returns:
the closest row index in DataTable.
Since:
3.4.4

getColumnAt

public int getColumnAt(int actualRow)
Gets the closest column index in DataTable that includes the actual row index in the original table model.

There might be many columns that represents the actual row in the original table model. If this is the case, the closest one will be returned. If there are multiple data fields, the left-most column will be returned.

Parameters:
actualRow - the actual row index in the original table model
Returns:
the closest column index in DataTable.
Since:
3.4.4

invalidateRowHeaderTableModel

public void invalidateRowHeaderTableModel()
Description copied from interface: IPivotDataModel
Invalidate row header table model before calculate. After calculating, you should always set model for corner table explicitly.

Specified by:
invalidateRowHeaderTableModel in interface IPivotDataModel

invalidateColumnHeaderTableModel

public void invalidateColumnHeaderTableModel()
Description copied from interface: IPivotDataModel
Invalidate column header table model before calculate. After calculating, you should always set model for corner table explicitly.

Specified by:
invalidateColumnHeaderTableModel in interface IPivotDataModel

invalidateCornerTableModel

public void invalidateCornerTableModel()
Description copied from interface: IPivotDataModel
Invalidate corner table model before calculate. After calculating, you should always set model for corner table explicitly.

Specified by:
invalidateCornerTableModel in interface IPivotDataModel

invalidateDataTableModel

public void invalidateDataTableModel()
Description copied from interface: IPivotDataModel
Invalidate data table model before calculate. After calculating, you should always set model for corner table explicitly.

Specified by:
invalidateDataTableModel in interface IPivotDataModel

getPossibleValues

@Deprecated
public Object[] getPossibleValues(int columnIndex)
Deprecated. the order of the possible values returned from this method is not clear. Please use getPossibleValues(int, java.util.Comparator) instead. We didn't use this method anymore in our code.

Gets the possible values of the specified columnIndex. The values are sorted.

Specified by:
getPossibleValues in interface IPivotDataModel
Parameters:
columnIndex - the column index.
Returns:
the possible values of in the column.

getPossibleValues

public Object[] getPossibleValues(PivotField field)
Description copied from interface: PivotValueProvider
Retrieve the possible values for the designated field.

In general, you need consider the current filtering to return possible values appropriately.

Specified by:
getPossibleValues in interface IPivotDataModel
Specified by:
getPossibleValues in interface PivotValueProvider
Parameters:
field - the pivot field
Returns:
possible values array.

getPossibleValues

public Object[] getPossibleValues(int columnIndex,
                                  Comparator comparator)
Gets the possible values of the specified columnIndex. The values are sorted using the comparator passed in as parameter.

If the Field.isPreferSelectedPossibleValues() returns false, all values in Field.getFilteredPossibleValues() will also present in the return array.

Specified by:
getPossibleValues in interface IPivotDataModel
Parameters:
columnIndex - the column index
comparator - the comparator
Returns:
the possible values of in the column.

getRowHeaderTableModel

public HeaderTableModel getRowHeaderTableModel()
Gets the row header table model. It can be used by HeaderTable.

Specified by:
getRowHeaderTableModel in interface IPivotDataModel
Returns:
the row header table model.

createRowHeaderTableModel

protected HeaderTableModel createRowHeaderTableModel(CompoundKey[] keys)
Creates the row header table model.

Parameters:
keys - the row keys.
Returns:
the HeaderTableModel used for the row header table.

getCornerTableModel

public TableModel getCornerTableModel()
Gets the corner table model. It is the table model for the top left corner but in regular PivotTablePane, this model is not used. You need to enable it by overriding the following method in PivotTablePane and override setupLayout to add _dataFieldsArea and _rowFieldsArea to somewhere else in order to set the _cornerTable to UPPER_LEFT_CORNER of the JScrollPane.
 protected void initComponents() {
     super.initComponents();
    _cornerTable = new HeaderTable(this);
    _cornerTable.setRowHeight(getRowHeight());
    setCornerTableModel(_cornerTable, getPivotDataModel().getCornerTableModel());
    _cornerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     _cornerTable.setCellSelectionEnabled(true);
     ((JideTable) _cornerTable).setColumnResizable(true);
     ((JideTable) _cornerTable).setNonContiguousCellSelection(true);
 }
 

Specified by:
getCornerTableModel in interface IPivotDataModel
Returns:
the corner table model.

getColumnHeaderTableModel

public HeaderTableModel getColumnHeaderTableModel()
Gets the column header table model. It can be used by HeaderTable.

Specified by:
getColumnHeaderTableModel in interface IPivotDataModel
Returns:
the column header table model.

createColumnHeaderTableModel

protected HeaderTableModel createColumnHeaderTableModel(CompoundKey[] keys)
Creates the column header table model.

Parameters:
keys - the column keys.
Returns:
the HeaderTableModel used for the column header table.

getDataTableModel

public TableModel getDataTableModel()
Gets the data table model.

Specified by:
getDataTableModel in interface IPivotDataModel
Returns:
the data table model.

createDataTableModel

protected DataTableModel createDataTableModel()
Creates DataTableModel.

Returns:
the DataTableModel.

getRowFields

public PivotField[] getRowFields()
Gets the row fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getRowFields in interface IPivotDataModel
Returns:
the row fields.

getFieldIndices

protected int[] getFieldIndices(PivotField[] fields)

getRowFieldIndices

public int[] getRowFieldIndices()
Gets the model indices for the row fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getRowFieldIndices in interface IPivotDataModel
Returns:
the row fields.

getColumnFields

public PivotField[] getColumnFields()
Gets the column fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getColumnFields in interface IPivotDataModel
Returns:
the column fields.

getColumnFieldIndices

public int[] getColumnFieldIndices()
Gets the model indices for the column fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getColumnFieldIndices in interface IPivotDataModel
Returns:
the column fields.

getDataFields

public PivotField[] getDataFields()
Gets the data fields. it must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getDataFields in interface IPivotDataModel
Returns:
the data fields.

resetDataFields

public void resetDataFields()
Description copied from interface: IPivotDataModel
Reset data fields based on the values in every PivotField. This method should only be invoked for protection purpose.

Specified by:
resetDataFields in interface IPivotDataModel

getDataFieldIndices

public int[] getDataFieldIndices()
Gets the model indices for the data fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getDataFieldIndices in interface IPivotDataModel
Returns:
the data fields.

getFilterFields

public PivotField[] getFilterFields()
Gets the filter fields. it must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getFilterFields in interface IPivotDataModel
Returns:
the filter fields.

getFilterFieldIndices

public int[] getFilterFieldIndices()
Gets the model indices for the filter fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getFilterFieldIndices in interface IPivotDataModel
Returns:
the filter fields.

getUnassignedFields

public PivotField[] getUnassignedFields()
Gets the unassigned fields. it must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getUnassignedFields in interface IPivotDataModel
Returns:
the unassigned fields.

getUnassignedFieldIndices

public int[] getUnassignedFieldIndices()
Gets the model indices for the unassigned fields. It must be called after calculate() is called. Otherwise, it will return null.

Specified by:
getUnassignedFieldIndices in interface IPivotDataModel
Returns:
the unassigned fields.

getDataAt

public List<Integer> getDataAt(int rowIndex,
                               int columnIndex)
Gets the row index list at the specified row index and column index. If both indices are greater than or equal 0, it will get the row index list as in the data table model. If the row index is less than 0 but the column index is greater than or equal 0, it will get the row index list as in the column header table model. The negative row index is converted to the row index relative to row header table model using - rowIndex - 1. If the column index is less than 0 but the row index is greater than or equal 0, it will get the row index list as in the row header table model. The negative column index is converted to the column index relative to column header table model using - columnIndex - 1.

Please note, the list returned from this method is used internally. If you iterate through the list and modify the table model at the same time, the list could be changed as well. So to be safe, you should replicate the list if you plan to modify the table model.

Specified by:
getDataAt in interface IPivotDataModel
Parameters:
rowIndex - the row index relative to DataTableModel.
columnIndex - the column index relative to DataTableModel.
Returns:
a list of integer which are row indexes to the data source that you can get using getDataSource().

getDataAt

public List<Integer> getDataAt(CompoundKey rowKey,
                               CompoundKey columnKey)
Gets the row index list that matches with the rowKey and columnKey.

Specified by:
getDataAt in interface IPivotDataModel
Parameters:
rowKey - the row compound key
columnKey - the column compound key
Returns:
a list of integer which are row indexes to the data source that you can get using getDataSource().

sortCompoundKeys

protected CompoundKey[] sortCompoundKeys(CompoundKey[] keys,
                                         PivotField[] fields)
Sorts the compound keys based on the sort order in the fields.

Parameters:
keys - the list of CompoundKeys.
fields - the array of the fields.
Returns:
sorted compound key array.

isRowDataFields

public boolean isRowDataFields()
Is the data field displayed on the row header area. It possibly returns true only if isColumnDataFields return false. Otherwise data fields will display on the column header area.

Specified by:
isRowDataFields in interface IPivotDataModel
Returns:
true or false.

isColumnDataFields

public boolean isColumnDataFields()
Checks if the data field displayed on the column header area.

Specified by:
isColumnDataFields in interface IPivotDataModel
Returns:
true or false.

isAlwaysColumnDataFields

public boolean isAlwaysColumnDataFields()
Checks if the data fields will always displayed on the column header area. If this method returns true, isColumnDataFields will always return true.

Specified by:
isAlwaysColumnDataFields in interface IPivotDataModel
Returns:
true or false.

setAlwaysColumnDataFields

public void setAlwaysColumnDataFields(boolean alwaysColumnDataFields)
Sets the flag whether the data fields will always be displayed on the column header area. By default, we might use row header area to display the data fields if there is no field in the row area.

Specified by:
setAlwaysColumnDataFields in interface IPivotDataModel
Parameters:
alwaysColumnDataFields - true or false.

isAlwaysRowDataFields

public boolean isAlwaysRowDataFields()
Is the data field always displayed on the row header area. If this method returns true, isRowDataFields will always return true as long as isColumnDataFields returns false.

Specified by:
isAlwaysRowDataFields in interface IPivotDataModel
Returns:
true or false.

setAlwaysRowDataFields

public void setAlwaysRowDataFields(boolean alwaysRowDataFields)
Sets the flag whether the data fields will always be displayed on the row header area. By default, we might use row header area to display the data fields if there is no field in the row area.

Specified by:
setAlwaysRowDataFields in interface IPivotDataModel
Parameters:
alwaysRowDataFields - true or false.

isHideSingleDataField

public boolean isHideSingleDataField()
Specified by:
isHideSingleDataField in interface IPivotDataModel

setHideSingleDataField

public void setHideSingleDataField(boolean hideSingleDataField)
Specified by:
setHideSingleDataField in interface IPivotDataModel

isShowGrandTotalForRow

public boolean isShowGrandTotalForRow()
Checks if grand total row is visible.

Specified by:
isShowGrandTotalForRow in interface IPivotDataModel
Returns:
true if grand total row is visible. Otherwise is false.

setShowGrandTotalForRow

public void setShowGrandTotalForRow(boolean showGrandTotalForRow)
Shows grand total row. If you changed this value, you need to call PivotTablePane.rowHeaderUpdated() or PivotTablePane.bothHeadersUpdated() if you also changed grandTotalForColumn.

Specified by:
setShowGrandTotalForRow in interface IPivotDataModel
Parameters:
showGrandTotalForRow - whether show grand total for row.

isShowGrandTotalForColumn

public boolean isShowGrandTotalForColumn()
Checks if grand total column is visible.

Specified by:
isShowGrandTotalForColumn in interface IPivotDataModel
Returns:
true if grand total column is visible. Otherwise is false.

setShowGrandTotalForColumn

public void setShowGrandTotalForColumn(boolean showGrandTotalForColumn)
Shows grand total column. If you changed this value, you need to call PivotTablePane.columnHeaderUpdated() or PivotTablePane.bothHeadersUpdated() if you also changed grandTotalForRow.

Specified by:
setShowGrandTotalForColumn in interface IPivotDataModel
Parameters:
showGrandTotalForColumn - whether show grand total for column.

getCellStyleProvider

public PivotCellStyleProvider getCellStyleProvider()
Gets the PivotCellStyleProvider.

Specified by:
getCellStyleProvider in interface IPivotDataModel
Returns:
the PivotCellStyleProvider.

setCellStyleProvider

public void setCellStyleProvider(PivotCellStyleProvider cellStyleProvider)
Sets the PivotCellStyleProvider. You can use this provider to provide CellStyle for column header table, row header table and data table.

Specified by:
setCellStyleProvider in interface IPivotDataModel
Parameters:
cellStyleProvider - the cell style provider.

setRowHeaderEditingProvider

public void setRowHeaderEditingProvider(PivotDataEditingProvider rowHeaderEditingProvider)
Sets the PivotDataEditingProvider that is used for the row header table. You can use this provider to provide a way to edit cell directly in pivot table. The provide will interpret the user change and modify the actual data source.

Specified by:
setRowHeaderEditingProvider in interface IPivotDataModel
Parameters:
rowHeaderEditingProvider - the date editing provider.

getRowHeaderEditingProvider

public PivotDataEditingProvider getRowHeaderEditingProvider()
Gets the PivotDataEditingProvider for the row header table.

Specified by:
getRowHeaderEditingProvider in interface IPivotDataModel
Returns:
the PivotDataEditingProvider.

setColumnHeaderEditingProvider

public void setColumnHeaderEditingProvider(PivotDataEditingProvider columnHeaderEditingProvider)
Sets the PivotDataEditingProvider that is used for the column header table. You can use this provider to provide a way to edit cell directly in pivot table. The provide will interpret the user change and modify the actual data source.

Specified by:
setColumnHeaderEditingProvider in interface IPivotDataModel
Parameters:
columnHeaderEditingProvider - the date editing provider.

getColumnHeaderEditingProvider

public PivotDataEditingProvider getColumnHeaderEditingProvider()
Gets the PivotDataEditingProvider for the column header table.

Specified by:
getColumnHeaderEditingProvider in interface IPivotDataModel
Returns:
the PivotDataEditingProvider.

getDataEditingProvider

public PivotDataEditingProvider getDataEditingProvider()
Gets the PivotDataEditingProvider for the data table.

Specified by:
getDataEditingProvider in interface IPivotDataModel
Returns:
the PivotDataEditingProvider.

setDataEditingProvider

public void setDataEditingProvider(PivotDataEditingProvider dataEditingProvider)
Sets the PivotDataEditingProvider for the data table. You can use this provider to provide a way to edit cell directly in pivot table. The provide will interpret the user change and modify the actual data source.

Specified by:
setDataEditingProvider in interface IPivotDataModel
Parameters:
dataEditingProvider - the date editing provider.

getSummaryCalculator

public SummaryCalculator getSummaryCalculator()
Gets the statistics calculator used to calculate all the statistics for the pivot data model.

Specified by:
getSummaryCalculator in interface IPivotDataModel
Returns:
the statistics calculator.

setSummaryCalculator

public void setSummaryCalculator(SummaryCalculator summaryCalculator)
Sets the statistics calculator.

Specified by:
setSummaryCalculator in interface IPivotDataModel
Parameters:
summaryCalculator - the summary calculator.

getSummaryCalculatorFactory

public SummaryCalculatorFactory getSummaryCalculatorFactory()
Gets the summary calculator factory which will create summary calculator to calculate all the statistics for the pivot data model. Please note, this SummaryCalculatorFactory is only used when the calculateStatistics(PivotField, int, int, int, Object[]) method is called from a non-EDT. On EDT, we will use getSummaryCalculator() method to get the SummaryCalculator.

Specified by:
getSummaryCalculatorFactory in interface IPivotDataModel
Returns:
the summary calculator factory.

setSummaryCalculatorFactory

public void setSummaryCalculatorFactory(SummaryCalculatorFactory summaryCalculatorFactory)
Sets the statistics calculator factory. We will use this factory to create SummaryCalculator if the calculation is running in a multiple thread environment. Otherwise we will use getSummaryCalculator() method to get the SummaryCalculator.

Specified by:
setSummaryCalculatorFactory in interface IPivotDataModel
Parameters:
summaryCalculatorFactory - the summary calculator factory.

isDisplayGrandTotalFirstForRow

public boolean isDisplayGrandTotalFirstForRow()
Description copied from interface: IPivotDataModel
Checks if the grand total is displayed as the first row.

Specified by:
isDisplayGrandTotalFirstForRow in interface IPivotDataModel
Returns:
true or false.

setDisplayGrandTotalFirstForRow

public void setDisplayGrandTotalFirstForRow(boolean displayGrandTotalFirstForRow)
Description copied from interface: IPivotDataModel
By default, grand total is displayed at the last row in the pivot table. If you set this flag to true, it will be displayed as the first row.

Specified by:
setDisplayGrandTotalFirstForRow in interface IPivotDataModel
Parameters:
displayGrandTotalFirstForRow - true or false.

isDisplayGrandTotalFirstForColumn

public boolean isDisplayGrandTotalFirstForColumn()
Description copied from interface: IPivotDataModel
Checks if the grand total is displayed as the first column.

Specified by:
isDisplayGrandTotalFirstForColumn in interface IPivotDataModel
Returns:
true or false.

setDisplayGrandTotalFirstForColumn

public void setDisplayGrandTotalFirstForColumn(boolean displayGrandTotalFirstForColumn)
Description copied from interface: IPivotDataModel
By default, grand total is displayed at the last column in the pivot table. If you set this flag to true, it will be displayed as the first column.

Specified by:
setDisplayGrandTotalFirstForColumn in interface IPivotDataModel
Parameters:
displayGrandTotalFirstForColumn - true or false.

isDisplayGrandTotalFirst

public boolean isDisplayGrandTotalFirst()
Checks if the grand total is displayed as the first column (row).

Specified by:
isDisplayGrandTotalFirst in interface IPivotDataModel
Returns:
true or false.

setDisplayGrandTotalFirst

@Deprecated
public void setDisplayGrandTotalFirst(boolean displayGrandTotalFirst)
Deprecated. replaced by setDisplayGrandTotalFirstForRow(boolean) and setDisplayGrandTotalFirstForColumn(boolean)

By default, grand total is displayed at the last column (row) in the pivot table. If you set this flag to true, it will be displayed as the first column (row).

It's deprecated since 2.11.1. To keep backward compatibility, if the user happens to invoke this method to set the flag, it will automatically invoke both setDisplayGrandTotalFirstForRow(boolean) and setDisplayGrandTotalFirstForColumn(boolean).

Specified by:
setDisplayGrandTotalFirst in interface IPivotDataModel
Parameters:
displayGrandTotalFirst - true or false.

isAutoUpdate

public boolean isAutoUpdate()
Checks if the pivot data will be automatically updated when the underlying table model data changes.

Specified by:
isAutoUpdate in interface IPivotDataModel
Returns:
true or false.

setAutoUpdate

public void setAutoUpdate(boolean autoUpdate)
Sets the flag if the pivot data will be automatically updated when the underlying table model data changes. By default, it is false because in most cases people use pivot data to analyze static data. If the data changes, you have to call calculate() method when the underlying table model data changes. However because the data inside pivot table is very complex, right now autoUpdate will only update correctly if the table model data change is cellUpdated event and rowUpdated event. If you add/remove rows or columns, you still have to call calculate() just like before.

Specified by:
setAutoUpdate in interface IPivotDataModel
Parameters:
autoUpdate - true or false.

isAdjusting

public boolean isAdjusting()
Checks if the PivotDataModel is adjusting. If it is adjusting, other code should not call calculate() or update UI automatically when a property is changed. Right now, we used in PivotField.setSelectedPossibleValues(Object[]). By default, isAdjusting is false, so setSelectedPossibleValues will call calculate() and bothHeaderUpdated(). If isAdjusting is true, they will be not be called.

Specified by:
isAdjusting in interface IPivotDataModel
Returns:
true if adjusting. Otherwise false.

setAdjusting

public void setAdjusting(boolean adjusting)
Sets the PivotDataModel to adjusting mode. If it is adjusting, PivotDataModel will not call calculate() and update the UI when something is changed. After you set adjusting to false, PivotDataModel will then calculate(). But you will be still be responsible to call the XxxUpdated() method on PivotTablePane to update the UI.

Specified by:
setAdjusting in interface IPivotDataModel
Parameters:
adjusting - true or false.

isSummaryMode

public boolean isSummaryMode()
Checks if the pivot data model works in summary mode. Summary mode means instead of display the summary (such as sum, max, min, stddev etc statistics) of the values in the data table, it displays the first value that matches the key.

Default is true.

Specified by:
isSummaryMode in interface IPivotDataModel
Specified by:
isSummaryMode in interface PivotValueProvider
Returns:
true or false.

setSummaryMode

public void setSummaryMode(boolean summaryMode)
Sets the flag for the summary mode. Summary mode means instead of display the summary (such as sum, max, min, stddev etc statistics) of the values in the data table, it displays the first value that matches the key.

Specified by:
setSummaryMode in interface IPivotDataModel
Specified by:
setSummaryMode in interface PivotValueProvider
Parameters:
summaryMode - true to set to summary mode. Otherwise false.
See Also:
isSummaryMode()

isAggregateMode

public boolean isAggregateMode()
Checks if the pivot data model works in aggregate mode. Aggregate mode is only used by AggregateTableModel to show the actual cell values for the matched keys. By default, the actual values will not be displayed. Typically you should setSummaryMode(false).

Default is false.

Specified by:
isAggregateMode in interface IPivotDataModel
Returns:
true or false.

isSingleValueMode

public boolean isSingleValueMode()
The cells in the data table are actually summary of multiple rows in the original table model. For example, if the summary is SUM, we will display the sum of all the values of all the rows and display it in the cell of the data table. However In the single value mode, whenever there are two rows that maps to the same cell, we will delete the second row.

Specified by:
isSingleValueMode in interface IPivotDataModel
Specified by:
isSingleValueMode in interface PivotValueProvider
Returns:
true or false.

setSingleValueMode

public void setSingleValueMode(boolean singleValueMode)
Sets the single value mode.

Specified by:
setSingleValueMode in interface IPivotDataModel
Specified by:
setSingleValueMode in interface PivotValueProvider
Parameters:
singleValueMode - true or false.

verify

public boolean verify()
This method is for debugging purpose, not a public API. It will print out if there is any cell span errors in the row header and the column header table.

Specified by:
verify in interface IPivotDataModel

getRowHeaderRowIndexAt

public int getRowHeaderRowIndexAt(int rowIndex)
Gets the row index in the row header table which has the data from the original table model at the specified rowIndex.

Specified by:
getRowHeaderRowIndexAt in interface IPivotDataModel
Parameters:
rowIndex - the row at the original table model.
Returns:
the row index as in the row header table.

getColumnHeaderColumnIndexAt

public int getColumnHeaderColumnIndexAt(int rowIndex)
Gets the column index in the column header table which has the data from the original table model at the specified rowIndex.

Specified by:
getColumnHeaderColumnIndexAt in interface IPivotDataModel
Parameters:
rowIndex - the row at the original table model.
Returns:
the column index as in the column header table.

isValueImmutable

public static boolean isValueImmutable()
Checks the valueImmutable flag.

Returns:
true or false.

setValueImmutable

public static void setValueImmutable(boolean valueImmutable)
Sets the valueImmutable flag. By default, we assume all values in getValueAt of PivotDataSource or TableModel are immutable so that we can cache the hashCode of those values for the performance reason. All primitives, Number, String are immutable which are most table model getValueAt will return. If you need to return your own classes in getValueAt, you can make them immutable. But if for whatever reason you can't do that, you can call PivotDataModel#setValueImmutable(false) before creating any PivotDataModel. Just so you know, from our performance testing based on PivotTableDemo, setValueImmutable(false) will double the time to do the calculate() method. It's something you need to consider.

Parameters:
valueImmutable - true or false.

isUseComparable

public static boolean isUseComparable()
Checks the useComparable flag.

Returns:
true or false.
Since:
3.3.3

setUseComparable

public static void setUseComparable(boolean useComparable)
Sets the flag of useComparable. This flag is used when comparing. If the two objects are Comparable, we will use Comparable's compareTo method to compare, which is usually faster than using using Comparator. However if for whatever reason, we can't use Comparator, you can set this flag to false so that it will always use ObjectComparatorManager to compare.

Parameters:
useComparable - true or false.
Since:
3.3.3

isHideSummaryValues

public boolean isHideSummaryValues()
Get the flag that indicating if summary values should be hidden if all its children values are hidden.

The default value of this flag is true, which could cause incompatible behavior with release earlier than 2.8.3.

Specified by:
isHideSummaryValues in interface IPivotDataModel
Returns:
true if summary values need be hidden. otherwise false.

setHideSummaryValues

public void setHideSummaryValues(boolean hideSummaryValues)
Set the flag that indicating if summary values should be hidden if all its children values are hidden.

Specified by:
setHideSummaryValues in interface IPivotDataModel
Parameters:
hideSummaryValues - the flag
See Also:
isHideSummaryValues()

isKeepRowChildrenOnSummaryFilter

public boolean isKeepRowChildrenOnSummaryFilter()
Description copied from interface: IPivotDataModel
Get the flag indicating that if all its row children in row header table should be kept if the summary row is kept on data field filter.

The default value is true which means all its row children would be kept. You could change it to false if you want to keep all its column children of summary values in column header table.

This flag only takes effects when at least one data field filters on summary values.

#see PivotField.isDataFieldFilterOnSummary()

Specified by:
isKeepRowChildrenOnSummaryFilter in interface IPivotDataModel
Returns:
true if row children of summary values are to be kept. Otherwise false.

setKeepRowChildrenOnSummaryFilter

public void setKeepRowChildrenOnSummaryFilter(boolean keepRowChildrenOnSummaryFilter)
Description copied from interface: IPivotDataModel
Set the flag indicating that if all its row children in row header table should be kept if the summary row is kept on data field filter.

#see #isKeepRowChildrenOnSummaryFilter

Specified by:
setKeepRowChildrenOnSummaryFilter in interface IPivotDataModel
Parameters:
keepRowChildrenOnSummaryFilter - the flag

isHideExpandIconOnSingleRow

public boolean isHideExpandIconOnSingleRow()
Get the flag indicating if the expand/collapse icon will be hidden if there is only one row as its child.

Returns:
true if the icon would be hidden. Otherwise false.
See Also:
setHideExpandIconOnSingleRow(boolean)

setHideExpandIconOnSingleRow

public void setHideExpandIconOnSingleRow(boolean hideExpandIconOnSingleRow)
Set the flag indicating if the expand/collapse icon will be hidden if there is only one row as its child.

By default, the flag is true to hide the expand icon.

Parameters:
hideExpandIconOnSingleRow - the flag

isLayoutDataFieldsFirst

public boolean isLayoutDataFieldsFirst()
Gets the flag indicating if the data field should be laid out in the first level or not.

Specified by:
isLayoutDataFieldsFirst in interface IPivotDataModel
Returns:
true if the data field should be laid out first. Otherwise false.
Since:
3.3.8
See Also:
setLayoutDataFieldsFirst(boolean)

setLayoutDataFieldsFirst

public void setLayoutDataFieldsFirst(boolean layoutDataFieldsFirst)
Sets the flag indicating if the data field should be laid out in the first level or not.

By default the flag is false to keep the default behavior backward compatible.

Specified by:
setLayoutDataFieldsFirst in interface IPivotDataModel
Parameters:
layoutDataFieldsFirst - the flag
Since:
3.3.8

isHighPerformanceMode

public boolean isHighPerformanceMode()
Description copied from interface: IPivotDataModel
Gets the flag indicating if the IPivotDataModel should work on high performance mode.

Specified by:
isHighPerformanceMode in interface IPivotDataModel
Returns:
true if the IPivotDataModel should work on high performance mode. Otherwise false.
See Also:
IPivotDataModel.setHighPerformanceMode(boolean)

setHighPerformanceMode

public void setHighPerformanceMode(boolean highPerformanceMode)
Description copied from interface: IPivotDataModel
Sets the flag indicating if the IPivotDataModel should work on high performance mode.

By default the flag is false to keep the default behavior backward compatible.

Setting this flag to true will improve the calculating performance. However, some features, like the expansion state persistence, selection persistence, column width persistence, hidden value persistence, will be lost.

Specified by:
setHighPerformanceMode in interface IPivotDataModel
Parameters:
highPerformanceMode - the flag

getRowMerger

public PivotDataModel.RowMerger getRowMerger()
Gets the row merger.

Returns:
the row merger.
See Also:
PivotDataModel.RowMerger

setRowMerger

public void setRowMerger(PivotDataModel.RowMerger rowMerger)
Sets the row merger.

Parameters:
rowMerger - a new RowMerger
See Also:
PivotDataModel.RowMerger

isAutoSortKeys

public boolean isAutoSortKeys()
Checks whether the CompoundKeys automatically are sorted.

Returns:
true or false.

setAutoSortKeys

public void setAutoSortKeys(boolean autoSortKeys)
Sets the flag whether the CompoundKeys should be automatically sorted when calcuate() is called.

Parameters:
autoSortKeys - true or false.

getStatisticsType

public int getStatisticsType(Values rowValues,
                             Values columnValues,
                             PivotField dataField)
Description copied from interface: PivotValueProvider
Get the statistics layer. By default, it should return PivotConstants.STATISTICS_CALCULATION_DEFAULT. So that the PivotValueProvider itself will conduct the statistics. However, for running percentage or daily average, you probably need return other values so that CalculatedPivotDataModel would calculate the summary itself.

Specified by:
getStatisticsType in interface PivotValueProvider
Parameters:
rowValues - the row values
columnValues - the column values
dataField - the data field
Returns:
the statistics layer.

calculateStatistics

protected Object calculateStatistics(PivotField field,
                                     Values rowValues,
                                     Values columnValues,
                                     int summaryType,
                                     Object[] objects)
Calculate statistics for the cell with the same rowValues and the same columnValues in DataTable.

Parameters:
field - the data field
rowValues - the row values
columnValues - the column values
summaryType - the summary type
objects - the base values
Returns:
the calculated value.

calculateStatistics

@Deprecated
protected Object calculateStatistics(PivotField field,
                                                int rowIndex,
                                                int columnIndex,
                                                int summaryType,
                                                Object[] objects)
Deprecated. replaced by calculateStatistics(PivotField, Values, Values, int, Object[])

Calculate statistics for the cell with (rowIndex, columnIndex) in DataTable. This method will only be invoked by DataTableModel if this pivot data model is NOT a CalculatedPivotDataModel.

Parameters:
field - the data field
rowIndex - the row index in the data table
columnIndex - the column index in the data table
summaryType - the summary type
objects - the base values
Returns:
the calculated value.

collectValuesForCell

protected Object[] collectValuesForCell(PivotField field,
                                        Values rowKeys,
                                        Values columnKeys,
                                        int summaryType)

collectValuesForCell

protected Object[] collectValuesForCell(PivotField field,
                                        int rowIndex,
                                        int columnIndex,
                                        int summaryType)

getValueAt

public Object getValueAt(PivotField field,
                         Values rowKeys,
                         Values columnKeys)
Description copied from interface: IPivotDataModel
Get the value to be compared.

Specified by:
getValueAt in interface IPivotDataModel
Specified by:
getValueAt in interface PivotValueProvider
Parameters:
field - the data field
rowKeys - row value keys in the corresponding row header table
columnKeys - column value keys in the corresponding column header table
Returns:
the value from the cell.

shouldCalculateSummary

protected boolean shouldCalculateSummary(int rowIndex,
                                         int columnIndex)
Check if the cell in the DataTable need calculate summary.

PivotTablePane will get corresponding class, editorContext, converterContext, value, etc., depending on this method.

You don't have to override this method unless you want to control the details of the cell behavior.

Parameters:
rowIndex - the row index of the cell
columnIndex - the column index of the cell
Returns:
true if the cell needs calculation. Otherwise false.

isValuesVisible

public boolean isValuesVisible(Values values)
Checks if the Values is visible.

Specified by:
isValuesVisible in interface IPivotDataModel
Parameters:
values - the Values.
Returns:
true or false True means the Values is visible.

addHiddenValues

public void addHiddenValues(Values values)
Adds the values to the hidden values. For example, if you want to hide the column or row, as in PivotTableDemo, that year is 1994, quarter is 2 and month is 6, you can call the code below to do it.

 addHiddenValues(new DefaultValues(new Object[]{1994, 2, 6});
 

Specified by:
addHiddenValues in interface IPivotDataModel
Parameters:
values - the Values.

removeHiddenValues

public void removeHiddenValues(Values values)
Removes the values from the hidden values.

Specified by:
removeHiddenValues in interface IPivotDataModel
Parameters:
values - the Values.

clearHiddenValues

public void clearHiddenValues()
Clears the hidden values. In the other word, all Values will be shown on the header tables.

Specified by:
clearHiddenValues in interface IPivotDataModel

hasHiddenValues

public boolean hasHiddenValues()
Checks if there are hidden values.

Specified by:
hasHiddenValues in interface IPivotDataModel
Returns:
True if there are hidden values. Otherwise false.

getHiddenValues

public Values[] getHiddenValues()
Gets all the hidden values.

Specified by:
getHiddenValues in interface IPivotDataModel
Returns:
the hidden values in an array.

isColumnVisible

public boolean isColumnVisible(Values values,
                               PivotField field)
Description copied from interface: IPivotDataModel
Checks if the Values is visible.

Specified by:
isColumnVisible in interface IPivotDataModel
Parameters:
values - the Values
field - the data field
Returns:
true or false True means the Values is visible.

addHiddenColumn

public void addHiddenColumn(Values values,
                            PivotField field)
Description copied from interface: IPivotDataModel
Adds the designated column defined by values and PivotField to the hidden values. If all data fields in one values are hidden, addHiddenValues() will be invoked to hide the entire values.

This method should invoke IPivotDataModel.addHiddenColumn(Values, PivotField, String) with the string as "15\t75\t75"

Specified by:
addHiddenColumn in interface IPivotDataModel
Parameters:
values - the Values
field - the data field

addHiddenColumn

public void addHiddenColumn(Values values,
                            PivotField dataField,
                            String width)
Description copied from interface: IPivotDataModel
Adds the designated column defined by values and PivotField to the hidden values. If all data fields in one values are hidden, addHiddenValues() will be invoked to hide the entire values.

Specified by:
addHiddenColumn in interface IPivotDataModel
Parameters:
values - the Values
dataField - the data field
width - the width information before the column is hidden

removeHiddenColumn

public String removeHiddenColumn(Values values,
                                 PivotField field)
Description copied from interface: IPivotDataModel
Removes the column from the hidden columns.

Specified by:
removeHiddenColumn in interface IPivotDataModel
Parameters:
values - the Values
field - the data field
Returns:
the saved column width while hiding the column. -1 if the column width is not available.

clearHiddenColumns

public void clearHiddenColumns()
Description copied from interface: IPivotDataModel
Clears the hidden columns. In the other word, all columns will be shown on the header tables.

Specified by:
clearHiddenColumns in interface IPivotDataModel

hasHiddenColumns

public boolean hasHiddenColumns()
Description copied from interface: IPivotDataModel
Checks if there are hidden columns.

Specified by:
hasHiddenColumns in interface IPivotDataModel
Returns:
True if there are hidden columns. Otherwise false.

getHiddenColumns

public Object[][] getHiddenColumns()
Description copied from interface: IPivotDataModel
Get the hidden columns array.

It will return a two-dimension array. Each row means a hidden column and has three elements. In each row, the first element is Values and the second element is DataField while the last one is the width information before hidden. There are three elements in the width information, which in order are minWdith, preferredWidth then width.

Specified by:
getHiddenColumns in interface IPivotDataModel
Returns:
the hidden column array.

isAllowEmptyColumnHeader

public boolean isAllowEmptyColumnHeader()
Gets the flag if empty headers are allowed.

Specified by:
isAllowEmptyColumnHeader in interface IPivotDataModel
Returns:
true or false.

setAllowEmptyColumnHeader

public void setAllowEmptyColumnHeader(boolean allowEmptyColumnHeader)
Sets the flag if empty column header is allowed. This is used when there are no column fields but there are data fields. If this flag is set to false, we will display summary information on the data fields in the data table. If set to true, the data table will be empty.

Specified by:
setAllowEmptyColumnHeader in interface IPivotDataModel
Parameters:
allowEmptyColumnHeader - true or false.

isAllowEmptyRowHeader

public boolean isAllowEmptyRowHeader()
Gets the flag if empty headers are allowed.

Specified by:
isAllowEmptyRowHeader in interface IPivotDataModel
Returns:
true or false.

setAllowEmptyRowHeader

public void setAllowEmptyRowHeader(boolean allowEmptyRowHeader)
Sets the flag if empty row header is allowed. This is used when there are no row fields but there are data fields. If this flag is set to false, we will display summary information on the data fields in the data table. If set to true, the data table will be empty.

Specified by:
setAllowEmptyRowHeader in interface IPivotDataModel
Parameters:
allowEmptyRowHeader - true or false.

isExpandByDefault

public boolean isExpandByDefault()
Checks the flag whether the pivot table expands to show all the values.

Specified by:
isExpandByDefault in interface IPivotDataModel
Returns:
true or false.

setExpandByDefault

public void setExpandByDefault(boolean expandByDefault)
Sets the flag whether the pivot table should expand to show all the values. By default, when calculate() method is called on PivotDataModel, all values are expanded so that user will see a fully expanded pivot table. You can change it to false so that it will show only the top level summary.

Specified by:
setExpandByDefault in interface IPivotDataModel
Parameters:
expandByDefault - true or false.

isShowSubtotalAsChild

public boolean isShowSubtotalAsChild()
Description copied from interface: IPivotDataModel
Get the flag.

Specified by:
isShowSubtotalAsChild in interface IPivotDataModel
Returns:
true if show subtotal as child. Otherwise false.
See Also:
IPivotDataModel.setShowSubtotalAsChild(boolean)

setShowSubtotalAsChild

public void setShowSubtotalAsChild(boolean showSubtotalAsChild)
By default, the subtotal rows/columns are at the same level as the values. For example, if there is a year value is 1994, 1994 total is at the same level as sibling. If this flag is set to true, the subtotal will become a child of the value.

Specified by:
setShowSubtotalAsChild in interface IPivotDataModel
Parameters:
showSubtotalAsChild - true or false.

isHideRedundantSubtotal

public boolean isHideRedundantSubtotal()
When the subtotal is configured as automatically and there is only one item, the subtotal is redundant. By setting this flag to false, we will hide the subtotal if there is only one item.

Specified by:
isHideRedundantSubtotal in interface IPivotDataModel
Returns:
true or false.
Since:
3.3.3

setHideRedundantSubtotal

public void setHideRedundantSubtotal(boolean hideRedundantSubtotal)
Sets the hideRedundantSubtotal flag.

Specified by:
setHideRedundantSubtotal in interface IPivotDataModel
Parameters:
hideRedundantSubtotal - true or false.
Since:
3.3.3
See Also:
isHideRedundantSubtotal()

addPivotValueProviderListener

public void addPivotValueProviderListener(PivotValueProviderListener l)
Description copied from interface: PivotValueProvider
Add PivotValueProviderListener so that the listener could know when calculation starts or ends.

Specified by:
addPivotValueProviderListener in interface PivotValueProvider
Parameters:
l - the listener

removePivotValueProviderListener

public void removePivotValueProviderListener(PivotValueProviderListener l)
Description copied from interface: PivotValueProvider
Remove registered PivotValueProviderListener.

Specified by:
removePivotValueProviderListener in interface PivotValueProvider
Parameters:
l - the listener

getPivotValueProviderListeners

public PivotValueProviderListener[] getPivotValueProviderListeners()

firePivotValueProviderChanged

public void firePivotValueProviderChanged(int type)

firePivotValueProviderChanged

public void firePivotValueProviderChanged(int type,
                                          Object object)

getRowKeys

public CompoundKey[] getRowKeys()
Description copied from interface: PivotValueProvider
Get row key array.

Specified by:
getRowKeys in interface PivotValueProvider
Returns:
the row key array.

getColumnKeys

public CompoundKey[] getColumnKeys()
Description copied from interface: PivotValueProvider
Get column key array.

Specified by:
getColumnKeys in interface PivotValueProvider
Returns:
the column key array.

isSummaryLayer

public boolean isSummaryLayer()
Description copied from interface: IPivotDataModel
Gets the flag indicating if it's a summary layer.

Specified by:
isSummaryLayer in interface IPivotDataModel
Returns:
true if it's a summary layer. Otherwise false.

setSummaryLayer

public void setSummaryLayer(boolean summaryLayer)
Description copied from interface: IPivotDataModel
Sets the flag indicating if it's a summary layer.

Specified by:
setSummaryLayer in interface IPivotDataModel
Parameters:
summaryLayer - the flag

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  Object newValue)
Support for reporting property changes for boolean properties. This method can be called when a property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.

Parameters:
propertyName - the property whose value has changed
oldValue - the property's previous value
newValue - the property's new value

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.

If listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the property change listener to be added
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This method should be used to remove PropertyChangeListeners that were registered for all bound properties of this class.

If listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the PropertyChangeListener to be removed
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

isComputeAffectedCellOnUpdate

public boolean isComputeAffectedCellOnUpdate()
Get the flag indicating that if the PivotValueProviderEvent will contain the affected cells information on original data model change scenario.

Returns:
true if the PivotValueProviderEvent will contain the affected cells information. Otherwise false.
See Also:
isAutoUpdate(), setComputeAffectedCellOnUpdate(boolean)

setComputeAffectedCellOnUpdate

public void setComputeAffectedCellOnUpdate(boolean computeAffectedCellOnUpdate)
Set the flag indicating that if the PivotValueProviderEvent will contain the affected cells information on original data model change scenario.

By default, the flag is false. You could set it to true however it may hit the performance since we have to cache the values before and after value changed to get the affected cells.

This flag could only take effect when both isAutoUpdate() and isCacheEnabled() return true.

Parameters:
computeAffectedCellOnUpdate - the flag

JIDE 3.5.15