org.jminor.framework.client.model
Class DefaultEntityModel

java.lang.Object
  extended by org.jminor.framework.client.model.DefaultEntityModel
All Implemented Interfaces:
Refreshable, EntityDataProvider, EntityModel

public class DefaultEntityModel
extends Object
implements EntityModel

A default EntityModel implementation.

 String entityID = "some.entity";
 String clientTypeID = "JavadocDemo";
 User user = new User("scott", "tiger");

 EntityConnectionProvider connectionProvider = EntityConnectionProviders.createConnectionProvider(user, clientTypeID);

 EntityModel model = new DefaultEntityModel(entityID, connectionProvider);

 EntityPanel panel = new EntityPanel(model);
 


Field Summary
protected static org.slf4j.Logger LOG
           
 
Constructor Summary
DefaultEntityModel(EntityEditModel editModel)
          Instantiates a new DefaultEntityModel
DefaultEntityModel(EntityEditModel editModel, boolean includeTableModel)
          Instantiates a new DefaultEntityModel
DefaultEntityModel(EntityEditModel editModel, EntityTableModel tableModel)
          Instantiates a new DefaultEntityModel
DefaultEntityModel(EntityTableModel tableModel)
          Instantiates a new DefaultEntityModel
DefaultEntityModel(String entityID, EntityConnectionProvider connectionProvider)
          Instantiates a new EntityModel with default EntityEditModel and EntityTableModel implementations.
DefaultEntityModel(String entityID, EntityConnectionProvider connectionProvider, boolean includeTableModel)
          Instantiates a new DefaultEntityModel with default EntityEditModel and EntityTableModel implementations.
 
Method Summary
 void addAfterRefreshListener(ActionListener listener)
          
 void addBeforeRefreshListener(ActionListener listener)
          
 EntityModel addDetailModel(EntityModel detailModel)
          Adds the given detail model to this model
 void addDetailModels(EntityModel... detailModels)
          Adds the given detail models to this model.
 void addLinkedDetailModelsListener(ActionListener listener)
          
 void clear()
          Clears all data from this refreshable instance
 void clearDetailModels()
          Clears the detail models.
 boolean containsDetailModel(Class<? extends EntityModel> modelClass)
          
 boolean containsDetailModel(EntityModel detailModel)
          
 boolean containsDetailModel(String entityID)
          
 boolean containsTableModel()
          
 EntityConnectionProvider getConnectionProvider()
          
 EntityModel getDetailModel(Class<? extends EntityModel> modelClass)
          Returns the first detail model of the given type, this method does not automatically create an entity model if none is available
 EntityModel getDetailModel(String entityID)
          Returns a detail model of the given type, automatically creates a default entity model if none is available and auto creation is turned on
 Collection<? extends EntityModel> getDetailModels()
          
 EntityEditModel getEditModel()
          
 String getEntityID()
          
 Collection<EntityModel> getLinkedDetailModels()
          
 EntityModel getMasterModel()
          
 EntityTableModel getTableModel()
          
protected  void handleInitialization(String masterEntityID, List<Entity> selectedMasterEntities)
           
 void initialize(String masterEntityID, List<Entity> selectedMasterEntities)
          Initializes this EntityModel according to the given master entities, sets the appropriate property value and filters the EntityTableModel
 void refresh()
          Performs a refresh
 void refreshDetailModels()
          Refreshes the detail models.
 void removeAfterRefreshListener(ActionListener listener)
          
 void removeBeforeRefreshListener(ActionListener listener)
          
 void removeLinkedDetailModelsListener(ActionListener listener)
          
 void setLinkedDetailModels(EntityModel... detailModels)
          Sets the currently linked detail models.
 void setMasterModel(EntityModel entityModel)
          Sets the model serving as master model
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

protected static final org.slf4j.Logger LOG
Constructor Detail

DefaultEntityModel

public DefaultEntityModel(String entityID,
                          EntityConnectionProvider connectionProvider)
Instantiates a new EntityModel with default EntityEditModel and EntityTableModel implementations.

Parameters:
entityID - the ID of the Entity this EntityModel represents
connectionProvider - a EntityConnectionProvider

DefaultEntityModel

public DefaultEntityModel(String entityID,
                          EntityConnectionProvider connectionProvider,
                          boolean includeTableModel)
Instantiates a new DefaultEntityModel with default EntityEditModel and EntityTableModel implementations.

Parameters:
entityID - the ID of the Entity this DefaultEntityModel represents
connectionProvider - a EntityConnectionProvider
includeTableModel - true if this DefaultEntityModel should include a table model

DefaultEntityModel

public DefaultEntityModel(EntityEditModel editModel)
Instantiates a new DefaultEntityModel

Parameters:
editModel - the edit model

DefaultEntityModel

public DefaultEntityModel(EntityTableModel tableModel)
Instantiates a new DefaultEntityModel

Parameters:
tableModel - the table model

DefaultEntityModel

public DefaultEntityModel(EntityEditModel editModel,
                          boolean includeTableModel)
Instantiates a new DefaultEntityModel

Parameters:
editModel - the edit model
includeTableModel - if true then a default EntityTableModel is included

DefaultEntityModel

public DefaultEntityModel(EntityEditModel editModel,
                          EntityTableModel tableModel)
Instantiates a new DefaultEntityModel

Parameters:
editModel - the edit model
tableModel - the table model
Method Detail

toString

public final String toString()
Overrides:
toString in class Object
Returns:
a String representation of this EntityModel, returns the model class name by default

getEntityID

public final String getEntityID()

Specified by:
getEntityID in interface EntityDataProvider
Returns:
the ID of the entity this data provider is based on

getConnectionProvider

public final EntityConnectionProvider getConnectionProvider()

Specified by:
getConnectionProvider in interface EntityDataProvider
Returns:
the db provider this data provider uses

getMasterModel

public final EntityModel getMasterModel()

Specified by:
getMasterModel in interface EntityModel
Returns:
the master model, if any

setMasterModel

public final void setMasterModel(EntityModel entityModel)
Sets the model serving as master model

Specified by:
setMasterModel in interface EntityModel
Parameters:
entityModel - the master entity model

getEditModel

public final EntityEditModel getEditModel()

Specified by:
getEditModel in interface EntityModel
Returns:
the EntityEditModel instance used by this EntityModel

getTableModel

public final EntityTableModel getTableModel()

Specified by:
getTableModel in interface EntityModel
Returns:
the EntityTableModel, null if none is specified

containsTableModel

public final boolean containsTableModel()

Specified by:
containsTableModel in interface EntityModel
Returns:
true if this EntityModel contains a TableModel

addDetailModels

public final void addDetailModels(EntityModel... detailModels)
Adds the given detail models to this model.

Specified by:
addDetailModels in interface EntityModel
Parameters:
detailModels - the detail models to add

addDetailModel

public final EntityModel addDetailModel(EntityModel detailModel)
Adds the given detail model to this model

Specified by:
addDetailModel in interface EntityModel
Parameters:
detailModel - the detail model
Returns:
the detail model just added

containsDetailModel

public final boolean containsDetailModel(Class<? extends EntityModel> modelClass)

Specified by:
containsDetailModel in interface EntityModel
Parameters:
modelClass - the detail model class
Returns:
true if this model contains a detail model of the given class

containsDetailModel

public final boolean containsDetailModel(String entityID)

Specified by:
containsDetailModel in interface EntityModel
Parameters:
entityID - the entity ID
Returns:
true if this model contains a detail model for the given entity ID

containsDetailModel

public final boolean containsDetailModel(EntityModel detailModel)

Specified by:
containsDetailModel in interface EntityModel
Parameters:
detailModel - the detail model
Returns:
true if this model contains the given detail model

getDetailModels

public final Collection<? extends EntityModel> getDetailModels()

Specified by:
getDetailModels in interface EntityModel
Returns:
an unmodifiable collection containing the detail models this model contains

setLinkedDetailModels

public final void setLinkedDetailModels(EntityModel... detailModels)
Sets the currently linked detail models. Linked models are updated and filtered according to the entity/entities selected in this (the master) model

Specified by:
setLinkedDetailModels in interface EntityModel
Parameters:
detailModels - the detail models to link

getLinkedDetailModels

public final Collection<EntityModel> getLinkedDetailModels()

Specified by:
getLinkedDetailModels in interface EntityModel
Returns:
an unmodifiable collection containing the detail models that are currently linked to this model

getDetailModel

public final EntityModel getDetailModel(Class<? extends EntityModel> modelClass)
Returns the first detail model of the given type, this method does not automatically create an entity model if none is available

Specified by:
getDetailModel in interface EntityModel
Parameters:
modelClass - the type of the required EntityModel
Returns:
the detail model of type entityModelClass, null if none is found

getDetailModel

public final EntityModel getDetailModel(String entityID)
Returns a detail model of the given type, automatically creates a default entity model if none is available and auto creation is turned on

Specified by:
getDetailModel in interface EntityModel
Parameters:
entityID - the entity ID of the required EntityModel
Returns:
the detail model of type entityModelClass
See Also:
Configuration.AUTO_CREATE_ENTITY_MODELS

refresh

public final void refresh()
Performs a refresh

Specified by:
refresh in interface Refreshable

refreshDetailModels

public final void refreshDetailModels()
Refreshes the detail models.

Specified by:
refreshDetailModels in interface EntityModel

clear

public final void clear()
Clears all data from this refreshable instance

Specified by:
clear in interface Refreshable

clearDetailModels

public final void clearDetailModels()
Clears the detail models.

Specified by:
clearDetailModels in interface EntityModel

initialize

public void initialize(String masterEntityID,
                       List<Entity> selectedMasterEntities)
Initializes this EntityModel according to the given master entities, sets the appropriate property value and filters the EntityTableModel

Specified by:
initialize in interface EntityModel
Parameters:
masterEntityID - the ID of the master entity
selectedMasterEntities - the master entities

addLinkedDetailModelsListener

public final void addLinkedDetailModelsListener(ActionListener listener)

Specified by:
addLinkedDetailModelsListener in interface EntityModel
Parameters:
listener - a listener to be notified each time the linked detail models change

removeLinkedDetailModelsListener

public final void removeLinkedDetailModelsListener(ActionListener listener)

Specified by:
removeLinkedDetailModelsListener in interface EntityModel
Parameters:
listener - the listener to remove

addBeforeRefreshListener

public final void addBeforeRefreshListener(ActionListener listener)

Specified by:
addBeforeRefreshListener in interface EntityModel
Parameters:
listener - a listener to be notified before a refresh is performed

removeBeforeRefreshListener

public final void removeBeforeRefreshListener(ActionListener listener)

Specified by:
removeBeforeRefreshListener in interface EntityModel
Parameters:
listener - the listener to remove

addAfterRefreshListener

public final void addAfterRefreshListener(ActionListener listener)

Specified by:
addAfterRefreshListener in interface EntityModel
Parameters:
listener - a listener to be notified each time a refresh has been performed

removeAfterRefreshListener

public final void removeAfterRefreshListener(ActionListener listener)

Specified by:
removeAfterRefreshListener in interface EntityModel
Parameters:
listener - the listener to remove

handleInitialization

protected void handleInitialization(String masterEntityID,
                                    List<Entity> selectedMasterEntities)
Parameters:
masterEntityID - the entity ID of the master model doing the initialization
selectedMasterEntities - the entities selected in the master model