Class ItemListModel<T,ID>

All Implemented Interfaces:
IItemListModel<T>, IUpdatable, Serializable
Direct Known Subclasses:
EntityListModel, ItemListModelSelectByView

public abstract class ItemListModel<T,ID> extends AMessaging implements IItemListModel<T>
See Also:
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • all

      protected List<T> all
    • filtered

      protected List<T> filtered
    • globalFilter

      protected String globalFilter
    • hasAddNewEntity

      protected boolean hasAddNewEntity
    • marked

      protected List<T> marked
    • selected

      protected T selected
  • Constructor Details

    • ItemListModel

      protected ItemListModel()
  • Method Details

    • addMarked

      public void addMarked(T entity)
      Description copied from interface: IItemListModel
      Adds the given entity to the List of marked entities
      Specified by:
      addMarked in interface IItemListModel<T>
      Parameters:
      entity - to be added
    • addNew

      public void addNew()
      Description copied from interface: IItemListModel
      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 interface IItemListModel<T>
    • create

      public void create() throws Exception
      Throws:
      Exception
    • delete

      public String delete()
      Description copied from interface: IItemListModel
      Deletes the currently selected model from the database. If the currently selected model IItemListModel.isNew(), does nothing.
      Specified by:
      delete in interface IItemListModel<T>
      Returns:
      A view ID of the page to show after the model was deleted.
    • deleteEntity

      public String deleteEntity(T entity)
      Description copied from interface: IItemListModel
      Same as IItemListModel.delete(), but takes the model to be deleted as an argument instead of deleting the currently selected model.
      Specified by:
      deleteEntity in interface IItemListModel<T>
      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: IItemListModel
      Same as IItemListModel.deleteEntity(Object), but takes the model to be deleted as an argument instead of deleting the currently selected model.
      Specified by:
      deleteEntity in interface IItemListModel<T>
      Parameters:
      targetView - The 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.
    • deleteMarkedEntities

      public void deleteMarkedEntities()
      Description copied from interface: IItemListModel
      Deletes all marked entities
      Specified by:
      deleteMarkedEntities in interface IItemListModel<T>
    • getAll

      public List<T> getAll()
      Specified by:
      getAll in interface IItemListModel<T>
      Returns:
      A list of all models, not including a #IItemListModel.isNew(), unsaved model.
    • getAllPlusNew

      public List<T> getAllPlusNew()
      Specified by:
      getAllPlusNew in interface IItemListModel<T>
      Returns:
      A list of all models, including the #IItemListModel.isNew(), unsaved model, if it exists.
    • getFiltered

      public List<T> getFiltered()
      Specified by:
      getFiltered in interface IItemListModel<T>
      Returns:
      A subset of IItemListModel.getAll(), with some models excluded according to some filter criterion.
    • setFiltered

      public void setFiltered(List<T> filtered)
      Description copied from interface: IItemListModel
      Sets the list of filtered models. This should be subset of IItemListModel.getAll().
      Specified by:
      setFiltered in interface IItemListModel<T>
      Parameters:
      filtered - List of filtered models to set.
    • getGlobalFilter

      public String getGlobalFilter()
    • setGlobalFilter

      public void setGlobalFilter(String globalFilter)
    • getMarked

      public List<T> getMarked()
      Specified by:
      getMarked in interface IItemListModel<T>
      Returns:
      List of entities that have been marked (i.e. for further processing)
    • setMarked

      public void setMarked(List<T> marked)
      Description copied from interface: IItemListModel
      Sets the list of marked entities
      Specified by:
      setMarked in interface IItemListModel<T>
      Parameters:
      marked - List of entities to be marked
    • getSelected

      public T getSelected()
      Specified by:
      getSelected in interface IItemListModel<T>
      Returns:
      The currently selected model. A new model if none is selected.
    • setSelected

      public void setSelected(T selected)
      Description copied from interface: IItemListModel
      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 the IItemListModel.getSelected() model may not refer to the same instance as the given model.
      Specified by:
      setSelected in interface IItemListModel<T>
      Parameters:
      selected - The model to be selected.
    • hasEntity

      public boolean hasEntity()
      Specified by:
      hasEntity in interface IItemListModel<T>
      Returns:
      true iff not #IItemListModel.isEmptyList() or the currently selected model IItemListModel.isNew().
    • isEmptyList

      public boolean isEmptyList()
      Specified by:
      isEmptyList in interface IItemListModel<T>
      Returns:
      true iff IItemListModel.getAll() is empty.
    • isMarkedDeletable

      public boolean isMarkedDeletable()
      Specified by:
      isMarkedDeletable in interface IItemListModel<T>
      Returns:
      true iff every single marked entity is deletable. false otherwise
    • isNew

      public boolean isNew()
      Specified by:
      isNew in interface IItemListModel<T>
      Returns:
      Whether the currently selected model is new, ie. whether it is persisted in the database or exists only in memory.
    • loadLazyData

      public void loadLazyData()
      Description copied from interface: IItemListModel
      Can be overridden to initialize lazily loaded fields on the entity. By default, does not load any lazy data.
      Specified by:
      loadLazyData in interface IItemListModel<T>
    • onRowSelect

      public void onRowSelect(org.primefaces.event.SelectEvent<?> event)
      Specified by:
      onRowSelect in interface IItemListModel<T>
    • onRowSelectCheckbox

      public void onRowSelectCheckbox(org.primefaces.event.SelectEvent<?> event)
      Specified by:
      onRowSelectCheckbox in interface IItemListModel<T>
    • onRowUnselectCheckbox

      public void onRowUnselectCheckbox(org.primefaces.event.UnselectEvent<?> event)
      Specified by:
      onRowUnselectCheckbox in interface IItemListModel<T>
    • onToggleSelect

      public void onToggleSelect(org.primefaces.event.ToggleSelectEvent event)
      Specified by:
      onToggleSelect in interface IItemListModel<T>
    • removeMarked

      public void removeMarked(T entity)
      Description copied from interface: IItemListModel
      Removes the given entity from the List of marked entities
      Specified by:
      removeMarked in interface IItemListModel<T>
      Parameters:
      entity - to be removed
    • save

      public void save(boolean addSuccessMessage, boolean addErrorMessage)
    • save

      public void save()
      Description copied from interface: IItemListModel
      Saves the currently selected model to the database. If it IItemListModel.isNew(), creates a new entry in the database, otherwise updates the existing entry.
      Specified by:
      save in interface IItemListModel<T>
    • isHasAddNewEntity

      public boolean isHasAddNewEntity()
    • setHasAddNewEntity

      public void setHasAddNewEntity(boolean isNewEntity)
    • setSelectedFromMarked

      public void setSelectedFromMarked()
      If there is exactly one entity marked, makes it the selected one
      Specified by:
      setSelectedFromMarked in interface IItemListModel<T>
    • update

      public void update() throws Exception
      Throws:
      Exception
    • updateData

      public void updateData()
      Specified by:
      updateData in interface IUpdatable
    • updateSelected

      public void updateSelected()
      Description copied from interface: IItemListModel
      Rereads the currently model from the database, discarding any local, unsaved changes. Does nothing iff the currently selected model IItemListModel.isNew().
      Specified by:
      updateSelected in interface IItemListModel<T>
    • castTo

      protected T castTo(Object object)
    • crudCreate

      protected abstract T crudCreate(T item) throws Exception
      Throws:
      Exception
    • crudDelete

      protected abstract void crudDelete(T item) throws Exception
      Throws:
      Exception
    • crudRead

      protected abstract T crudRead(ID id) throws Exception
      Throws:
      Exception
    • crudUpdate

      protected abstract T crudUpdate(T item) throws Exception
      Throws:
      Exception
    • fetchAll

      protected abstract List<T> fetchAll() throws Exception
      Fetches all available entities. By default, this simple reads all entities matching the QueryCriteriaManager provided in the constructor. Override this for custom logic. If you choose to override this, you may provide null for the QueryCriteriaManager, if you do not call this super method and do not attempt to use it yourself.
      Returns:
      A list with all available entities. The order of the returned list is preserved.
      Throws:
      Exception
    • findName

      protected abstract String findName(T item)
    • getId

      protected abstract ID getId(T item)
    • getNew

      protected abstract T getNew()
    • isDetached

      protected abstract boolean isDetached(T item)
    • isPersisted

      protected abstract boolean isPersisted(T item)
    • performDelete

      protected boolean performDelete(T item)
    • selectDefault

      protected void selectDefault()
      Called when no item is selected. Should select the default item by calling #setSelected(Object). Defaults to selecting the first item; or a new item if no items exists. Override for custom behavior.
    • onSelectionChanged

      protected void onSelectionChanged(T selected)
      Called when the selection changes, e.g. when a new item is selected or the selection is cleared.
      Parameters:
      selected - The currently selected item, or null if no item is selected.