Package de.xima.fc.gui.model.data
Class EntityListModel<T extends ITransferableEntity>
- java.lang.Object
-
- de.xima.fc.gui.common.utils.msg.I18nUtils
-
- de.xima.fc.gui.common.utils.msg.MessageUtils
-
- de.xima.fc.gui.common.utils.msg.AMessaging
-
- de.xima.fc.gui.model.data.EntityListModel<T>
-
- All Implemented Interfaces:
IEntityListModel<T>
,IUpdatable
,Serializable
- Direct Known Subclasses:
EntityListModelSelectByView
,LicenseBean.EntityListModelImpl
,ProjectBean.EntityListModelImpl
,SystemMessagesBean.EntityListModelImpl
public class EntityListModel<T extends ITransferableEntity> extends AMessaging implements IEntityListModel<T>
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected List<T>
all
protected Class<T>
entityClass
protected List<T>
filtered
protected String
globalFilter
protected boolean
hasAddNewEntity
protected List<T>
marked
protected de.xima.cmn.criteria.QueryCriteriaManager
qcm
protected T
selected
-
Constructor Summary
Constructors Constructor Description EntityListModel(Class<T> entityClass, de.xima.cmn.criteria.QueryCriteriaManager qcm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMarked(T entity)
Adds the given entity to theList
of marked entitiesvoid
addNew()
Sets the currently selected model to a new model.void
create()
String
delete()
Deletes the currently selected model from the database.String
delete(String targetView)
Deletes the currently selected model from the database.String
deleteEntity(String targetView, T entity)
Same asIEntityListModel.delete(String)
, but takes the model to be deleted as an argument instead of deleting the currently selected model.String
deleteEntity(T entity)
Same asIEntityListModel.delete()
, but takes the model to be deleted as an argument instead of deleting the currently selected model.void
deleteMarkedEntities()
Deletes all marked entitiesIEntityContext
ec()
protected List<T>
fetchAll()
Fetches all available entities.List<T>
getAll()
List<T>
getAllPlusNew()
IGenericDao<T>
getDao()
List<T>
getFiltered()
String
getGlobalFilter()
List<T>
getMarked()
T
getNew()
T
getSelected()
boolean
hasEntity()
protected boolean
isDetached(de.xima.cmn.dao.interfaces.IEntity<Long> entity)
boolean
isEmptyList()
boolean
isMarkedDeletable()
boolean
isNew()
void
loadLazyData()
Can be overriden to initialize lazily loaded fields on the entity.void
onRowSelect(org.primefaces.event.SelectEvent event)
void
onRowSelectCheckbox(org.primefaces.event.SelectEvent event)
void
onRowUnselectCheckbox(org.primefaces.event.UnselectEvent event)
void
onToggleSelect(org.primefaces.event.ToggleSelectEvent event)
void
removeMarked(T entity)
Removes the given entity from theList
of marked entitiesvoid
save()
Saves the currently selected model to the database.void
save(boolean addSuccessMessage, boolean addErrorMessage)
protected void
selectDefault()
Called when no item is selected.void
setFiltered(List<T> filtered)
Sets the list of filtered models.void
setGlobalFilter(String globalFilter)
void
setHasAddNewEntity(boolean isNewEntity)
void
setMarked(List<T> marked)
Sets the list of marked entitiesvoid
setSelected(T selected)
Sets the currently selected model to the given model.void
setSelectedFromMarked()
If there is exactly one entity marked, makes it the selected onevoid
update()
void
updateData()
void
updateSelected()
Rereads the currently model from the database, discarding any local, unsaved changes.-
Methods inherited from class de.xima.fc.gui.common.utils.msg.MessageUtils
addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsgFromString, addErrorMsgFromString, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addInfoMsg, addInfoMsg, addInfoMsg, addInfoMsg, addInfoMsgFromString, addInfoMsgFromString, addInfoMsgToComponent, addInfoMsgToComponent, addInfoMsgToComponent, addInfoMsgToComponent, addMsg, addMsg, addMsg, addMsg, addMsgs, addMsgToComponent, addMsgToComponent, addWarnMsg, addWarnMsg, addWarnMsg, addWarnMsg, addWarnMsgFromString, addWarnMsgFromString, addWarnMsgToComponent, addWarnMsgToComponent, addWarnMsgToComponent, addWarnMsgToComponent, cleanErrorMsg, getErrorMessage, getNewErrorMsg, getNewErrorMsg, getNewErrorMsg, getNewInfoMsg, getNewInfoMsg, getNewMsg, getNewWarnMsg, getNewWarnMsg
-
-
-
-
Field Detail
-
hasAddNewEntity
protected boolean hasAddNewEntity
-
entityClass
protected final Class<T extends ITransferableEntity> entityClass
-
qcm
protected final de.xima.cmn.criteria.QueryCriteriaManager qcm
-
all
protected List<T extends ITransferableEntity> all
-
filtered
protected List<T extends ITransferableEntity> filtered
-
marked
protected List<T extends ITransferableEntity> marked
-
selected
protected T extends ITransferableEntity selected
-
globalFilter
protected String globalFilter
-
-
Method Detail
-
getAll
public List<T> getAll()
- Specified by:
getAll
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
- A list of all models, not including a #
IEntityListModel.isNew()
, unsaved model.
-
getAllPlusNew
public List<T> getAllPlusNew()
- Specified by:
getAllPlusNew
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
- A list of all models, including the #
IEntityListModel.isNew()
, unsaved model, if it exists.
-
updateData
public void updateData()
- Specified by:
updateData
in interfaceIUpdatable
-
selectDefault
protected void selectDefault()
Called when no item is selected. Should select the default item by calling #setSelected(ITransferableEntity)
. Defaults to selecting the first item; or a new item if no items exists. Override for custom behavior.
-
fetchAll
protected List<T> fetchAll()
Fetches all available entities. By default, this simple reads all entities matching theQueryCriteriaManager
provided in the constructor. Override this for custom logic. If you choose to override this, you may providenull
for theQueryCriteriaManager
, if you do not call this super method and do not attempt to use it yourself.- Returns:
- List
All available entities. The order of the returned list is preserved.
-
addNew
public void addNew()
Description copied from interface:IEntityListModel
Sets the currently selected model to a new model. A new model is not yet persisted in the database and exists only in memory.- Specified by:
addNew
in interfaceIEntityListModel<T extends ITransferableEntity>
-
getNew
public T getNew()
-
create
public void create()
-
update
public void update()
-
save
public void save(boolean addSuccessMessage, boolean addErrorMessage)
-
save
public void save()
Description copied from interface:IEntityListModel
Saves the currently selected model to the database. If itIEntityListModel.isNew()
, creates a new entry in the database, otherwise updates the existing entry.- Specified by:
save
in interfaceIEntityListModel<T extends ITransferableEntity>
-
getSelected
public T getSelected()
- Specified by:
getSelected
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
- The currently selected model. A new model if none is selected.
-
getGlobalFilter
public String getGlobalFilter()
-
setGlobalFilter
public void setGlobalFilter(String globalFilter)
-
loadLazyData
public void loadLazyData()
Description copied from interface:IEntityListModel
Can be overriden to initialize lazily loaded fields on the entity. By default, does not load any lazy data.- Specified by:
loadLazyData
in interfaceIEntityListModel<T extends ITransferableEntity>
-
setSelected
public void setSelected(T selected)
Description copied from interface:IEntityListModel
Sets the currently selected model to the given model. If the given model exists in the database but is not currently managed by an entity manager, rereads the model from the database. Thus theIEntityListModel.getSelected()
model may not refer to the same instance as the given model.- Specified by:
setSelected
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
selected
- The model to be selected.
-
setSelectedFromMarked
public void setSelectedFromMarked()
If there is exactly one entity marked, makes it the selected one- Specified by:
setSelectedFromMarked
in interfaceIEntityListModel<T extends ITransferableEntity>
-
getFiltered
public List<T> getFiltered()
- Specified by:
getFiltered
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
- A subset of
IEntityListModel.getAll()
, with some models excluded according to some filter criterion.
-
setFiltered
public void setFiltered(List<T> filtered)
Description copied from interface:IEntityListModel
Sets the list of filtered models. This should be subset ofIEntityListModel.getAll()
.- Specified by:
setFiltered
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
filtered
- List of filtered models to set.
-
getMarked
public List<T> getMarked()
- Specified by:
getMarked
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
List
of entities that have been marked (i.e. for further processing)
-
setMarked
public void setMarked(List<T> marked)
Description copied from interface:IEntityListModel
Sets the list of marked entities- Specified by:
setMarked
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
marked
-List
of entities to be marked
-
addMarked
public void addMarked(T entity)
Description copied from interface:IEntityListModel
Adds the given entity to theList
of marked entities- Specified by:
addMarked
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
entity
- to be added
-
removeMarked
public void removeMarked(T entity)
Description copied from interface:IEntityListModel
Removes the given entity from theList
of marked entities- Specified by:
removeMarked
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
entity
- to be removed
-
isNew
public boolean isNew()
- Specified by:
isNew
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
- Whether the currently selected model is new, ie. whether it is persisted in the database or exists only in memory.
-
updateSelected
public void updateSelected()
Description copied from interface:IEntityListModel
Rereads the currently model from the database, discarding any local, unsaved changes. Does nothing iff the currently selected modelIEntityListModel.isNew()
.- Specified by:
updateSelected
in interfaceIEntityListModel<T extends ITransferableEntity>
-
isEmptyList
public boolean isEmptyList()
- Specified by:
isEmptyList
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
true
iffIEntityListModel.getAll()
is empty.
-
hasEntity
public boolean hasEntity()
- Specified by:
hasEntity
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
true
iff not #IEntityListModel.isEmptyList()
or the currently selected modelIEntityListModel.isNew()
.
-
setHasAddNewEntity
public void setHasAddNewEntity(boolean isNewEntity)
-
getDao
public IGenericDao<T> getDao()
-
delete
public String delete()
Description copied from interface:IEntityListModel
Deletes the currently selected model from the database. If the currently selected modelIEntityListModel.isNew()
, does nothing.- Specified by:
delete
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
- A view ID of the page to show after the model was deleted.
-
delete
public String delete(String targetView)
Description copied from interface:IEntityListModel
Deletes the currently selected model from the database. If the currently selected modelIEntityListModel.isNew()
, does nothing.- Specified by:
delete
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
targetView
- TheEnum.name()
of a view whose view ID is returned after this operation completes successfully. Can also be a relative path, in which case that path is returned.- Returns:
- A view ID of the page to show after the model was deleted.
-
ec
public IEntityContext ec()
-
isDetached
protected boolean isDetached(de.xima.cmn.dao.interfaces.IEntity<Long> entity)
-
deleteEntity
public String deleteEntity(T entity)
Description copied from interface:IEntityListModel
Same asIEntityListModel.delete()
, but takes the model to be deleted as an argument instead of deleting the currently selected model.- Specified by:
deleteEntity
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
entity
- The model to be deleted.- Returns:
- A view ID of the page to show after the model was deleted.
-
deleteEntity
public String deleteEntity(String targetView, T entity)
Description copied from interface:IEntityListModel
Same asIEntityListModel.delete(String)
, but takes the model to be deleted as an argument instead of deleting the currently selected model.- Specified by:
deleteEntity
in interfaceIEntityListModel<T extends ITransferableEntity>
- Parameters:
targetView
- TheEnum.name()
of a view whose view ID is returned after this operation completes successfully. Can also be a relative path, in which case that path is returned.entity
- The model to be deleted.- Returns:
- A view ID of the page to show after the model was deleted.
-
isMarkedDeletable
public boolean isMarkedDeletable()
- Specified by:
isMarkedDeletable
in interfaceIEntityListModel<T extends ITransferableEntity>
- Returns:
true
iff every single marked entity is deletable.false
otherwise
-
deleteMarkedEntities
public void deleteMarkedEntities()
Description copied from interface:IEntityListModel
Deletes all marked entities- Specified by:
deleteMarkedEntities
in interfaceIEntityListModel<T extends ITransferableEntity>
-
onRowSelect
public void onRowSelect(org.primefaces.event.SelectEvent event)
- Specified by:
onRowSelect
in interfaceIEntityListModel<T extends ITransferableEntity>
-
onRowSelectCheckbox
public void onRowSelectCheckbox(org.primefaces.event.SelectEvent event)
- Specified by:
onRowSelectCheckbox
in interfaceIEntityListModel<T extends ITransferableEntity>
-
onRowUnselectCheckbox
public void onRowUnselectCheckbox(org.primefaces.event.UnselectEvent event)
- Specified by:
onRowUnselectCheckbox
in interfaceIEntityListModel<T extends ITransferableEntity>
-
onToggleSelect
public void onToggleSelect(org.primefaces.event.ToggleSelectEvent event)
- Specified by:
onToggleSelect
in interfaceIEntityListModel<T extends ITransferableEntity>
-
-