org.jminor.framework.client.model
Interface EntityEditModel

All Superinterfaces:
EntityDataProvider, Refreshable, ValueChangeMapEditModel<String,Object>
All Known Implementing Classes:
DefaultEntityEditModel

public interface EntityEditModel
extends ValueChangeMapEditModel<String,Object>, EntityDataProvider

Specifies a class for editing entity instances.


Method Summary
 void addAfterDeleteListener(ActionListener listener)
           
 void addAfterInsertListener(ActionListener listener)
           
 void addAfterRefreshListener(ActionListener listener)
           
 void addAfterUpdateListener(ActionListener listener)
           
 void addBeforeDeleteListener(ActionListener listener)
           
 void addBeforeInsertListener(ActionListener listener)
           
 void addBeforeRefreshListener(ActionListener listener)
           
 void addBeforeUpdateListener(ActionListener listener)
           
 void addEntitiesChangedListener(ActionListener listener)
           
 void clearComboBoxModels()
          Clears the data from all combo box models
 boolean containsComboBoxModel(String propertyID)
          Returns true if this edit model contains a ComboBoxModel for the given property
 EntityComboBoxModel createEntityComboBoxModel(Property.ForeignKeyProperty foreignKeyProperty)
          Creates a default EntityComboBoxModel for the given property, override to provide specific EntityComboBoxModels (filtered for example) for properties.
 EntityLookupModel createEntityLookupModel(String entityID, List<Property.ColumnProperty> lookupProperties, Criteria additionalSearchCriteria)
          Creates a EntityLookupModel for the given entityID
 FilteredComboBoxModel createPropertyComboBoxModel(Property.ColumnProperty property, EventObserver refreshEvent, String nullValueString)
          Creates a combo box model containing the current values of the given property
 List<Entity> delete()
          Deletes the active entity
 List<Entity> delete(List<Entity> entities)
          Deletes the given entities, returns silently on recieving an empty list
 StateObserver getAllowDeleteState()
           
 StateObserver getAllowInsertState()
           
 StateObserver getAllowUpdateState()
           
 Object getDefaultValue(Property property)
          Returns the default value for the given property, used when initializing a new default entity for this edit model.
 EntityComboBoxModel getEntityComboBoxModel(Property.ForeignKeyProperty foreignKeyProperty)
           
 EntityComboBoxModel getEntityComboBoxModel(String propertyID)
           
 Entity getEntityCopy()
           
 Entity getEntityCopy(boolean includePrimaryKeyValues)
           
 StateObserver getEntityNullState()
           
 Entity getForeignKeyValue(String foreignKeyPropertyID)
          Returns the value associated with the given propertyID assuming it is an Entity instance
 FilteredComboBoxModel getPropertyComboBoxModel(Property.ColumnProperty property)
           
 ValueCollectionProvider getValueProvider(Property property)
          Initializes a value provider for the given property, used for adding lookup functionality to input fields for example.
 EntityComboBoxModel initializeEntityComboBoxModel(Property.ForeignKeyProperty foreignKeyProperty)
           
 EntityComboBoxModel initializeEntityComboBoxModel(String propertyID)
           
 FilteredComboBoxModel initializePropertyComboBoxModel(Property.ColumnProperty property, EventObserver refreshEvent, String nullValueString)
           
 List<Entity.Key> insert()
          Performs a insert on the active entity
 List<Entity.Key> insert(List<Entity> entities)
          Performs an insert on the given entities, returns silently on recieving an empty list
 boolean isDeleteAllowed()
           
 boolean isEntityNew()
           
 boolean isInsertAllowed()
           
 boolean isReadOnly()
           
 boolean isUpdateAllowed()
           
 boolean persistValueOnClear(Property property)
          Returns true if the last available value for this property should be used when initializing a default entity.
 void refreshComboBoxModels()
          Refreshes the Refreshable ComboBoxModels associated with this EntityEditModel
 void removeAfterDeleteListener(ActionListener listener)
           
 void removeAfterInsertListener(ActionListener listener)
           
 void removeAfterRefreshListener(ActionListener listener)
           
 void removeAfterUpdateListener(ActionListener listener)
           
 void removeBeforeDeleteListener(ActionListener listener)
           
 void removeBeforeInsertListener(ActionListener listener)
           
 void removeBeforeRefreshListener(ActionListener listener)
           
 void removeBeforeUpdateListener(ActionListener listener)
           
 void removeEntitiesChangedListener(ActionListener listener)
           
 void replaceForeignKeyValues(String foreignKeyEntityID, Collection<Entity> newForeignKeyValues)
          For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity from foreignKeyValues, useful when property values have been changed in the referenced entity that must be reflected in the edit model.
 EntityEditModel setDeleteAllowed(boolean value)
           
 void setEntity(Entity entity)
          Sets the Entity instance to edit
 EntityEditModel setInsertAllowed(boolean value)
           
 EntityEditModel setPersistValueOnClear(String propertyID, boolean persistValueOnClear)
           
 EntityEditModel setReadOnly(boolean readOnly)
           
 EntityEditModel setUpdateAllowed(boolean value)
           
 List<Entity> update()
          Performs a update on the active entity
 List<Entity> update(List<Entity> entities)
          Updates the given Entities.
 
Methods inherited from interface org.jminor.common.model.valuemap.ValueChangeMapEditModel
addValueListener, addValueMapSetListener, addValueSetListener, getDefaultValueMap, getModifiedState, getValidator, getValidState, getValue, getValueChangeObserver, isModified, isNullable, isValid, isValid, isValueNull, removeValueListener, removeValueMapSetListener, removeValueSetListener, setValue, setValueMap, validate
 
Methods inherited from interface org.jminor.common.model.Refreshable
clear, refresh
 
Methods inherited from interface org.jminor.framework.client.model.EntityDataProvider
getConnectionProvider, getEntityID
 

Method Detail

setEntity

void setEntity(Entity entity)
Sets the Entity instance to edit

Parameters:
entity - the entity

getEntityCopy

Entity getEntityCopy()
Returns:
a deep copy of the active entity
See Also:
ValueChangeMap.getCopy()

getEntityCopy

Entity getEntityCopy(boolean includePrimaryKeyValues)
Parameters:
includePrimaryKeyValues - if false then the primary key values are excluded
Returns:
a deep copy of the active entity
See Also:
ValueChangeMap.getCopy()

isEntityNew

boolean isEntityNew()
Returns:
true if the active entity is new, that is, has a primary key with null value or a original null value
See Also:
Entity.isPrimaryKeyNull()

getForeignKeyValue

Entity getForeignKeyValue(String foreignKeyPropertyID)
Returns the value associated with the given propertyID assuming it is an Entity instance

Parameters:
foreignKeyPropertyID - the ID of the property
Returns:
the value assuming it is an Entity
Throws:
ClassCastException - in case the value was not an Entity

replaceForeignKeyValues

void replaceForeignKeyValues(String foreignKeyEntityID,
                             Collection<Entity> newForeignKeyValues)
For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity from foreignKeyValues, useful when property values have been changed in the referenced entity that must be reflected in the edit model.

Parameters:
foreignKeyEntityID - the entity ID of the foreign key values
newForeignKeyValues - the new foreign key entities

getValueProvider

ValueCollectionProvider getValueProvider(Property property)
Initializes a value provider for the given property, used for adding lookup functionality to input fields for example.

Parameters:
property - the property
Returns:
a value provider for the given property

isReadOnly

boolean isReadOnly()
Returns:
true if this model is read only, by default this returns the isReadOnly value of the underlying entity

setReadOnly

EntityEditModel setReadOnly(boolean readOnly)
Parameters:
readOnly - the read only status
Returns:
this edit model instance

setPersistValueOnClear

EntityEditModel setPersistValueOnClear(String propertyID,
                                       boolean persistValueOnClear)
Parameters:
propertyID - the property ID
persistValueOnClear - true if this model should persist the value of the given property on clear
Returns:
this edit model instance
See Also:
Configuration.PERSIST_FOREIGN_KEY_VALUES

isInsertAllowed

boolean isInsertAllowed()
Returns:
true if this model should allow records to be inserted

setInsertAllowed

EntityEditModel setInsertAllowed(boolean value)
Parameters:
value - true if this model should allow inserts
Returns:
this edit model instance

isUpdateAllowed

boolean isUpdateAllowed()
Returns:
true if this model should allow records to be updated

setUpdateAllowed

EntityEditModel setUpdateAllowed(boolean value)
Parameters:
value - true if this model should allow records to be updated
Returns:
this edit model instance

isDeleteAllowed

boolean isDeleteAllowed()
Returns:
true if this model should allow records to be deleted

setDeleteAllowed

EntityEditModel setDeleteAllowed(boolean value)
Parameters:
value - true if this model should allow records to be deleted
Returns:
this edit model instance

createEntityComboBoxModel

EntityComboBoxModel createEntityComboBoxModel(Property.ForeignKeyProperty foreignKeyProperty)
Creates a default EntityComboBoxModel for the given property, override to provide specific EntityComboBoxModels (filtered for example) for properties. This method is called when creating a EntityComboBoxModel for entity properties, both for the edit fields used when editing a single record and the edit field used when updating multiple records. This default implementation returns a sorted EntityComboBoxModel with the default nullValueItem if the underlying property is nullable

Parameters:
foreignKeyProperty - the foreign key property for which to create a EntityComboBoxModel
Returns:
a EntityComboBoxModel for the given property
See Also:
Configuration.DEFAULT_COMBO_BOX_NULL_VALUE_ITEM, Property.isNullable()

createEntityLookupModel

EntityLookupModel createEntityLookupModel(String entityID,
                                          List<Property.ColumnProperty> lookupProperties,
                                          Criteria additionalSearchCriteria)
Creates a EntityLookupModel for the given entityID

Parameters:
entityID - the ID of the entity
lookupProperties - the properties involved in the lookup
additionalSearchCriteria - an additional search criteria applied when performing the lookup
Returns:
a EntityLookupModel

initializePropertyComboBoxModel

FilteredComboBoxModel initializePropertyComboBoxModel(Property.ColumnProperty property,
                                                      EventObserver refreshEvent,
                                                      String nullValueString)
Parameters:
property - the property for which to get the ComboBoxModel
refreshEvent - the combo box model is refreshed when this event fires, if none is specified addEntitiesChangedListener() is used.
nullValueString - the value to use for representing the null item at the top of the list, if this value is null then no such item is included
Returns:
a PropertyComboBoxModel representing property, if no combo box model has been initialized for the given property, a new one is created and associated with the property, to be returned the next time this method is called

getPropertyComboBoxModel

FilteredComboBoxModel getPropertyComboBoxModel(Property.ColumnProperty property)
Parameters:
property - the property for which to get the ComboBoxModel
Returns:
a PropertyComboBoxModel representing property
Throws:
RuntimeException - if no combo box has been initialized for the given property

containsComboBoxModel

boolean containsComboBoxModel(String propertyID)
Returns true if this edit model contains a ComboBoxModel for the given property

Parameters:
propertyID - the ID of the property
Returns:
true if a ComboBoxModel has been initialized for the given property

getEntityComboBoxModel

EntityComboBoxModel getEntityComboBoxModel(String propertyID)
Parameters:
propertyID - the ID of the property for which to retrieve the EntityComboBoxModel
Returns:
the EntityComboBoxModel for the property identified by propertyID, if no combo box model is associated with the property a new one is initialized, and associated with the given property
Throws:
RuntimeException - if no combo box has been initialized for the given property

getEntityComboBoxModel

EntityComboBoxModel getEntityComboBoxModel(Property.ForeignKeyProperty foreignKeyProperty)
Parameters:
foreignKeyProperty - the foreign key property for which to retrieve the EntityComboBoxModel
Returns:
the EntityComboBoxModel associated with the property
Throws:
RuntimeException - if no combo box has been initialized for the given property

initializeEntityComboBoxModel

EntityComboBoxModel initializeEntityComboBoxModel(String propertyID)
Parameters:
propertyID - the ID of the foreign key property for which to retrieve the EntityComboBoxModel
Returns:
the EntityComboBoxModel for the property, if no combo box model is associated with the property a new one is initialized, and associated with the given property

initializeEntityComboBoxModel

EntityComboBoxModel initializeEntityComboBoxModel(Property.ForeignKeyProperty foreignKeyProperty)
Parameters:
foreignKeyProperty - the foreign key property for which to retrieve the EntityComboBoxModel
Returns:
the EntityComboBoxModel for the property, if no combo box model is associated with the property a new one is initialized, and associated with the given property

createPropertyComboBoxModel

FilteredComboBoxModel createPropertyComboBoxModel(Property.ColumnProperty property,
                                                  EventObserver refreshEvent,
                                                  String nullValueString)
Creates a combo box model containing the current values of the given property

Parameters:
property - the property
refreshEvent - the combo box model is refreshed each time this event is fired
nullValueString - the string to use as a null value caption
Returns:
a combo box model based on the given property

refreshComboBoxModels

void refreshComboBoxModels()
Refreshes the Refreshable ComboBoxModels associated with this EntityEditModel

See Also:
Refreshable

clearComboBoxModels

void clearComboBoxModels()
Clears the data from all combo box models


getDefaultValue

Object getDefaultValue(Property property)
Returns the default value for the given property, used when initializing a new default entity for this edit model. This does not apply to denormalized properties (Property.DenormalizedProperty) nor properties that are wrapped in foreign key properties (Property.ForeignKeyProperty) If the default value of a property should be the last value used persistValueOnClear should be overridden so that it returns true for that property.

Parameters:
property - the property
Returns:
the default value for the property
See Also:
Property.setDefaultValue(Object), persistValueOnClear(org.jminor.framework.domain.Property)

persistValueOnClear

boolean persistValueOnClear(Property property)
Returns true if the last available value for this property should be used when initializing a default entity. Override for selective reset of field values when the model is cleared. For Property.ForeignKeyProperty values this method by default returns the value of the property Configuration.PERSIST_FOREIGN_KEY_VALUES.

Parameters:
property - the property
Returns:
true if the given field value should be reset when the model is cleared
See Also:
Configuration.PERSIST_FOREIGN_KEY_VALUES

insert

List<Entity.Key> insert()
                        throws CancelException,
                               DatabaseException,
                               ValidationException
Performs a insert on the active entity

Returns:
the primary keys of the inserted entities
Throws:
DatabaseException - in case of a database exception
CancelException - in case the user cancels the operation
ValidationException - in case validation fails
See Also:
Entity.Validator.validate(java.util.Collection, int)

insert

List<Entity.Key> insert(List<Entity> entities)
                        throws CancelException,
                               DatabaseException,
                               ValidationException
Performs an insert on the given entities, returns silently on recieving an empty list

Parameters:
entities - the entities to insert
Returns:
the primary keys of the inserted entities
Throws:
DatabaseException - in case of a database exception
CancelException - in case the user cancels the operation
ValidationException - in case validation fails
See Also:
addBeforeInsertListener(java.awt.event.ActionListener), addAfterInsertListener(java.awt.event.ActionListener), Entity.Validator.validate(java.util.Collection, int)

update

List<Entity> update()
                    throws CancelException,
                           DatabaseException,
                           ValidationException
Performs a update on the active entity

Returns:
the updated entities
Throws:
DatabaseException - in case of a database exception
CancelException - in case the user cancels the operation
RecordModifiedException - in case an entity was modified by another user
ValidationException - in case validation fails
See Also:
Entity.Validator.validate(java.util.Collection, int)

update

List<Entity> update(List<Entity> entities)
                    throws DatabaseException,
                           CancelException,
                           ValidationException
Updates the given Entities. If the entities are unmodified or the list is empty this method returns silently.

Parameters:
entities - the Entities to update
Returns:
the updated entities
Throws:
DatabaseException - in case of a database exception
CancelException - in case the user cancels the operation
RecordModifiedException - in case an entity was modified by another user
ValidationException - in case validation fails
See Also:
addBeforeUpdateListener(java.awt.event.ActionListener), addAfterUpdateListener(java.awt.event.ActionListener), Entity.Validator.validate(java.util.Collection, int)

delete

List<Entity> delete()
                    throws DatabaseException,
                           CancelException
Deletes the active entity

Returns:
the deleted entities
Throws:
DatabaseException - in case of a database exception
CancelException - in case the user cancels the operation
See Also:
addBeforeDeleteListener(java.awt.event.ActionListener), addAfterDeleteListener(java.awt.event.ActionListener)

delete

List<Entity> delete(List<Entity> entities)
                    throws DatabaseException,
                           CancelException
Deletes the given entities, returns silently on recieving an empty list

Parameters:
entities - the entities to delete
Returns:
the deleted entities
Throws:
DatabaseException - in case of a database exception
CancelException - in case the user cancels the operation
See Also:
addBeforeDeleteListener(java.awt.event.ActionListener), addAfterDeleteListener(java.awt.event.ActionListener)

getAllowDeleteState

StateObserver getAllowDeleteState()
Returns:
the state used to determine if deleting should be enabled
See Also:
isDeleteAllowed(), setDeleteAllowed(boolean)

getEntityNullState

StateObserver getEntityNullState()
Returns:
a State indicating whether or not the active entity is null

getAllowUpdateState

StateObserver getAllowUpdateState()
Returns:
the state used to determine if updating should be enabled
See Also:
isUpdateAllowed(), setUpdateAllowed(boolean)

getAllowInsertState

StateObserver getAllowInsertState()
Returns:
the state used to determine if inserting should be enabled
See Also:
isInsertAllowed(), setInsertAllowed(boolean)

addBeforeInsertListener

void addBeforeInsertListener(ActionListener listener)
Parameters:
listener - a listener to be notified before an insert is performed

removeBeforeInsertListener

void removeBeforeInsertListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addAfterInsertListener

void addAfterInsertListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time a insert has been performed

removeAfterInsertListener

void removeAfterInsertListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addBeforeUpdateListener

void addBeforeUpdateListener(ActionListener listener)
Parameters:
listener - a listener to be notified before an update is performed

removeBeforeUpdateListener

void removeBeforeUpdateListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addAfterUpdateListener

void addAfterUpdateListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time an update has been performed

removeAfterUpdateListener

void removeAfterUpdateListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addBeforeDeleteListener

void addBeforeDeleteListener(ActionListener listener)
Parameters:
listener - a listener to be notified before a delete is performed

removeBeforeDeleteListener

void removeBeforeDeleteListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addAfterDeleteListener

void addAfterDeleteListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time a delete has been performed

removeAfterDeleteListener

void removeAfterDeleteListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addBeforeRefreshListener

void addBeforeRefreshListener(ActionListener listener)
Parameters:
listener - a listener to be notified before a refresh is performed

removeBeforeRefreshListener

void removeBeforeRefreshListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addAfterRefreshListener

void addAfterRefreshListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time a refresh has been performed

removeAfterRefreshListener

void removeAfterRefreshListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time

addEntitiesChangedListener

void addEntitiesChangedListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time a entity is modified via this model, updated, inserted or deleted

removeEntitiesChangedListener

void removeEntitiesChangedListener(ActionListener listener)
Parameters:
listener - a listener to be notified each time