org.jminor.framework.client.model
Class DefaultEntityComboBoxModel

java.lang.Object
  extended by org.jminor.common.model.combobox.DefaultFilteredComboBoxModel<Entity>
      extended by org.jminor.framework.client.model.DefaultEntityComboBoxModel
All Implemented Interfaces:
ComboBoxModel, ListModel, FilteredComboBoxModel<Entity>, FilteredModel<Entity>, Refreshable, EntityComboBoxModel, EntityDataProvider

public class DefaultEntityComboBoxModel
extends DefaultFilteredComboBoxModel<Entity>
implements EntityComboBoxModel

A ComboBoxModel based on an Entity, showing by default all the entities in the underlying table.


Constructor Summary
DefaultEntityComboBoxModel(String entityID, EntityConnectionProvider connectionProvider)
           
 
Method Summary
 void addRefreshListener(ActionListener listener)
          
 EntityComboBoxModel createForeignKeyFilterComboBoxModel(String foreignKeyPropertyID)
          Returns a combo box model for selecting a foreign key value for filtering this model
 void forceRefresh()
          Forces a refresh of this model, disregarding the staticData directive
 EntityConnectionProvider getConnectionProvider()
          
 Entity getEntity(Entity.Key primaryKey)
          
 String getEntityID()
          
 Collection<Entity> getForeignKeyFilterEntities(String foreignKeyPropertyID)
          
 Entity getSelectedEntity()
          
protected  List<Entity> initializeContents()
          
 boolean isStaticData()
          
static void linkForeignKeyComboBoxModel(String foreignKeyPropertyID, EntityComboBoxModel model, EntityComboBoxModel foreignKeyModel)
           
protected  List<Entity> performQuery(EntitySelectCriteria selectCriteria)
          Retrieves the entities to present in this EntityComboBoxModel
 void removeRefreshListener(ActionListener listener)
          
 void setEntitySelectCriteria(EntitySelectCriteria entitySelectCriteria)
          Sets the criteria to use when querying data
 void setForeignKeyFilterEntities(String foreignKeyPropertyID, Collection<Entity> entities)
          Filters this combo box model so that only entities referencing the given foreign key entities via the given foreign key property are shown.
 void setSelectedEntityByPrimaryKey(Entity.Key primaryKey)
          Selects the entity with the given primary key, if the entity is not available in the model this method returns silently without changing the selection
 EntityComboBoxModel setStaticData(boolean staticData)
          Specifies whether or not this model's data should be considered static, that is, only fetched once.
 String toString()
          
protected  Object translateSelectionItem(Object item)
          
protected  boolean vetoSelectionChange(Object item)
          
 
Methods inherited from class org.jminor.common.model.combobox.DefaultFilteredComboBoxModel
addFilteringListener, addItem, addListDataListener, addSelectionListener, clear, contains, filterContents, fireContentsChanged, getAllItems, getElementAt, getFilterCriteria, getFilteredItemCount, getFilteredItems, getNullValueString, getSelectedItem, getSize, getVisibleItemCount, getVisibleItems, isCleared, isFiltered, isNullValueSelected, isVisible, refresh, removeFilteringListener, removeItem, removeListDataListener, removeSelectionListener, setContents, setFilterCriteria, setNullValueString, setSelectedItem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jminor.common.model.combobox.FilteredComboBoxModel
addItem, addSelectionListener, getNullValueString, isCleared, isNullValueSelected, removeItem, removeSelectionListener, setContents, setNullValueString
 
Methods inherited from interface org.jminor.common.model.FilteredModel
addFilteringListener, contains, filterContents, getAllItems, getFilterCriteria, getFilteredItemCount, getFilteredItems, getVisibleItemCount, getVisibleItems, isFiltered, isVisible, removeFilteringListener, setFilterCriteria
 
Methods inherited from interface javax.swing.ComboBoxModel
getSelectedItem, setSelectedItem
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, getElementAt, getSize, removeListDataListener
 
Methods inherited from interface org.jminor.common.model.Refreshable
clear, refresh
 

Constructor Detail

DefaultEntityComboBoxModel

public DefaultEntityComboBoxModel(String entityID,
                                  EntityConnectionProvider connectionProvider)
Parameters:
entityID - the ID of the entity this combo box model should represent
connectionProvider - a EntityConnectionProvider instance
Method Detail

toString

public final String toString()

Overrides:
toString in class Object

getConnectionProvider

public final EntityConnectionProvider getConnectionProvider()

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

getEntityID

public final String getEntityID()

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

forceRefresh

public final void forceRefresh()
Forces a refresh of this model, disregarding the staticData directive

Specified by:
forceRefresh in interface EntityComboBoxModel

isStaticData

public final boolean isStaticData()

Specified by:
isStaticData in interface EntityComboBoxModel
Returns:
true if the data for this model should only be fetched once
See Also:
EntityComboBoxModel.forceRefresh()

setStaticData

public final EntityComboBoxModel setStaticData(boolean staticData)
Specifies whether or not this model's data should be considered static, that is, only fetched once.

Specified by:
setStaticData in interface EntityComboBoxModel
Parameters:
staticData - the value
Returns:
this EntityComboBoxModel instance

getEntity

public final Entity getEntity(Entity.Key primaryKey)

Specified by:
getEntity in interface EntityComboBoxModel
Parameters:
primaryKey - the primary key of the entity to fetch from this model
Returns:
the entity with the given key if it is contained in the model, null otherwise

setSelectedEntityByPrimaryKey

public final void setSelectedEntityByPrimaryKey(Entity.Key primaryKey)
Selects the entity with the given primary key, if the entity is not available in the model this method returns silently without changing the selection

Specified by:
setSelectedEntityByPrimaryKey in interface EntityComboBoxModel
Parameters:
primaryKey - the primary key of the entity to select

getSelectedEntity

public final Entity getSelectedEntity()

Specified by:
getSelectedEntity in interface EntityComboBoxModel
Returns:
the selected entity or null if none is selected

setEntitySelectCriteria

public final void setEntitySelectCriteria(EntitySelectCriteria entitySelectCriteria)
Sets the criteria to use when querying data

Specified by:
setEntitySelectCriteria in interface EntityComboBoxModel
Parameters:
entitySelectCriteria - the criteria

setForeignKeyFilterEntities

public final void setForeignKeyFilterEntities(String foreignKeyPropertyID,
                                              Collection<Entity> entities)
Filters this combo box model so that only entities referencing the given foreign key entities via the given foreign key property are shown.

Specified by:
setForeignKeyFilterEntities in interface EntityComboBoxModel
Parameters:
foreignKeyPropertyID - the property ID
entities - the entities

getForeignKeyFilterEntities

public final Collection<Entity> getForeignKeyFilterEntities(String foreignKeyPropertyID)

Specified by:
getForeignKeyFilterEntities in interface EntityComboBoxModel
Parameters:
foreignKeyPropertyID - the ID of the foreign key property
Returns:
the entity values currently used to filter the contents of this model

createForeignKeyFilterComboBoxModel

public final EntityComboBoxModel createForeignKeyFilterComboBoxModel(String foreignKeyPropertyID)
Returns a combo box model for selecting a foreign key value for filtering this model

Specified by:
createForeignKeyFilterComboBoxModel in interface EntityComboBoxModel
Parameters:
foreignKeyPropertyID - the ID of the property with which values to create the combo box model
Returns:
a combo box model for selecting a filtering value for this combo box model

addRefreshListener

public final void addRefreshListener(ActionListener listener)

Specified by:
addRefreshListener in interface EntityComboBoxModel
Parameters:
listener - a listener to be notified each time this model is refreshed

removeRefreshListener

public final void removeRefreshListener(ActionListener listener)

Specified by:
removeRefreshListener in interface EntityComboBoxModel
Parameters:
listener - the listener to remove

linkForeignKeyComboBoxModel

public static void linkForeignKeyComboBoxModel(String foreignKeyPropertyID,
                                               EntityComboBoxModel model,
                                               EntityComboBoxModel foreignKeyModel)

translateSelectionItem

protected Object translateSelectionItem(Object item)

Overrides:
translateSelectionItem in class DefaultFilteredComboBoxModel<Entity>

vetoSelectionChange

protected final boolean vetoSelectionChange(Object item)

Overrides:
vetoSelectionChange in class DefaultFilteredComboBoxModel<Entity>

initializeContents

protected final List<Entity> initializeContents()

Overrides:
initializeContents in class DefaultFilteredComboBoxModel<Entity>
Returns:
a List containing the items to be shown in this combo box model, by default it simply returns a list containing the items currently contained in the model, both filtered and visible, excluding the null value.

performQuery

protected List<Entity> performQuery(EntitySelectCriteria selectCriteria)
Retrieves the entities to present in this EntityComboBoxModel

Parameters:
selectCriteria - the criteria to base the query on
Returns:
the entities to present in this EntityComboBoxModel