net.infordata.ifw2.web.grds
Class PojoDataGridModel<C>

java.lang.Object
  extended by net.infordata.ifw2.web.grds.APojoGridModel<C>
      extended by net.infordata.ifw2.web.grds.PojoDataGridModel<C>
Type Parameters:
C -
All Implemented Interfaces:
java.io.Serializable, IDataGridModel, IGridModel, IPojoGridModel<C>
Direct Known Subclasses:
EnumModel

public class PojoDataGridModel<C>
extends APojoGridModel<C>
implements IDataGridModel

An IPojoGridModel and IDataGridModel backed by a Collection supporting data filtering and sorting only for columns bounded to any Comparable pojo property.

Author:
valentino.proietti
See Also:
Serialized Form

Constructor Summary
PojoDataGridModel(java.lang.Class<C> c)
           
PojoDataGridModel(java.lang.Class<C> c, java.util.Collection<? extends C> data)
           
 
Method Summary
 void applyFilters(java.lang.String filteredColumnName, java.util.Map<java.lang.String,AFilterDefinition<?>> filters)
          If IDataGridModel.isFilterable() then this method can be used to change data filter definitions, otherwise you can assume that it is never used.
 boolean canDoContainsSearch()
           
 boolean canSearchOnSortedColumn()
           
 int containsSearch(java.lang.String columnName, java.lang.String value, boolean forward, int startFrom)
           
 int fetchRows(int rowIndex, int count)
          Used by the ui to ensure that the request rows really exist without the need to retrieve any column value.
 int getCurrentRow()
           
 int getCurrentRowCount()
           
 java.util.List<C> getData()
          Any modification maded to the returned collection is reflected into the model as soon as the _sync() method is directly called or indirectly called.
 int getDataVersion()
           
 java.util.List<C> getDataView()
           
 java.util.Map<java.lang.String,AFilterDefinition<?>> getFilters()
           
 C getPojo(int rowIndex)
           
 int getRowCount()
           
 java.lang.Boolean getSortedAscendingIndicator()
           
 java.lang.String getSortedColumn()
           
 boolean isFilterable()
           
 boolean isSortable()
           
 IColumn removeColumn(java.lang.String columnName)
           
 int searchOnSortedColumn(java.lang.Object value)
          Searches the given value between values of the currently sorted column.
 void setCurrentRow(int rowIndex)
           
 void setSortedColumn(java.lang.String columnName, boolean ascending)
          If IDataGridModel.isSortable() then this method is used to change the sort order otherwise you can assume that it is never used.
 void sync()
          Called by the framework just before displaying the AGridFlow.
 
Methods inherited from class net.infordata.ifw2.web.grds.APojoGridModel
getClassInfo, getColumn, getColumnCount, getColumnGroup, getColumnGroupsMap, getColumnIndex, getColumnName, getCurrentPojo, getPojoType, getProperty, getPropertyName, getValue, getValueAt, isCurrentRowFreezed, registerColumn, registerColumn, registerColumn, rowIndexOf
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.infordata.ifw2.web.grds.IGridModel
getColumn, getColumnCount, getColumnGroup, getColumnIndex, getColumnName, getValueAt, isCurrentRowFreezed
 

Constructor Detail

PojoDataGridModel

public PojoDataGridModel(java.lang.Class<C> c)

PojoDataGridModel

public PojoDataGridModel(java.lang.Class<C> c,
                         java.util.Collection<? extends C> data)
Method Detail

removeColumn

public IColumn removeColumn(java.lang.String columnName)
Overrides:
removeColumn in class APojoGridModel<C>
Parameters:
columnName -
Returns:
the removed IColumn or null if none.

getData

public java.util.List<C> getData()
Any modification maded to the returned collection is reflected into the model as soon as the _sync() method is directly called or indirectly called.

Returns:
the model back-end collection.

getDataView

public final java.util.List<C> getDataView()
Specified by:
getDataView in interface IPojoGridModel<C>
Returns:
a snapshot list reflecting any sort order or filter applied, it is unmodifiable but can change if the backend collection changes.

sync

public void sync()
Description copied from interface: IGridModel
Called by the framework just before displaying the AGridFlow.
Here is where the model can, as an example, ensure that depending sub models are synchronized or to restore data after a serialization.
Keep in mind that after synchronizing the model internal state can be changed.

Specified by:
sync in interface IGridModel
Overrides:
sync in class APojoGridModel<C>

getDataVersion

public int getDataVersion()
Specified by:
getDataVersion in interface IPojoGridModel<C>
Specified by:
getDataVersion in class APojoGridModel<C>
Returns:
The value must change any time one or more CRUD operations have been completed on the content model and after the model has been synchronized (see IGridModel.sync().
This can be used by wrapping models to update their state when the wrapped model changes.

setCurrentRow

public void setCurrentRow(int rowIndex)
Specified by:
setCurrentRow in interface IGridModel

getCurrentRow

public int getCurrentRow()
Specified by:
getCurrentRow in interface IGridModel
Returns:
the current row, a number less than 0 means none.

fetchRows

public int fetchRows(int rowIndex,
                     int count)
Description copied from interface: IGridModel
Used by the ui to ensure that the request rows really exist without the need to retrieve any column value.
The ui is simply saying that it wants to get access to the given rows.

Specified by:
fetchRows in interface IGridModel
Specified by:
fetchRows in class APojoGridModel<C>
Parameters:
rowIndex - - starting from this index ...
count - - ... we want this number of rows
Returns:
the real number of rows founded.
Returning a number less than the requested number of rows means that the last row has been finally reached, in this case a following call to IGridModel.getRowCount() must return the real rows counter and a call to IGridModel.getCurrentRow() a valid row index.

getPojo

public C getPojo(int rowIndex)
Specified by:
getPojo in interface IPojoGridModel<C>
Specified by:
getPojo in class APojoGridModel<C>
Returns:
the pojo object at the given index.

getCurrentRowCount

public int getCurrentRowCount()
Specified by:
getCurrentRowCount in interface IGridModel
Specified by:
getCurrentRowCount in class APojoGridModel<C>
Returns:
the currently loaded rows, generally it is equal to IGridModel.getRowCount() but can be less if the model supports paging.

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface IGridModel
Specified by:
getRowCount in class APojoGridModel<C>
Returns:
the row count, if not known yet Integer.MAX_VALUE.

isFilterable

public boolean isFilterable()
Specified by:
isFilterable in interface IDataGridModel
Returns:
true if the model supports data filtering.

applyFilters

public void applyFilters(java.lang.String filteredColumnName,
                         java.util.Map<java.lang.String,AFilterDefinition<?>> filters)
Description copied from interface: IDataGridModel
If IDataGridModel.isFilterable() then this method can be used to change data filter definitions, otherwise you can assume that it is never used.

Specified by:
applyFilters in interface IDataGridModel
Parameters:
filteredColumnName - - used in case a the filter has been applied on a specific column, otherwise null.
Implementors must clone any AFilterDefinition.
filters - - filters to be applied per column

getFilters

public java.util.Map<java.lang.String,AFilterDefinition<?>> getFilters()
Specified by:
getFilters in interface IDataGridModel
Returns:
an unmodifiable map or null if no filter has been applied.

isSortable

public boolean isSortable()
Specified by:
isSortable in interface IDataGridModel
Returns:
true if the model supports changing of the sort order.

getSortedColumn

public final java.lang.String getSortedColumn()
Specified by:
getSortedColumn in interface IDataGridModel
Returns:
the sorted column, null if none.
It is called even if IDataGridModel.isSortable() == false, because the model can be sorted but not sortable (ie the sort order is not changeable with the gui).

getSortedAscendingIndicator

public java.lang.Boolean getSortedAscendingIndicator()
Specified by:
getSortedAscendingIndicator in interface IDataGridModel
Returns:
true if sorted in ascending order, false if in descending and null if not sorted.
It is called even if IDataGridModel.isSortable() == false, because the model can be sorted but not sortable (ie the sort order is not changeable with the ui).

setSortedColumn

public void setSortedColumn(java.lang.String columnName,
                            boolean ascending)
Description copied from interface: IDataGridModel
If IDataGridModel.isSortable() then this method is used to change the sort order otherwise you can assume that it is never used.

Specified by:
setSortedColumn in interface IDataGridModel

searchOnSortedColumn

public int searchOnSortedColumn(java.lang.Object value)
Description copied from interface: IDataGridModel
Searches the given value between values of the currently sorted column.

Specified by:
searchOnSortedColumn in interface IDataGridModel
Returns:
should be "compatible" with Collections.binarySearch(java.util.List, Object).

canSearchOnSortedColumn

public boolean canSearchOnSortedColumn()
Specified by:
canSearchOnSortedColumn in interface IDataGridModel
Returns:
true if IDataGridModel.searchOnSortedColumn(Object) can used.

containsSearch

public int containsSearch(java.lang.String columnName,
                          java.lang.String value,
                          boolean forward,
                          int startFrom)
Specified by:
containsSearch in interface IDataGridModel
Returns:
less than zero if nothing has been found

canDoContainsSearch

public boolean canDoContainsSearch()
Specified by:
canDoContainsSearch in interface IDataGridModel
Returns:
true if #containsSearch(int, String, boolean, int) can be used.