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

java.lang.Object
  extended by net.infordata.ifw2.web.grds.APojoEditableDataGridModel<C>
Type Parameters:
C -
All Implemented Interfaces:
java.io.Serializable, IDataGridModel, IEditableGridModel, IGridModel, IPojoEditableGridModel<C>, IPojoGridModel<C>

public abstract class APojoEditableDataGridModel<C>
extends java.lang.Object
implements IPojoEditableGridModel<C>, IPojoGridModel<C>, IDataGridModel, java.io.Serializable

An adapter combining the IEditableGridModel interface with an PojoGridModel instance.

Author:
valentino.proietti
See Also:
Serialized Form

Constructor Summary
APojoEditableDataGridModel(PojoDataGridModel<C> model, IPojoForm<C> form)
           
APojoEditableDataGridModel(PojoDataGridModel<C> model, IPojoForm<C> form, java.util.Comparator<? super C> univocityComparator)
           
 
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.
 void cancel()
          Cancel any pending or insert operations, if there are none, nothing happens.
 boolean canDoContainsSearch()
           
 boolean canRemoveCurrentRow()
           
 boolean canSearchOnSortedColumn()
           
 int containsSearch(java.lang.String columnName, java.lang.String value, boolean forward, int startFrom)
           
 IForm edit()
          Edit the current row.
 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.
 IColumn getColumn(int columnIndex)
           
 int getColumnCount()
           
 IColumnGroup getColumnGroup(java.lang.String groupId)
           
 int getColumnIndex(java.lang.String columnName)
           
 java.lang.String getColumnName(int columnIndex)
           
 C getCurrentPojo()
           
 int getCurrentRow()
           
 int getCurrentRowCount()
           
 java.util.List<C> getData()
          Any modification maded to the returned collection is reflected into the model.
 int getDataVersion()
           
 java.util.List<C> getDataView()
          If an insert or edit operation is pending, the pojo is not contained in the returned collection.
 java.util.Map<java.lang.String,AFilterDefinition<?>> getFilters()
           
 IPojoForm<C> getForm()
           
 C getPojo(int rowIndex)
           
 java.lang.Class<C> getPojoType()
           
 java.lang.String getPropertyName(int columnIndex)
           
 int getRowCount()
           
 java.lang.Boolean getSortedAscendingIndicator()
           
 java.lang.String getSortedColumn()
           
 java.lang.Object getValue(C pojo, int columnIndex)
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 IForm insert(java.lang.Object param, boolean afterCurrentRow)
           
 boolean isCurrentRowEditable()
           
 boolean isCurrentRowFreezed()
           
 boolean isEditing(C pojo)
           
 boolean isEditPending()
           
 boolean isFilterable()
           
 boolean isInsertAllowed(java.lang.Object param, boolean afterCurrentRow)
           
 boolean isInserting(C pojo)
           
 boolean isInsertPending()
           
 boolean isSortable()
           
 boolean post()
          If in edit mode, the current record instance is replaced.
 boolean remove()
           
 IForm replaceInsertedPojo(C pojo)
           
 int rowIndexOf(C pojo)
           
 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()
          Keeps the internal IForm and the internal IGridModel in sync.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

APojoEditableDataGridModel

public APojoEditableDataGridModel(PojoDataGridModel<C> model,
                                  IPojoForm<C> form,
                                  java.util.Comparator<? super C> univocityComparator)
Parameters:
model -
form -
univocityComparator - - if specified, when an insert or a change is confirmed, any pojo matching the new or changed pojo is removed.

APojoEditableDataGridModel

public APojoEditableDataGridModel(PojoDataGridModel<C> model,
                                  IPojoForm<C> form)
Method Detail

canRemoveCurrentRow

public boolean canRemoveCurrentRow()
Specified by:
canRemoveCurrentRow in interface IEditableGridModel

cancel

public void cancel()
Description copied from interface: IEditableGridModel
Cancel any pending or insert operations, if there are none, nothing happens.

Specified by:
cancel in interface IEditableGridModel

edit

public IForm edit()
Description copied from interface: IEditableGridModel
Edit the current row.

Specified by:
edit in interface IEditableGridModel
Returns:
the editing IForm, it must be the same returned by IEditableGridModel.getForm() at least until a IEditableGridModel.cancel()

getForm

public final IPojoForm<C> getForm()
Specified by:
getForm in interface IEditableGridModel
Returns:
the IForm usable to edit current row values.
Even if there is no current row, an IForm must be returned.

insert

public IForm insert(java.lang.Object param,
                    boolean afterCurrentRow)
Specified by:
insert in interface IEditableGridModel
Parameters:
param - - a generic parameter, the model can use to determine the type of row to insert.
afterCurrentRow - - false: the object is inserted in place of the current row, true: it is inserted after the current row.
Returns:
the inserting IForm, it must be the same returned by IEditableGridModel.getForm() at least until a IEditableGridModel.cancel()

replaceInsertedPojo

public IForm replaceInsertedPojo(C pojo)
Specified by:
replaceInsertedPojo in interface IPojoEditableGridModel<C>
Parameters:
pojo - - replaces the inserted pojo, the form is refreshed.
Returns:
itself

isCurrentRowEditable

public boolean isCurrentRowEditable()
Specified by:
isCurrentRowEditable in interface IEditableGridModel

isInsertPending

public final boolean isInsertPending()
Specified by:
isInsertPending in interface IEditableGridModel
Returns:
true if an insert operation is pending, use IEditableGridModel.cancel() to abort the operation.

isEditPending

public final boolean isEditPending()
Specified by:
isEditPending in interface IEditableGridModel
Returns:
true if an edit operation is pending, use IEditableGridModel.cancel() to abort the operation.

isInsertAllowed

public boolean isInsertAllowed(java.lang.Object param,
                               boolean afterCurrentRow)
Specified by:
isInsertAllowed in interface IEditableGridModel

post

public boolean post()
If in edit mode, the current record instance is replaced.

Specified by:
post in interface IEditableGridModel
Returns:
false if the model cannot be updated with the current data.
In this case any user error should be attached to the IForm instance and the model doesn't exit from the pending insert or edit state. It is possible for the model to open a message dialog in case of errors (see FlowContext.modalDialog(net.infordata.ifw2.web.ctrl.IFlowAsDialog, net.infordata.ifw2.web.ctrl.IDialogCallback)).

remove

public boolean remove()
Specified by:
remove in interface IEditableGridModel
Returns:
true if the row has been removed.
It is possible for the model to open a message dialog in case of errors (see FlowContext.modalDialog(net.infordata.ifw2.web.ctrl.IFlowAsDialog, net.infordata.ifw2.web.ctrl.IDialogCallback)).

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
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.

getColumnGroup

public IColumnGroup getColumnGroup(java.lang.String groupId)
Specified by:
getColumnGroup in interface IGridModel
Returns:
if null then default behaviors and values are assumed.

getColumn

public IColumn getColumn(int columnIndex)
Specified by:
getColumn in interface IGridModel
Returns:
always not null otherwise an exception is thrown if the column doesn't exist.

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface IGridModel

getColumnIndex

public int getColumnIndex(java.lang.String columnName)
Specified by:
getColumnIndex in interface IGridModel
Returns:
less than 0 if not found.

getColumnName

public java.lang.String getColumnName(int columnIndex)
Specified by:
getColumnName in interface IGridModel

getCurrentRow

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

getCurrentRowCount

public int getCurrentRowCount()
Specified by:
getCurrentRowCount in interface IGridModel
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
Returns:
the row count, if not known yet Integer.MAX_VALUE.

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Specified by:
getValueAt in interface IGridModel
Returns:
the value for the given coordinates.

getPropertyName

public final java.lang.String getPropertyName(int columnIndex)
Specified by:
getPropertyName in interface IPojoGridModel<C>
Returns:
null if the column is not related to a pojo property, otherwise the property name which can be different from the column name.

getPojo

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

rowIndexOf

public int rowIndexOf(C pojo)
Specified by:
rowIndexOf in interface IPojoGridModel<C>
Returns:
the row index of the given pojo.

getValue

public final java.lang.Object getValue(C pojo,
                                       int columnIndex)
Specified by:
getValue in interface IPojoGridModel<C>
Parameters:
pojo - - the pojo to extract value from.
columnIndex - - the columnIndex which must be mapped to a pojo property or to a computed value.
Returns:
the pojo property value for the given column.

getCurrentPojo

public final C getCurrentPojo()
Specified by:
getCurrentPojo in interface IPojoGridModel<C>
Returns:
the current pojo, null if none.

isCurrentRowFreezed

public boolean isCurrentRowFreezed()
Specified by:
isCurrentRowFreezed in interface IGridModel
Returns:
true if some sort of editing is happening on the current row, this freezes the current row.

setCurrentRow

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

getData

public final java.util.List<C> getData()
Any modification maded to the returned collection is reflected into the model.

Returns:
the model back-end collection.
Throws:
java.lang.IllegalStateException - if an edit or insert operation is pending.

getDataView

public final java.util.List<C> getDataView()
If an insert or edit operation is pending, the pojo is not contained in the returned collection.

Specified by:
getDataView in interface IPojoEditableGridModel<C>
Specified by:
getDataView in interface IPojoGridModel<C>
Returns:
A read-only snapshot list reflecting any sort order or filter applied, it is unmodifiable but can change if "back-end" collection or data changes.

isEditing

public final boolean isEditing(C pojo)
Specified by:
isEditing in interface IPojoEditableGridModel<C>
Returns:
true if there is a pending edit operation and if the given pojo instance is the edited pojo or a temporary clone of it.

isInserting

public final boolean isInserting(C pojo)
Specified by:
isInserting in interface IPojoEditableGridModel<C>
Returns:
true if there is a pending insert operation and the given pojo instance is the one behing inserted.

sync

public void sync()
Keeps the internal IForm and the internal IGridModel in sync.

Specified by:
sync in interface IGridModel

getDataVersion

public final int getDataVersion()
Specified by:
getDataVersion in interface IPojoGridModel<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.

getPojoType

public java.lang.Class<C> getPojoType()
Specified by:
getPojoType in interface IPojoGridModel<C>

isSortable

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

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

getSortedColumn

public 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).

searchOnSortedColumn

public int searchOnSortedColumn(java.lang.Object value)
                         throws java.lang.IllegalStateException
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).
Throws:
java.lang.IllegalStateException - - if there isn't a sorted column.

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.

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.