org.argouml.uml.ui
Class UMLComboBoxModel2

java.lang.Object
  extended byjavax.swing.AbstractListModel
      extended byorg.argouml.uml.ui.UMLComboBoxModel2
All Implemented Interfaces:
ComboBoxModel, EventListener, ListModel, PropertyChangeListener, Serializable, TargetListener
Direct Known Subclasses:
UMLAssociationRoleBaseComboBoxModel, UMLGeneralizationPowertypeComboBoxModel, UMLMessageActivatorComboBoxModel, UMLMetaClassComboBoxModel, UMLModelElementNamespaceComboBoxModel, UMLMultiplicityComboBoxModel, UMLObjectFlowStateClassifierComboBoxModel, UMLReceptionSignalComboBoxModel, UMLStateMachineContextComboBoxModel, UMLStructuralFeatureTypeComboBoxModel, UMLStubStateComboBoxModel, UMLSubmachineStateComboBoxModel, UMLTagDefinitionComboBoxModel, UMLTagDefinitionOwnerComboBoxModel, UMLTagDefinitionTypeComboBoxModel

public abstract class UMLComboBoxModel2
extends AbstractListModel
implements PropertyChangeListener, ComboBoxModel, TargetListener

ComboBoxmodel for UML modelelements. This implementation does not use reflection and seperates Model, View and Controller better then does the former UMLComboBoxModel.

This combobox allows selecting no value, if so indicated at construction time of this class. I.e. it is "clearable".

See Also:
Serialized Form

Field Summary
protected  boolean buildingModel
          Flag to indicate whether the model is being build.
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
UMLComboBoxModel2(String name, boolean clearable)
          Constructs a model for a combobox.
 
Method Summary
protected  void addAll(Collection col)
          Utility method to add a collection of elements to the model.
 void addElement(Object o)
           
protected  void addOtherModelEventListeners(Object newTarget)
          This function allows subclasses to listen to more modelelements.
protected abstract  void buildModelList()
          Builds the list of elements and sets the selectedIndex to the currently selected item if there is one.
 boolean contains(Object elem)
          Returns true if some object elem is contained by the list of choices.
protected  void fireContentsChanged(Object source, int index0, int index1)
           
protected  void fireIntervalAdded(Object source, int index0, int index1)
           
protected  void fireIntervalRemoved(Object source, int index0, int index1)
           
protected  Object getChangedElement(PropertyChangeEvent e)
          Utility method to get the changed element from some event e.
 Object getElementAt(int index)
           
 int getIndexOf(Object o)
           
protected  String getName(Object obj)
           
protected  String getPropertySetName()
           
 Object getSelectedItem()
           
protected abstract  Object getSelectedModelElement()
          Gets the modelelement that is selected in the UML model.
 int getSize()
           
protected  Object getTarget()
          Utility method to get the target.
protected  boolean isClearable()
          Return boolean indicating whether combo allows empty string.
protected  boolean isFireListEvents()
           
protected abstract  boolean isValidElement(Object element)
          Returns true if the given element is valid.
protected  boolean isValidEvent(PropertyChangeEvent e)
          Returns true if some event is valid.
 void propertyChange(PropertyChangeEvent evt)
          If the property that this comboboxmodel depicts is changed in the UML model, this method will make sure that the changes will be done in the combobox-model equally.
protected  void removeAll(Collection col)
          Utility method to remove a collection of elements from the model.
 void removeAllElements()
          Remove all elements.
 void removeElement(Object o)
           
protected  void removeOtherModelEventListeners(Object oldTarget)
          This function allows subclasses to listen to more modelelements.
protected  void setElements(Collection elements)
          Utility method to change all elements in the list with modelelements at once.
protected  void setFireListEvents(boolean events)
           
 void setSelectedItem(Object o)
           
protected  void setTarget(Object theNewTarget)
          Sets the target.
 void targetAdded(TargetEvent e)
          Fired when a target is added to the list of targets.
 void targetRemoved(TargetEvent e)
          Fired when a target is removed from the list of targets
 void targetSet(TargetEvent e)
          Fired when a total new set of targets is set
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

buildingModel

protected boolean buildingModel
Flag to indicate whether the model is being build.

Constructor Detail

UMLComboBoxModel2

public UMLComboBoxModel2(String name,
                         boolean clearable)
Constructs a model for a combobox. The container given is used to retreive the target that is manipulated through this combobox. If clearable is true, the user can select null in the combobox and thereby clear the attribute in the model.

Parameters:
name - The name of the property change event that must be fired to set the selected item programmatically (via changing the model)
clearable - Flag to indicate if the user may select "" as value in the combobox. If true the attribute that is shown by this combobox may be set to null. Makes sure that there is allways a "" in the list with objects so the user has the oportunity to select this to clear the attribute.
Throws:
IllegalArgumentException - if one of the arguments is null
Method Detail

propertyChange

public void propertyChange(PropertyChangeEvent evt)
If the property that this comboboxmodel depicts is changed in the UML model, this method will make sure that the changes will be done in the combobox-model equally.

TODO: This function is not yet completely written!

Specified by:
propertyChange in interface PropertyChangeListener
See Also:
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)

isValidElement

protected abstract boolean isValidElement(Object element)
Returns true if the given element is valid.

It is valid if it may be added to the list of elements.

Parameters:
element - the given element
Returns:
true if the given element is valid

buildModelList

protected abstract void buildModelList()
Builds the list of elements and sets the selectedIndex to the currently selected item if there is one. Called from targetChanged every time the target of the proppanel is changed.


getName

protected String getName(Object obj)
Parameters:
obj - an UML object
Returns:
its name or "" (if it was not named or deleted)

setElements

protected void setElements(Collection elements)
Utility method to change all elements in the list with modelelements at once. A minimal update strategy is used to minimize event firing for unchanged elements.

Parameters:
elements - the given elements

getTarget

protected Object getTarget()
Utility method to get the target.

Returns:
the ModelElement

removeAll

protected void removeAll(Collection col)
Utility method to remove a collection of elements from the model.

Parameters:
col - the elements to be removed

addAll

protected void addAll(Collection col)
Utility method to add a collection of elements to the model.

Parameters:
col - the elements to be addd

getChangedElement

protected Object getChangedElement(PropertyChangeEvent e)
Utility method to get the changed element from some event e.

Parameters:
e - the given event
Returns:
Object the changed element

setTarget

protected void setTarget(Object theNewTarget)
Sets the target. If the old target is a ModelElement, it also removes the model from the element listener list of the target. If the new target is a ModelElement, the model is added as element listener to the new target.

This function is called when the user changes the target. Hence, this shall not result in any UML model changes. Hence, we block firing list events completely by setting buildingModel to true for the duration of this function.

This function looks a lot like the one in UMLModelElementListModel2.

Parameters:
theNewTarget - the target

removeOtherModelEventListeners

protected void removeOtherModelEventListeners(Object oldTarget)
This function allows subclasses to listen to more modelelements. The given target is guaranteed to be a UML modelelement.

Parameters:
oldTarget - the UML modelelement

addOtherModelEventListeners

protected void addOtherModelEventListeners(Object newTarget)
This function allows subclasses to listen to more modelelements. The given target is guaranteed to be a UML modelelement.

Parameters:
newTarget - the UML modelelement

getSelectedModelElement

protected abstract Object getSelectedModelElement()
Gets the modelelement that is selected in the UML model. For example, say that this ComboBoxmodel contains all namespaces (as in UMLNamespaceComboBoxmodel) , this method should return the namespace that owns the target then.

Returns:
Object

getElementAt

public Object getElementAt(int index)
Specified by:
getElementAt in interface ListModel
See Also:
ListModel.getElementAt(int)

getSize

public int getSize()
Specified by:
getSize in interface ListModel
See Also:
ListModel.getSize()

getIndexOf

public int getIndexOf(Object o)
Parameters:
o - the given element
Returns:
the index of the given element

addElement

public void addElement(Object o)
Parameters:
o - the element to be added

setSelectedItem

public void setSelectedItem(Object o)
Specified by:
setSelectedItem in interface ComboBoxModel
See Also:
ComboBoxModel.setSelectedItem(java.lang.Object)

removeElement

public void removeElement(Object o)
Parameters:
o - the element to be removed

removeAllElements

public void removeAllElements()
Remove all elements.


getSelectedItem

public Object getSelectedItem()
Specified by:
getSelectedItem in interface ComboBoxModel
See Also:
ComboBoxModel.getSelectedItem()

contains

public boolean contains(Object elem)
Returns true if some object elem is contained by the list of choices.

Parameters:
elem - the given element
Returns:
boolean true if it is in the selection

isValidEvent

protected boolean isValidEvent(PropertyChangeEvent e)
Returns true if some event is valid. An event is valid if the element changed in the event is valid. This is determined via a call to isValidElement. This method can be overriden by subclasses if they cannot determine if it is a valid event just by checking the changed element.

Parameters:
e - the event
Returns:
boolean true if the event is valid

fireContentsChanged

protected void fireContentsChanged(Object source,
                                   int index0,
                                   int index1)
See Also:
AbstractListModel.fireContentsChanged( Object, int, int)

fireIntervalAdded

protected void fireIntervalAdded(Object source,
                                 int index0,
                                 int index1)
See Also:
AbstractListModel.fireIntervalAdded( Object, int, int)

fireIntervalRemoved

protected void fireIntervalRemoved(Object source,
                                   int index0,
                                   int index1)
See Also:
AbstractListModel.fireIntervalRemoved( Object, int, int)

targetAdded

public void targetAdded(TargetEvent e)
Description copied from interface: TargetListener
Fired when a target is added to the list of targets.

Specified by:
targetAdded in interface TargetListener
Parameters:
e - The targetevent, name will be TARGET_ADDED
See Also:
TargetListener.targetAdded(TargetEvent)

targetRemoved

public void targetRemoved(TargetEvent e)
Description copied from interface: TargetListener
Fired when a target is removed from the list of targets

Specified by:
targetRemoved in interface TargetListener
Parameters:
e - The targetevent, name will be TARGET_REMOVED
See Also:
TargetListener.targetRemoved(TargetEvent)

targetSet

public void targetSet(TargetEvent e)
Description copied from interface: TargetListener
Fired when a total new set of targets is set

Specified by:
targetSet in interface TargetListener
Parameters:
e - The targetevent, name will be TARGET_SET
See Also:
TargetListener.targetSet(TargetEvent)

isClearable

protected boolean isClearable()
Return boolean indicating whether combo allows empty string.

Returns:
state of isClearable flag

getPropertySetName

protected String getPropertySetName()
Returns:
name of property registered with event listener

isFireListEvents

protected boolean isFireListEvents()
Returns:
Returns the fireListEvents.

setFireListEvents

protected void setFireListEvents(boolean events)
Parameters:
events - The fireListEvents to set.


ArgoUML © 1996-2006ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook