Package org.zkoss.pivot.impl
Class TabularPivotModel
java.lang.Object
org.zkoss.pivot.impl.AbstractPivotModel
org.zkoss.pivot.impl.TabularPivotModel
- All Implemented Interfaces:
Serializable,PivotModel,PivotModelExt,PivotModelExt.SortCtrl
public class TabularPivotModel
extends AbstractPivotModel
implements PivotModelExt, PivotModelExt.SortCtrl
An implementation of PivotModel, which takes raw data in the form of a two
dimensional list.
- Author:
- simonpai
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static interfaceNested classes/interfaces inherited from interface org.zkoss.pivot.PivotModelExt
PivotModelExt.SortCtrl -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final TabularPivotModel.CalculatorContextSpaceprotected static final intprotected static final Comparator<PivotHeaderNode> -
Constructor Summary
ConstructorsConstructorDescriptionTabularPivotModel(Iterable<? extends List<?>> data, List<String> columns) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister a customCalculatorsupported in this model.protected ContextualCalculator<?>cast(Calculator calc) protected TabularPivotFieldcast(PivotField field) protected SimplePivotHeaderNodecast(PivotHeaderNode node) voidclearAllFields(boolean complete) Remove all pivot fields from column, row, and data.voidClear all registered customCalculatorsupported in this model.protected final ContextualCalculator<?>getCalculator(SimplePivotHeaderNode rowNode, int rowCalIndex, SimplePivotHeaderNode colNode, int colCalIndex, int dataIndex) protected CalculatorContextSignatureOverride this method to intervene the required signature for preparing source space.final TabularPivotField[]Return the header tree of columns.final TabularPivotField[]Returns the pivot field from the specified field name, if any.Return a list of all fields in the model.getFields(PivotField.Type type) Return a list of pivot fields of the given type.Return the raw data collection.final TabularPivotField[]Return the header tree of rows.intgetSourceDataIndex(PivotField field) Return the index of raw data columns the field corresponds to.Return a list of supported Calculators as options of Summary and Subtotals.getValue(PivotHeaderNode rowNode, int rowCalIndex, PivotHeaderNode colNode, int colCalIndex, int dataIndex) Get the calculated data summary at specific cell position.protected voiditerateRawData(SimplePivotHeaderTree colTree, SimplePivotHeaderTree rowTree, TabularPivotModel.RawDataRunner runner) Override this method to provide a different implementation of raw data iteration.voidremoveField(String fieldName) Remove first field with given name from column, row, or data.voidremoveField(PivotField field) Remove the field from column, row, or data.voidUnregister a customCalculatorsupported in this model.voidsetFieldKeyComparator(String fieldName, Comparator<Object> comparator) Set a comparator on a pivot field for node ordering.voidsetFieldKeyComparator(PivotField field, Comparator<Object> comparator) Set a comparator on a pivot field for node orderingvoidsetFieldKeyOrder(String fieldName, boolean ascending) Set the ordering of keys on a field.voidsetFieldKeyOrder(PivotField field, boolean ascending) Set the node ordering of the field.voidsetFieldSubtotals(String fieldName, Calculator[] subtotals) Sets the subtotal calculators on a field, or null to show no subtotal.voidsetFieldSubtotals(PivotField field, Calculator[] subtotals) Set the subtotals on a field.voidsetFieldSummary(String fieldName, Calculator summary) Sets the summary calculator on a field, or null to use the default one.voidsetFieldSummary(PivotField field, Calculator summary) Set the summary on a field.voidsetFieldType(String fieldName, PivotField.Type type) Change the type of a pivot field.voidsetFieldType(PivotField field, PivotField.Type type) Change the type of a pivot field.voidsetFieldType(PivotField field, PivotField.Type type, int index) Change the type of a pivot field and insert it at the given level (in case of COLUMN or ROW) or display position (in case of DATA).protected booleanshallReloadSourceSpace(CalculatorContextSignature current, CalculatorContextSignature required) Override this method to determine whether to reload source space more aggressively than default setting.protected voidsortColumnTree(SimplePivotHeaderTree colTree) Override this method to change the default node sorting in the column tree.protected voidsortRowTree(SimplePivotHeaderTree rowTree) Override this method to change the default node sorting in the row tree.protected voidDeprecated.protected final voidvoidForce to update the cached result in the model by rescanning the raw data.Methods inherited from class org.zkoss.pivot.impl.AbstractPivotModel
addPivotDataListener, fireEvent, removePivotDataListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.zkoss.pivot.PivotModel
addPivotDataListener, removePivotDataListener
-
Field Details
-
_space
-
_STD_CAL_TYPE_SIZE
protected static final int _STD_CAL_TYPE_SIZE -
NODE_COMPARATOR
-
-
Constructor Details
-
TabularPivotModel
Constructor- Parameters:
data- a matrix data <row<column<cell>>>columns- a list of column fields according to the matrix data in order.
-
-
Method Details
-
getRawData
Return the raw data collection. -
setFieldType
Change the type of a pivot field. The field will be at the last level of column/row in case of COLUMN or ROW, and will be the last one in display order in case of DATA.- Parameters:
fieldName- name of the field- See Also:
-
setFieldType
Description copied from interface:PivotModelExtChange the type of a pivot field and insert it at the given level (in case of COLUMN or ROW) or display position (in case of DATA).- Specified by:
setFieldTypein interfacePivotModelExtindex- the tree level or display position- See Also:
-
setFieldType
Description copied from interface:PivotModelExtChange the type of a pivot field. The field will be at the last level of column/row in case of COLUMN or ROW, and will be the last one in display order in case of DATA.- Specified by:
setFieldTypein interfacePivotModelExt- See Also:
-
getSourceDataIndex
Return the index of raw data columns the field corresponds to. -
getRowFields
-
getColumnFields
-
getDataFields
-
getFields
Description copied from interface:PivotModelReturn a list of pivot fields of the given type.- Specified by:
getFieldsin interfacePivotModel- See Also:
-
getFields
Description copied from interface:PivotModelReturn a list of all fields in the model.- Specified by:
getFieldsin interfacePivotModel
-
getField
Returns the pivot field from the specified field name, if any.Note: it only returns the first one matching with the field name.
-
removeField
Remove first field with given name from column, row, or data. In other words, the field is set to PivotField.Type.UNUSED type.- See Also:
-
removeField
Remove the field from column, row, or data. In other words, the field is set to PivotField.Type.UNUSED type.- See Also:
-
clearAllFields
public void clearAllFields(boolean complete) Remove all pivot fields from column, row, and data. In other words, all field are set to PivotField.Type.UNUSED type- Parameters:
complete- true to additionally remove custom summary, subtotals and group handlers- See Also:
-
setFieldKeyOrder
Set the ordering of keys on a field. -
setFieldKeyOrder
Description copied from interface:PivotModelExt.SortCtrlSet the node ordering of the field.- Specified by:
setFieldKeyOrderin interfacePivotModelExt.SortCtrl
-
setFieldKeyComparator
Set a comparator on a pivot field for node ordering.- Parameters:
fieldName- the field on which the comparator appliescomparator- a comparator to sort field keys
-
setFieldKeyComparator
Description copied from interface:PivotModelExt.SortCtrlSet a comparator on a pivot field for node ordering- Specified by:
setFieldKeyComparatorin interfacePivotModelExt.SortCtrlcomparator- a comparator to sort field keys
-
updateRawData
public void updateRawData()Force to update the cached result in the model by rescanning the raw data. This will calliterateRawData(SimplePivotHeaderTree, SimplePivotHeaderTree, RawDataRunner)and hence trigger an iteration over the raw data. -
getSupportedCalculators
Description copied from interface:PivotModelExtReturn a list of supported Calculators as options of Summary and Subtotals.- Specified by:
getSupportedCalculatorsin interfacePivotModelExt
-
addSupportedCalculator
Register a customCalculatorsupported in this model. This will be reflected ingetSupportedCalculators()and hence are aware byPivotFieldControl. -
removeSupportedCalculator
Unregister a customCalculatorsupported in this model. This will be reflected ingetSupportedCalculators()and hence are aware byPivotFieldControl. -
clearSupportedCalculators
public void clearSupportedCalculators()Clear all registered customCalculatorsupported in this model. This will be reflected ingetSupportedCalculators()and hence are aware byPivotFieldControl. This does not affect built-in calculators. -
setFieldSummary
Sets the summary calculator on a field, or null to use the default one. -
setFieldSummary
Description copied from interface:PivotModelExtSet the summary on a field.- Specified by:
setFieldSummaryin interfacePivotModelExt
-
setFieldSubtotals
Sets the subtotal calculators on a field, or null to show no subtotal. -
setFieldSubtotals
Description copied from interface:PivotModelExtSet the subtotals on a field.- Specified by:
setFieldSubtotalsin interfacePivotModelExt
-
updateContextSpace
protected final void updateContextSpace() -
sortRowTree
Override this method to change the default node sorting in the row tree. The implementation usually involves callingSimplePivotHeaderTree.sort(Comparator)by providing a custom- Parameters:
rowTree- the header tree to be sorted- Since:
- 2.3.0
-
sortColumnTree
Override this method to change the default node sorting in the column tree. The implementation usually involves callingSimplePivotHeaderTree.sort(Comparator)by providing a custom- Parameters:
colTree- the header tree to be sorted- Since:
- 2.3.0
-
sortTrees
Deprecated.As of release 2.3.0, replaced bysortRowTree(SimplePivotHeaderTree)andsortColumnTree(SimplePivotHeaderTree) -
iterateRawData
protected void iterateRawData(SimplePivotHeaderTree colTree, SimplePivotHeaderTree rowTree, TabularPivotModel.RawDataRunner runner) Override this method to provide a different implementation of raw data iteration. For each iterated elementrow, the following should be called:runner.run(row, rowTree, colTree); -
getValue
public Number getValue(PivotHeaderNode rowNode, int rowCalIndex, PivotHeaderNode colNode, int colCalIndex, int dataIndex) Description copied from interface:PivotModelGet the calculated data summary at specific cell position.- Specified by:
getValuein interfacePivotModel- Parameters:
rowNode- row node, root node means grand totalrowCalIndex- row subtotal calculator index, -1 if not subtotalcolNode- column node, root node means grand totalcolCalIndex- column subtotal calculator index, -1 if not subtotaldataIndex- index of data fields
-
getCalculator
protected final ContextualCalculator<?> getCalculator(SimplePivotHeaderNode rowNode, int rowCalIndex, SimplePivotHeaderNode colNode, int colCalIndex, int dataIndex) -
getColumnHeaderTree
Description copied from interface:PivotModelReturn the header tree of columns.- Specified by:
getColumnHeaderTreein interfacePivotModel- See Also:
-
getRowHeaderTree
Description copied from interface:PivotModelReturn the header tree of rows.- Specified by:
getRowHeaderTreein interfacePivotModel- See Also:
-
getCalculatorContextSignature
Override this method to intervene the required signature for preparing source space. -
shallReloadSourceSpace
protected boolean shallReloadSourceSpace(CalculatorContextSignature current, CalculatorContextSignature required) Override this method to determine whether to reload source space more aggressively than default setting.- Parameters:
current- the current source space signaturerequired- the new required signature- Returns:
- true to for reloading source space
-
cast
-
cast
-
cast
-
sortRowTree(SimplePivotHeaderTree)andsortColumnTree(SimplePivotHeaderTree)