com.arsdigita.bebop
Class MapComponentSelectionModel

java.lang.Object
  extended bycom.arsdigita.bebop.MapComponentSelectionModel
All Implemented Interfaces:
ComponentSelectionModel, Lockable, SingleSelectionModel

public class MapComponentSelectionModel
extends Object
implements ComponentSelectionModel, Lockable

A simple implementation of a ComponentSelectionModel. Uses a map to bind keys to components.

This class also encapsulates a SingleSelectionModel, which is useful if the SingleSelectionModel comes from a List or similar class.

Version:
$Id: //core-platform/dev/src/com/arsdigita/bebop/MapComponentSelectionModel.java#7 $
Author:
David Lutterkort, Stanislav Freidin

Field Summary
static String versionId
           
 
Constructor Summary
MapComponentSelectionModel(Map components)
          Constructs a new MapSingleSelectionModel, using a DefaultSingleSelectionModel selection model and encapsulating the components map.
MapComponentSelectionModel(SingleSelectionModel selModel, Map components)
          Constructs a new MapSingleSelectionModel, using selModel as the inner selection model and encapsulating the components map.
 
Method Summary
 void add(Object key, Component c)
          Adds another key-component mapping to the model.
 void addChangeListener(ChangeListener l)
          Adds a change listener to the model.
 void clearSelection(PageState state)
          Clears the selection.
 Component getComponent(PageState state)
          Returns the component that should be used to output the currently selected element.
 Map getComponentsMap()
          Retrieves the internal Map of components.
 Object getSelectedKey(PageState state)
          Returns the key that identifies the selected element.
 SingleSelectionModel getSingleSelectionModel()
          Retrieves the internal SingleSelectionModel.
 ParameterModel getStateParameter()
          Returns the state parameter that will be used to keep track of the currently selected key.
 boolean isLocked()
          Return whether an object is locked and thus immutable, or can still be modified.
 boolean isSelected(PageState state)
          Returns true if there is a selected element.
 void lock()
          Lock an object.
 void removeChangeListener(ChangeListener l)
          Removes a change listener from the model.
 void setSelectedKey(PageState state, Object key)
          Sets the selected key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

MapComponentSelectionModel

public MapComponentSelectionModel(SingleSelectionModel selModel,
                                  Map components)
Constructs a new MapSingleSelectionModel, using selModel as the inner selection model and encapsulating the components map.

Parameters:
selModel - the single selection model to use to determine the currently selected key/component
components - the map of components that can be selected. The map is stored by reference. Therefore, changes to the map will affect the MapComponentSelectionModel instance.

MapComponentSelectionModel

public MapComponentSelectionModel(Map components)
Constructs a new MapSingleSelectionModel, using a DefaultSingleSelectionModel selection model and encapsulating the components map.

Parameters:
components - the map of components that can be selected. The map is stored by reference. Therefore, changes to the map will affect the MapComponentSelectionModel instance.
Method Detail

getSingleSelectionModel

public final SingleSelectionModel getSingleSelectionModel()
Retrieves the internal SingleSelectionModel.

Returns:
the internal SingleSelectionModel.

getComponentsMap

public final Map getComponentsMap()
Retrieves the internal Map of components. Deprecate ???

Returns:
the internal map of components.

getComponent

public Component getComponent(PageState state)
Returns the component that should be used to output the currently selected element.

Specified by:
getComponent in interface ComponentSelectionModel
Parameters:
state - the state of the current request
Returns:
the component used to output the selected element.

add

public void add(Object key,
                Component c)
Adds another key-component mapping to the model. Passthrough to the underlying Map.

Parameters:
key - the key for the mapping
c - the component for the mapping

isSelected

public boolean isSelected(PageState state)
Returns true if there is a selected element.

Specified by:
isSelected in interface SingleSelectionModel
Parameters:
state - the state of the current request
Returns:
true if there is a selected component false otherwise.

getSelectedKey

public Object getSelectedKey(PageState state)
Returns the key that identifies the selected element.

Specified by:
getSelectedKey in interface SingleSelectionModel
Parameters:
state - a PageState value
Returns:
a String value.

setSelectedKey

public void setSelectedKey(PageState state,
                           Object key)
Sets the selected key. If key is not in the collection of objects underlying this model, an IllegalArgumentException is thrown.

Specified by:
setSelectedKey in interface SingleSelectionModel
Parameters:
state - the state of the current request
key - the selected key
Throws:
IllegalArgumentException - if the supplied key cannot be selected in the context of the current request.

clearSelection

public void clearSelection(PageState state)
Clears the selection.

Specified by:
clearSelection in interface SingleSelectionModel
Parameters:
state - the state of the current request

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a change listener to the model. The listener's stateChanged is called whenever the selected key changes.

Specified by:
addChangeListener in interface SingleSelectionModel
Parameters:
l - a listener to notify when the selected key changes

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a change listener from the model.

Specified by:
removeChangeListener in interface SingleSelectionModel
Parameters:
l - the listener to remove

getStateParameter

public ParameterModel getStateParameter()
Returns the state parameter that will be used to keep track of the currently selected key. Typically, the implementing class will simply call:
return new StringParameter("foo");
This method may return null if a state parameter is not appropriate in the context of the implementing class.

Specified by:
getStateParameter in interface SingleSelectionModel
Returns:
the state parameter to use to keep track of the currently selected component.

lock

public final void lock()
Description copied from interface: Lockable
Lock an object. Locked objects are to be considered immutable. Any attempt to modify them, e.g., through a setXXX method should lead to an exception.

Most lockable Bebop classes throw an IllegalStateException if an attempt is made to modify a locked instance.

Specified by:
lock in interface Lockable

isLocked

public final boolean isLocked()
Description copied from interface: Lockable
Return whether an object is locked and thus immutable, or can still be modified.

Specified by:
isLocked in interface Lockable


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC