org.zkoss.pivot.impl
Class TabularPivotModel

java.lang.Object
  extended by org.zkoss.pivot.impl.AbstractPivotModel
      extended by org.zkoss.pivot.impl.TabularPivotModel
All Implemented Interfaces:
java.io.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:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.zkoss.pivot.PivotModelExt
PivotModelExt.SortCtrl
 
Field Summary
protected static java.util.Comparator<PivotHeaderNode> NODE_COMPARATOR
           
 
Constructor Summary
TabularPivotModel(java.lang.Iterable<? extends java.util.List<?>> data, java.util.List<java.lang.String> columns)
          Constructor
 
Method Summary
protected  void addRawValues(PivotHeaderNode rowNode, PivotHeaderNode colNode, java.util.List<?> row, TabularPivotField[] fields)
           
 void clearAllFields(boolean complete)
          Remove all pivot fields from column, row, and data.
protected  PivotHeaderTree[] createHeaderTrees()
          Create column and row header trees.
 TabularPivotField[] getColumnFields()
           
 PivotHeaderTree getColumnHeaderTree()
          Return the header tree of columns.
 TabularPivotField[] getDataFields()
           
 TabularPivotField getField(java.lang.String fieldName)
          Returns the pivot field from the specified field name, if any.
 TabularPivotField[] getFields()
          Return a list of all fields in the model.
 TabularPivotField[] getFields(PivotField.Type type)
          Return a list of pivot fields of the given type.
 java.lang.Iterable<? extends java.util.List<?>> getRawData()
          Return the raw data collection.
 java.util.List<java.lang.Object> getRawValues(PivotHeaderNode rowNode, PivotHeaderNode colNode, PivotField dataField)
          Return raw values intersected by column and row nodes, even if they are not leaves
 TabularPivotField[] getRowFields()
           
 PivotHeaderTree getRowHeaderTree()
          Return the header tree of rows.
 int getSourceDataIndex(PivotField field)
          Return the index of raw data columns the field corresponds to.
 java.lang.Number getValue(PivotHeaderNode rowNode, int rowCalIndex, PivotHeaderNode colNode, int colCalIndex, int dataIndex)
          Get the calculated data summary at specific cell position.
protected static java.util.List<java.lang.Object> getValues(TabularPivotField[] fields, java.util.List<?> row)
           
 void removeField(PivotField field)
          Remove the field from column, row, or data.
 void removeField(java.lang.String fieldName)
          Remove first field with given name from column, row, or data.
 void setFieldKeyComparator(PivotField field, java.util.Comparator<java.lang.Object> comparator)
          Set a comparator on a pivot field for node ordering
 void setFieldKeyComparator(java.lang.String fieldName, java.util.Comparator<java.lang.Object> comparator)
          Set a comparator on a pivot field for node ordering.
 void setFieldKeyOrder(PivotField field, boolean ascending)
          Set the node ordering of the field.
 void setFieldKeyOrder(java.lang.String fieldName, boolean ascending)
          Set the ordering of keys on a field.
 void setFieldType(PivotField field, PivotField.Type type)
          Change the type of a pivot field.
 void setFieldType(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).
 void setFieldType(java.lang.String fieldName, PivotField.Type type)
          Change the type of a pivot field.
 
Methods inherited from class org.zkoss.pivot.impl.AbstractPivotModel
addPivotDataListener, fireEvent, removePivotDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.zkoss.pivot.PivotModel
addPivotDataListener, removePivotDataListener
 

Field Detail

NODE_COMPARATOR

protected static final java.util.Comparator<PivotHeaderNode> NODE_COMPARATOR
Constructor Detail

TabularPivotModel

public TabularPivotModel(java.lang.Iterable<? extends java.util.List<?>> data,
                         java.util.List<java.lang.String> columns)
Constructor

Parameters:
data - a matrix data <row<column<cell>>>
columns - a list of column fields according to the matrix data in order.
Method Detail

getRawData

public java.lang.Iterable<? extends java.util.List<?>> getRawData()
Return the raw data collection.


setFieldType

public void setFieldType(java.lang.String fieldName,
                         PivotField.Type type)
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:
PivotField.Type

setFieldType

public void setFieldType(PivotField field,
                         PivotField.Type type,
                         int index)
Description copied from interface: PivotModelExt
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).

Specified by:
setFieldType in interface PivotModelExt
index - the tree level or display position
See Also:
PivotField.Type

setFieldType

public void setFieldType(PivotField field,
                         PivotField.Type type)
Description copied from interface: PivotModelExt
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.

Specified by:
setFieldType in interface PivotModelExt
See Also:
PivotField.Type

getSourceDataIndex

public int getSourceDataIndex(PivotField field)
Return the index of raw data columns the field corresponds to.


getRowFields

public final TabularPivotField[] getRowFields()

getColumnFields

public final TabularPivotField[] getColumnFields()

getDataFields

public final TabularPivotField[] getDataFields()

getFields

public TabularPivotField[] getFields(PivotField.Type type)
Description copied from interface: PivotModel
Return a list of pivot fields of the given type.

Specified by:
getFields in interface PivotModel
See Also:
PivotField, PivotField.Type

getFields

public TabularPivotField[] getFields()
Description copied from interface: PivotModel
Return a list of all fields in the model.

Specified by:
getFields in interface PivotModel

getField

public TabularPivotField getField(java.lang.String fieldName)
Returns the pivot field from the specified field name, if any.

Note: it only returns the first one matching with the field name.


removeField

public void removeField(java.lang.String fieldName)
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:
PivotField.Type

removeField

public void removeField(PivotField field)
Remove the field from column, row, or data. In other words, the field is set to PivotField.Type.UNUSED type.

See Also:
PivotField.Type

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:
PivotField.Type

setFieldKeyOrder

public void setFieldKeyOrder(java.lang.String fieldName,
                             boolean ascending)
Set the ordering of keys on a field.


setFieldKeyOrder

public void setFieldKeyOrder(PivotField field,
                             boolean ascending)
Description copied from interface: PivotModelExt.SortCtrl
Set the node ordering of the field.

Specified by:
setFieldKeyOrder in interface PivotModelExt.SortCtrl

setFieldKeyComparator

public void setFieldKeyComparator(java.lang.String fieldName,
                                  java.util.Comparator<java.lang.Object> comparator)
Set a comparator on a pivot field for node ordering.

Parameters:
fieldName - the field on which the comparator applies
comparator - a comparator to sort field keys

setFieldKeyComparator

public void setFieldKeyComparator(PivotField field,
                                  java.util.Comparator<java.lang.Object> comparator)
Description copied from interface: PivotModelExt.SortCtrl
Set a comparator on a pivot field for node ordering

Specified by:
setFieldKeyComparator in interface PivotModelExt.SortCtrl
comparator - a comparator to sort field keys

createHeaderTrees

protected PivotHeaderTree[] createHeaderTrees()
Create column and row header trees. Override this method to plug in customized PivotHeaderTree implementation.

Returns:
an array of PivotHeaderTree. 0: column tree, and 1: row tree

getValue

public java.lang.Number getValue(PivotHeaderNode rowNode,
                                 int rowCalIndex,
                                 PivotHeaderNode colNode,
                                 int colCalIndex,
                                 int dataIndex)
Description copied from interface: PivotModel
Get the calculated data summary at specific cell position.

Specified by:
getValue in interface PivotModel
Parameters:
rowNode - row node, root node means grand total
rowCalIndex - row subtotal calculator index, -1 if not subtotal
colNode - column node, root node means grand total
colCalIndex - column subtotal calculator index, -1 if not subtotal
dataIndex - index of data fields

getRawValues

public java.util.List<java.lang.Object> getRawValues(PivotHeaderNode rowNode,
                                                     PivotHeaderNode colNode,
                                                     PivotField dataField)
Return raw values intersected by column and row nodes, even if they are not leaves


getColumnHeaderTree

public PivotHeaderTree getColumnHeaderTree()
Description copied from interface: PivotModel
Return the header tree of columns.

Specified by:
getColumnHeaderTree in interface PivotModel
See Also:
PivotHeaderTree

getRowHeaderTree

public PivotHeaderTree getRowHeaderTree()
Description copied from interface: PivotModel
Return the header tree of rows.

Specified by:
getRowHeaderTree in interface PivotModel
See Also:
PivotHeaderTree

addRawValues

protected final void addRawValues(PivotHeaderNode rowNode,
                                  PivotHeaderNode colNode,
                                  java.util.List<?> row,
                                  TabularPivotField[] fields)

getValues

protected static final java.util.List<java.lang.Object> getValues(TabularPivotField[] fields,
                                                                  java.util.List<?> row)


Copyright © 2012. All Rights Reserved.