JIDE 3.5.15

com.jidesoft.pivot
Class TableModelPivotDataSource

java.lang.Object
  extended by com.jidesoft.pivot.TableModelPivotDataSource
All Implemented Interfaces:
PivotDataSource

public class TableModelPivotDataSource
extends Object
implements PivotDataSource


Field Summary
protected  IFilterableTableModel _filterTableModel
           
protected  TableModel _originalTableModel
           
protected  IFilterableTableModel _tableModel
           
 
Constructor Summary
TableModelPivotDataSource(TableModel originalTableModel)
           
 
Method Summary
 void addTableModelListener(TableModelListener listener)
          Adds the table model listener.
 void applyFilters()
          Tells the data source to apply the filters after all filters have been set using PivotDataSource.setFilter(Object[],int,boolean) method.
 void applyFilters(int[] rowFieldIndices, int[] columnFieldIndices, int[] dataFieldIndices, int[] filterFieldIndices)
          Tells the data source to apply the filters after all filters have been set using PivotDataSource.setFilter(Object[],int,boolean) method.
 void clearFilters()
          Tells the data source to clear all existing filters so that we can start to use PivotDataSource.setFilter(Object[],int,boolean) method to set the filters.
protected  IFilterableTableModel createFilterableTableModel(TableModel model)
          Create inner filterable table model to support filtering feature in PivotTablePane.
 int getActualRowIndex(int visualRowIndex)
          Gets the actual row index in the original table model.
 int getFieldCount()
          Gets number of fields in this data source.
 String getFieldName(int fieldIndex)
          Gets the field name.
 String getFieldTitle(int fieldIndex)
          Gets the field title.
 Class<?> getFieldType(int fieldIndex)
          Gets the field type.
 int getFilteredRowIndex(int actualRowIndex)
          Gets the row index after filtering so that we can use PivotDataSource.getValueAt(int,int) or PivotDataSource.setValueAt(Object,int,int) methods.
 Set<Object> getPossibleValues(int fieldIndex, boolean filterField, boolean isNullAllowed)
          Gets the possible values.
 int getRowCount()
          Gets the row count.
 TableModel getTableModel()
           
 Object getValueAt(int rowIndex, int fieldIndex)
          Gets the value at the specified field index and the row index.
 boolean hasFilter()
          Get if the data source has filter applying on it.
 void removeTableModelListener(TableModelListener listener)
          Removes the table model listener that was added earlier.
 void setExcludeFilter(Object[] values, int fieldIndex, boolean filterField)
          Sets the deselected possible values for the field.
 void setFilter(Filter filter, int fieldIndex, boolean filterField)
          Sets the Filter for the field.
 void setFilter(Object[] values, int fieldIndex, boolean filterField)
          Sets the possible values for the field.
 void setTableModel(TableModel tableModel)
           
 void setValueAt(Object value, int rowIndex, int fieldIndex)
          Gets the value at the specified field index and the row index.
protected  void updatePossibleValues(Set<Object> values, int fieldIndex, int row, int viewRow, boolean filterField, boolean isNullAllowed)
          Updates the possible value from the specified row index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_originalTableModel

protected TableModel _originalTableModel

_filterTableModel

protected IFilterableTableModel _filterTableModel

_tableModel

protected IFilterableTableModel _tableModel
Constructor Detail

TableModelPivotDataSource

public TableModelPivotDataSource(TableModel originalTableModel)
Method Detail

setTableModel

public void setTableModel(TableModel tableModel)

createFilterableTableModel

protected IFilterableTableModel createFilterableTableModel(TableModel model)
Create inner filterable table model to support filtering feature in PivotTablePane.

This method will be created twice every time setTableModel is invoked. The first time is to create a FilterableTableModel for filter fields, the second time is to create a FilterablTableModel for row/column/data fields.

The default implementation is just new FilterableTableModel(model).

Parameters:
model - the original table model
Returns:
the wrapping FilterableTableModel instance.

getTableModel

public TableModel getTableModel()

getFieldCount

public int getFieldCount()
Description copied from interface: PivotDataSource
Gets number of fields in this data source.

Specified by:
getFieldCount in interface PivotDataSource
Returns:
the field count.

getFieldName

public String getFieldName(int fieldIndex)
Description copied from interface: PivotDataSource
Gets the field name. The name should be unique in this data source.

Specified by:
getFieldName in interface PivotDataSource
Parameters:
fieldIndex - the field index.
Returns:
the field name.

getFieldTitle

public String getFieldTitle(int fieldIndex)
Description copied from interface: PivotDataSource
Gets the field title.

Specified by:
getFieldTitle in interface PivotDataSource
Parameters:
fieldIndex - the field index.
Returns:
the title of the field.

getFieldType

public Class<?> getFieldType(int fieldIndex)
Description copied from interface: PivotDataSource
Gets the field type.

Specified by:
getFieldType in interface PivotDataSource
Parameters:
fieldIndex - the field index.
Returns:
the field type.

getRowCount

public int getRowCount()
Description copied from interface: PivotDataSource
Gets the row count. If there is filtering, it should return the row count after filtering.

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

getValueAt

public Object getValueAt(int rowIndex,
                         int fieldIndex)
Description copied from interface: PivotDataSource
Gets the value at the specified field index and the row index.

Specified by:
getValueAt in interface PivotDataSource
Parameters:
rowIndex - the row index. It is the index after filtering.
fieldIndex - the field index.
Returns:
the value.

setValueAt

public void setValueAt(Object value,
                       int rowIndex,
                       int fieldIndex)
Description copied from interface: PivotDataSource
Gets the value at the specified field index and the row index.

Specified by:
setValueAt in interface PivotDataSource
Parameters:
value - the new value.
rowIndex - the row index. It is the index after filtering.
fieldIndex - the field index.

updatePossibleValues

protected void updatePossibleValues(Set<Object> values,
                                    int fieldIndex,
                                    int row,
                                    int viewRow,
                                    boolean filterField,
                                    boolean isNullAllowed)
Updates the possible value from the specified row index. If the field is a filter field, we will get the values from the _originalTableModel. Otherwise, we will get it from _filterTableModel.

Parameters:
values - the set of possible values.
fieldIndex - the field index
row - the row index as in the original table model
viewRow - the row index as in the filterable table model.
filterField - true if the field is a filter field. Otherwise false.
isNullAllowed - true if we will add null to the possible values set. Otherwise do not add.

getPossibleValues

public Set<Object> getPossibleValues(int fieldIndex,
                                     boolean filterField,
                                     boolean isNullAllowed)
Gets the possible values.

Specified by:
getPossibleValues in interface PivotDataSource
Parameters:
fieldIndex - the field index
filterField - If the field is a filter field. The difference is that a filter field will include values even though they are filtered by other filter fields, and a non-filter field will not.* @return
isNullAllowed - whether null value is allowed.
Returns:
the possible values.

hasFilter

public boolean hasFilter()
Description copied from interface: PivotDataSource
Get if the data source has filter applying on it.

Specified by:
hasFilter in interface PivotDataSource
Returns:
true if there are filters. Otherwise false.

clearFilters

public void clearFilters()
Description copied from interface: PivotDataSource
Tells the data source to clear all existing filters so that we can start to use PivotDataSource.setFilter(Object[],int,boolean) method to set the filters.

Specified by:
clearFilters in interface PivotDataSource

applyFilters

public void applyFilters()
Description copied from interface: PivotDataSource
Tells the data source to apply the filters after all filters have been set using PivotDataSource.setFilter(Object[],int,boolean) method. If you need to know the field indices of each area, you can override other applyFilters method with four int[] parameters.

Specified by:
applyFilters in interface PivotDataSource

applyFilters

public void applyFilters(int[] rowFieldIndices,
                         int[] columnFieldIndices,
                         int[] dataFieldIndices,
                         int[] filterFieldIndices)
Description copied from interface: PivotDataSource
Tells the data source to apply the filters after all filters have been set using PivotDataSource.setFilter(Object[],int,boolean) method. This method tells you the field indices of each area. In TableModelPivotDataSource implementation, we simply call PivotDataSource.applyFilters() as that implementation doesn't need to know the field indices.

Specified by:
applyFilters in interface PivotDataSource
Parameters:
rowFieldIndices - the field indices for row fields.
columnFieldIndices - the field indices for column fields.
dataFieldIndices - the field indices for data fields.
filterFieldIndices - the field indices for filter fields.

setFilter

public void setFilter(Object[] values,
                      int fieldIndex,
                      boolean filterField)
Description copied from interface: PivotDataSource
Sets the possible values for the field.

Specified by:
setFilter in interface PivotDataSource
Parameters:
values - the possible values.
fieldIndex - the field index.
filterField - whether the field is a filter field.

setExcludeFilter

public void setExcludeFilter(Object[] values,
                             int fieldIndex,
                             boolean filterField)
Description copied from interface: PivotDataSource
Sets the deselected possible values for the field.

Specified by:
setExcludeFilter in interface PivotDataSource
Parameters:
values - the deselected possible values.
fieldIndex - the field index.
filterField - whether the field is a filter field.

setFilter

public void setFilter(Filter filter,
                      int fieldIndex,
                      boolean filterField)
Description copied from interface: PivotDataSource
Sets the Filter for the field.

Specified by:
setFilter in interface PivotDataSource
Parameters:
filter - the Filter.
fieldIndex - the field index.
filterField - whether the field is a filter field.

getFilteredRowIndex

public int getFilteredRowIndex(int actualRowIndex)
Description copied from interface: PivotDataSource
Gets the row index after filtering so that we can use PivotDataSource.getValueAt(int,int) or PivotDataSource.setValueAt(Object,int,int) methods.

Specified by:
getFilteredRowIndex in interface PivotDataSource
Parameters:
actualRowIndex - the actual row index.
Returns:
the filtered row index. -1 of the row is filtered.

getActualRowIndex

public int getActualRowIndex(int visualRowIndex)
Description copied from interface: PivotDataSource
Gets the actual row index in the original table model. You can use this to get the actual index based on the visual row index you got in PivotDataModel.getDataAt(int, int) method.

Specified by:
getActualRowIndex in interface PivotDataSource
Parameters:
visualRowIndex - the visual row index.
Returns:
the actual row index. -1 of the row is filtered.

addTableModelListener

public void addTableModelListener(TableModelListener listener)
Description copied from interface: PivotDataSource
Adds the table model listener. Although there is no table model concept in the data source, TableModelEvent can still be used to indicate data change in the data source. Please note, the row index is the index as in the original data without filtering. When you fire the table model event, you can leave the source of it to null.

Specified by:
addTableModelListener in interface PivotDataSource
Parameters:
listener - the table model listener to be added.

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Description copied from interface: PivotDataSource
Removes the table model listener that was added earlier.

Specified by:
removeTableModelListener in interface PivotDataSource
Parameters:
listener - the table model listener to be removed.

JIDE 3.5.15