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, ru.novosoft.uml.MElementListener, PropertyChangeListener, Serializable, TargetListener
Direct Known Subclasses:
UMLAssociationRoleBaseComboBoxModel, UMLCallEventOperationComboBoxModel, UMLExtendBaseComboBoxModel, UMLExtendExtensionComboBoxModel, UMLFeatureOwnerComboBoxModel, UMLGeneralizationPowertypeComboBoxModel, UMLIncludeAdditionComboBoxModel, UMLIncludeBaseComboBoxModel, UMLMessageActivatorComboBoxModel, UMLMetaClassComboBoxModel, UMLModelElementNamespaceComboBoxModel, UMLModelElementStereotypeComboBoxModel, UMLMultiplicityComboBoxModel, UMLObjectFlowStateClassifierComboBoxModel, UMLReceptionSignalComboBoxModel, UMLStructuralFeatureTypeComboBoxModel, UMLStubStateComboBoxModel, UMLSubmachineStateComboBoxModel

public abstract class UMLComboBoxModel2
extends AbstractListModel
implements ru.novosoft.uml.MElementListener, ComboBoxModel, TargetListener, PropertyChangeListener

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
private  boolean buildingModel
          Flag to indicate wether the model is being build
private  Object comboBoxTarget
          The taget of the comboboxmodel.
private  boolean fireListEvents
          Flag to indicate wether list events should be fired
private  boolean isClearable
          Flag to indicate if the user may select "" as value in the combobox.
private static Logger LOG
           
private  List objects
          The list with objects that should be shown in the combobox
private  String propertySetName
          The name of the event with which NSUML sets the attribute that is shown in this comboboxmodel.
private  Object selectedObject
          The selected object
 
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 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(ru.novosoft.uml.MElementEvent e)
          Utility method to get the changed element from some event e
 Object getElementAt(int index)
           
 int getIndexOf(Object o)
           
 Object getSelectedItem()
           
protected abstract  Object getSelectedModelElement()
          Gets the modelelement that is selected in the NSUML model.
 int getSize()
           
protected  Object getTarget()
          Utility method to get the target.
protected abstract  boolean isValidElement(Object element)
          Returns true if the given element is valid, i.e.
protected  boolean isValidEvent(ru.novosoft.uml.MElementEvent e)
          Returns true if some event is valid.
 void listRoleItemSet(ru.novosoft.uml.MElementEvent e)
           
 void propertyChange(PropertyChangeEvent evt)
          If the property that this comboboxmodel depicts is changed in the UML model, this method will make sure that it is changed in the comboboxmodel too.
 void propertySet(ru.novosoft.uml.MElementEvent e)
          If the property that this comboboxmodel depicts is changed by the NSUML model, this method will make sure that it is changed in the comboboxmodel too.
 void recovered(ru.novosoft.uml.MElementEvent e)
           
protected  void removeAll(Collection col)
          Utility method to remove a collection of elements from the model.
 void removeAllElements()
          Remove all elements.
 void removed(ru.novosoft.uml.MElementEvent e)
           
 void removeElement(Object o)
           
 void roleAdded(ru.novosoft.uml.MElementEvent e)
           
 void roleRemoved(ru.novosoft.uml.MElementEvent e)
           
protected  void setElements(Collection elements)
          Utility method to change all elements in the list with modelelements at once.
 void setSelectedItem(Object o)
           
protected  void setTarget(Object target)
          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

LOG

private static final Logger LOG

comboBoxTarget

private Object comboBoxTarget
The taget of the comboboxmodel. This is some UML modelelement


objects

private List objects
The list with objects that should be shown in the combobox


selectedObject

private Object selectedObject
The selected object


isClearable

private boolean isClearable
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.


propertySetName

private String propertySetName
The name of the event with which NSUML sets the attribute that is shown in this comboboxmodel.


fireListEvents

private boolean fireListEvents
Flag to indicate wether list events should be fired


buildingModel

private boolean buildingModel
Flag to indicate wether 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 NSUML event that must be fired to set the selected item programmatically (via setting the NSUML 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 it is changed in the comboboxmodel too. TODO: This function is not yet completely written!

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

listRoleItemSet

public void listRoleItemSet(ru.novosoft.uml.MElementEvent e)
Specified by:
listRoleItemSet in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.listRoleItemSet(MElementEvent)

propertySet

public void propertySet(ru.novosoft.uml.MElementEvent e)
If the property that this comboboxmodel depicts is changed by the NSUML model, this method will make sure that it is changed in the comboboxmodel too.

TODO: MVW I tested this for the PropPanelCallEvent. It also works without this function. Why do we need this?

Specified by:
propertySet in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.propertySet(MElementEvent)

recovered

public void recovered(ru.novosoft.uml.MElementEvent e)
Specified by:
recovered in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.recovered(MElementEvent)

removed

public void removed(ru.novosoft.uml.MElementEvent e)
Specified by:
removed in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.removed(MElementEvent)

roleAdded

public void roleAdded(ru.novosoft.uml.MElementEvent e)
Specified by:
roleAdded in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.roleAdded(MElementEvent)

roleRemoved

public void roleRemoved(ru.novosoft.uml.MElementEvent e)
Specified by:
roleRemoved in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.roleRemoved(MElementEvent)

isValidElement

protected abstract boolean isValidElement(Object element)
Returns true if the given element is valid, i.e. 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.


setElements

protected void setElements(Collection elements)
Utility method to change all elements in the list with modelelements at once.

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(ru.novosoft.uml.MElementEvent 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 target)
Sets the target. If the old target is instanceof MBase, it also removes the model from the element listener list of the target. If the new target is instanceof MBase, the model is added as element listener to the new target.

Parameters:
target - the target

getSelectedModelElement

protected abstract Object getSelectedModelElement()
Gets the modelelement that is selected in the NSUML 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(ru.novosoft.uml.MElementEvent 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)


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook