net.infordata.ifw2.web.jpa
Class AJpaEditableFolderModel<C>

java.lang.Object
  extended by net.infordata.ifw2.web.jpa.AJpaEditableFolderModel<C>
Type Parameters:
C -
All Implemented Interfaces:
java.io.Serializable, IDataGridModel, IEditableGridModel, IGridModel, IPojoEditableGridModel<C>, IPojoGridModel<C>, IReloadableGridModel, ITreeGridModel, IJpaFolderModel<C>, IJpaGridModel<C>

public abstract class AJpaEditableFolderModel<C>
extends java.lang.Object
implements IJpaFolderModel<C>, IPojoEditableGridModel<C>, IReloadableGridModel, java.io.Serializable

An adapter combining the IPojoEditableGridModel interface with an AJpaFolderModel instance.

Author:
valentino.proietti
See Also:
Serialized Form

Constructor Summary
AJpaEditableFolderModel(AJpaFolderModel<C> model, IPojoForm<C> form)
           
 
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()
           
 void close()
           
 int containsSearch(java.lang.String columnName, java.lang.String value, boolean forward, int startFrom)
           
 AJpaFolderModel.Builder<C> createSyncTask()
           
 IPojoForm<C> edit()
          Edit the current row.
 void expandAllChilds(int rowIndex)
           
 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.
 void forceReload(boolean restoreCurrentRow)
          Forces the model to reload data from the external storage at next IGridModel.sync().
 IJpaColumn 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()
           
 AJpaFolderModel.ATreeNode<C> getCurrentTreeNode()
           
 int getDataVersion()
           
 java.util.List<C> getDataView()
          Depending on the implementation, the returned collection may or may not contain the inserting pending pojo and may or may not contain a clone of the edited object instead of the original one.
 javax.persistence.EntityManager getEntityManager()
           
 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()
           
 AJpaFolderModel.ATreeNode<C> getTreeNode(int rowIndex)
           
 boolean getUseBackgroudSyncIfNeeded()
           
 java.lang.Object getValue(C pojo, int columnIndex)
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 AJpaFolderModel.ATreeNode<C> getZoomedNode()
           
 int getZoomingLevel()
           
 boolean goTo(C pojo, boolean fetchAllFakeNodesChilds)
          See AJpaFolderModel.goTo(Object, boolean)
 IPojoForm<C> insert(java.lang.Object param, boolean asChild)
           
 boolean isCurrentRowEditable()
           
 boolean isCurrentRowFreezed()
           
 boolean isEditing(C pojo)
           
 boolean isEditPending()
           
 boolean isFilterable()
           
 boolean isInsertAllowed(java.lang.Object param, boolean asChild)
           
 boolean isInserting(C pojo)
           
 boolean isInsertPending()
           
 boolean isSortable()
           
 boolean post()
          Use data in IEditableGridModel.getForm() to update the model after an IEditableGridModel.edit() or IEditableGridModel.insert(Object, boolean) call.
 boolean reload(int rowIndex)
          Reloads the row from the external storage.
 boolean remove()
           
 IForm replaceInsertedPojo(C newPojo)
           
 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 setExpanded(int rowIndex, boolean expanded)
          Expands or collapses a node.
 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 setUseBackgroudSyncIfNeeded(boolean value)
          see AJpaFolderModel.setUseBackgroudSyncIfNeeded(boolean)
 void sync()
          Keeps the internal IForm and the internal IGridModel in sync.
 void zoomIn()
          The current node becomes the new root.
 void zoomOut(int levels)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AJpaEditableFolderModel

public AJpaEditableFolderModel(AJpaFolderModel<C> model,
                               IPojoForm<C> form)
Method Detail

forceReload

public void forceReload(boolean restoreCurrentRow)
Description copied from interface: IReloadableGridModel
Forces the model to reload data from the external storage at next IGridModel.sync().
It is usable to free up resources.

Specified by:
forceReload in interface IReloadableGridModel
Parameters:
restoreCurrentRow - - If true the model shall try to restore the old current row.
If the method is called more than one time (with a true value) without an implicit or explicit IGridModel.sync() the current-row at the moment of the first call must be used.

reload

public boolean reload(int rowIndex)
               throws OutOfBoundsException
Description copied from interface: IReloadableGridModel
Reloads the row from the external storage.

Specified by:
reload in interface IReloadableGridModel
Returns:
true if the row still exists, false if it has been removed or replaced.
Throws:
OutOfBoundsException

goTo

public boolean goTo(C pojo,
                    boolean fetchAllFakeNodesChilds)
See AJpaFolderModel.goTo(Object, boolean)

Specified by:
goTo in interface IJpaFolderModel<C>
Parameters:
pojo - - uses #getPathTo(EntityManager, Object) to build a path to the pojo.
The pojo becomes the current one on next IGridModel.sync().
fetchAllFakeNodesChilds - - true if childs of fake nodes in the path are all fetched, this ensures that the rest of entities in the path are founded.
Returns:
true if a path to the pojo has been found

close

public void close()

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 IPojoForm<C> 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 IPojoForm<C> insert(java.lang.Object param,
                           boolean asChild)
Specified by:
insert in interface IEditableGridModel
Parameters:
asChild - - true means insert a child, false means insert a sibling.
param - - a generic parameter, the model can use to determine the type of row to insert.
Returns:
the inserting IForm, it must be the same returned by IEditableGridModel.getForm() at least until a IEditableGridModel.cancel()

replaceInsertedPojo

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

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.

canRemoveCurrentRow

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

isCurrentRowEditable

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

isInsertAllowed

public boolean isInsertAllowed(java.lang.Object param,
                               boolean asChild)
Specified by:
isInsertAllowed in interface IEditableGridModel
Parameters:
asChild - - true to insert a child, false to insert a sibling of the current node
Returns:
true by default or if asChild then verifies that there is a current node and it is not an ITreeNode.isLeaf().

post

public boolean post()
Description copied from interface: IEditableGridModel
Use data in IEditableGridModel.getForm() to update the model after an IEditableGridModel.edit() or IEditableGridModel.insert(Object, boolean) call.

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 IJpaColumn getColumn(int columnIndex)
Specified by:
getColumn in interface IGridModel
Specified by:
getColumn in interface IJpaGridModel<C>
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 final int getCurrentRow()
Specified by:
getCurrentRow in interface IGridModel
Returns:
the current row, a number less than 0 means none.

getCurrentRowCount

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

getValueAt

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

getPojo

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

getTreeNode

public AJpaFolderModel.ATreeNode<C> getTreeNode(int rowIndex)
                                         throws OutOfBoundsException
Specified by:
getTreeNode in interface ITreeGridModel
Specified by:
getTreeNode in interface IJpaFolderModel<C>
Parameters:
rowIndex -
Returns:
the tree node at the given index.
Throws:
OutOfBoundsException - - The contract defined in getValueAt(int, int) must be respected.

getCurrentTreeNode

public AJpaFolderModel.ATreeNode<C> getCurrentTreeNode()
Specified by:
getCurrentTreeNode in interface ITreeGridModel
Specified by:
getCurrentTreeNode in interface IJpaFolderModel<C>
Returns:
the current node, null if none.

setExpanded

public void setExpanded(int rowIndex,
                        boolean expanded)
Expands or collapses a node.

Specified by:
setExpanded in interface ITreeGridModel
Parameters:
rowIndex -
expanded - - true to expand

expandAllChilds

public void expandAllChilds(int rowIndex)
Specified by:
expandAllChilds in interface IJpaFolderModel<C>
Parameters:
rowIndex - -1 means all childs of all nodes.

zoomIn

public void zoomIn()
Description copied from interface: IJpaFolderModel
The current node becomes the new root.

Specified by:
zoomIn in interface IJpaFolderModel<C>

zoomOut

public void zoomOut(int levels)
Specified by:
zoomOut in interface IJpaFolderModel<C>
Parameters:
levels - - the number of parents to climb up.
Less or equal to zero means all.

getZoomedNode

public final AJpaFolderModel.ATreeNode<C> getZoomedNode()
Specified by:
getZoomedNode in interface IJpaFolderModel<C>
Returns:
the currently zoomed node.

getZoomingLevel

public final int getZoomingLevel()
Specified by:
getZoomingLevel in interface IJpaFolderModel<C>
Returns:
the zoom deep, zero means none.

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.

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.

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

getDataView

public final java.util.List<C> getDataView()
Description copied from interface: IPojoEditableGridModel
Depending on the implementation, the returned collection may or may not contain the inserting pending pojo and may or may not contain a clone of the edited object instead of the original one.

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.

setUseBackgroudSyncIfNeeded

public final void setUseBackgroudSyncIfNeeded(boolean value)
see AJpaFolderModel.setUseBackgroudSyncIfNeeded(boolean)

Specified by:
setUseBackgroudSyncIfNeeded in interface IJpaFolderModel<C>
Parameters:
value -

getUseBackgroudSyncIfNeeded

public final boolean getUseBackgroudSyncIfNeeded()
Specified by:
getUseBackgroudSyncIfNeeded in interface IJpaFolderModel<C>

createSyncTask

public final AJpaFolderModel.Builder<C> createSyncTask()
Specified by:
createSyncTask in interface IJpaFolderModel<C>
Returns:
see AJpaFolderModel.createSyncTask().

sync

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

Specified by:
sync in interface IGridModel
Throws:
OutOfBoundsException

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 final java.lang.Class<C> getPojoType()
Specified by:
getPojoType in interface IPojoGridModel<C>

getEntityManager

public final javax.persistence.EntityManager getEntityManager()

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.

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

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

isFilterable

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

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

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.