org.argouml.uml.ui
Class UMLComboBoxModel2

java.lang.Object
  |
  +--javax.swing.AbstractListModel
        |
        +--org.argouml.uml.ui.UMLComboBoxModel2
All Implemented Interfaces:
javax.swing.ComboBoxModel, java.util.EventListener, javax.swing.ListModel, java.io.Serializable, TargetListener
Direct Known Subclasses:
UMLAssociationRoleBaseComboBoxModel, UMLExtendBaseComboBoxModel, UMLExtendExtensionComboBoxModel, UMLFeatureOwnerComboBoxModel, UMLGeneralizationPowertypeComboBoxModel, UMLIncludeAdditionComboBoxModel, UMLIncludeBaseComboBoxModel, UMLMessageActivatorComboBoxModel, UMLModelElementNamespaceComboBoxModel, UMLModelElementStereotypeComboBoxModel, UMLMultiplicityComboBoxModel, UMLReceptionSignalComboBoxModel, UMLStructuralFeatureTypeComboBoxModel, UMLSubmachineStateComboBoxModel

public abstract class UMLComboBoxModel2
extends javax.swing.AbstractListModel
implements javax.swing.ComboBoxModel, TargetListener

ComboBoxmodel for UML modelelements. This implementation does not use reflection and seperates Model, View and Controller better then does UMLComboBoxModel. In the future UMLComboBoxModel and UMLComboBox will be replaced with this implementation to improve performance.

See Also:
Serialized Form

Field Summary
protected  boolean _fireListEvents
          Flag to indicate wether list events should be fired
protected  java.lang.String _propertySetName
          The name of the event with which NSUML sets the attribute that is shown in this comboboxmodel.
protected  java.lang.Object _target
          The taget of the comboboxmodel.
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
UMLComboBoxModel2(java.lang.String propertySetName, boolean clearable)
          Constructs a model for a combobox.
 
Method Summary
protected  void addAll(java.util.Collection col)
          Utility method to add a collection of elements to the model
 void addElement(java.lang.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(java.lang.Object elem)
          Returns true if some object elem is contained by the list of choices
protected  void fireContentsChanged(java.lang.Object source, int index0, int index1)
           
protected  void fireIntervalAdded(java.lang.Object source, int index0, int index1)
           
protected  void fireIntervalRemoved(java.lang.Object source, int index0, int index1)
           
protected  java.lang.Object getChangedElement(MElementEvent e)
          Utility method to get the changed element from some event e
 java.lang.Object getElementAt(int index)
           
 int getIndexOf(java.lang.Object o)
           
 java.lang.Object getSelectedItem()
           
protected abstract  java.lang.Object getSelectedModelElement()
          Gets the modelelement that is selected in the NSUML model.
 int getSize()
           
protected  java.lang.Object getTarget()
          Utility method to get the target.
protected abstract  boolean isValidElement(java.lang.Object element)
          Returns true if the given element is valid, i.e.
protected  boolean isValidEvent(MElementEvent e)
          Returns true if some event is valid.
 void listRoleItemSet(MElementEvent e)
           
 void propertySet(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(MElementEvent e)
           
protected  void removeAll(java.util.Collection col)
          Utility method to remove a collection of elements from the model
 void removeAllElements()
           
 void removed(MElementEvent e)
           
 void removeElement(java.lang.Object o)
           
 void roleAdded(MElementEvent e)
           
 void roleRemoved(MElementEvent e)
           
protected  void setElements(java.util.Collection elements)
          Utility method to change all elements in the list with modelelements at once.
 void setSelectedItem(java.lang.Object o)
           
protected  void setTarget(java.lang.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

_target

protected java.lang.Object _target
The taget of the comboboxmodel. This is some UML modelelement


_propertySetName

protected java.lang.String _propertySetName
The name of the event with which NSUML sets the attribute that is shown in this comboboxmodel.


_fireListEvents

protected boolean _fireListEvents
Flag to indicate wether list events should be fired

Constructor Detail

UMLComboBoxModel2

public UMLComboBoxModel2(java.lang.String propertySetName,
                         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:
propertySetName - The name of the NSUML event that must be fired to set the selected item programmatically (via setting the NSUML model)
Throws:
java.lang.IllegalArgumentException - if one of the arguments is null
Method Detail

listRoleItemSet

public void listRoleItemSet(MElementEvent e)
See Also:
ru.novosoft.uml.MElementListener#listRoleItemSet(MElementEvent)

propertySet

public void propertySet(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.

See Also:
ru.novosoft.uml.MElementListener#propertySet(MElementEvent)

recovered

public void recovered(MElementEvent e)
See Also:
ru.novosoft.uml.MElementListener#recovered(MElementEvent)

removed

public void removed(MElementEvent e)
See Also:
ru.novosoft.uml.MElementListener#removed(MElementEvent)

roleAdded

public void roleAdded(MElementEvent e)
See Also:
ru.novosoft.uml.MElementListener#roleAdded(MElementEvent)

roleRemoved

public void roleRemoved(MElementEvent e)
See Also:
ru.novosoft.uml.MElementListener#roleRemoved(MElementEvent)

isValidElement

protected abstract boolean isValidElement(java.lang.Object element)
Returns true if the given element is valid, i.e. it may be added to the list of elements.

Parameters:
element -

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(java.util.Collection elements)
Utility method to change all elements in the list with modelelements at once.

Parameters:
elements -

getTarget

protected java.lang.Object getTarget()
Utility method to get the target. Sets the _target if the _target is null via the method setTarget().

Returns:
MModelElement

removeAll

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

Parameters:
col -

addAll

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

Parameters:
col -

getChangedElement

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

Parameters:
e -
Returns:
Object

setTarget

protected void setTarget(java.lang.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 -

getSelectedModelElement

protected abstract java.lang.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 java.lang.Object getElementAt(int index)
Specified by:
getElementAt in interface javax.swing.ListModel
See Also:
ListModel.getElementAt(int)

getSize

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

getIndexOf

public int getIndexOf(java.lang.Object o)

addElement

public void addElement(java.lang.Object o)

setSelectedItem

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

removeElement

public void removeElement(java.lang.Object o)

removeAllElements

public void removeAllElements()

getSelectedItem

public java.lang.Object getSelectedItem()
Specified by:
getSelectedItem in interface javax.swing.ComboBoxModel

contains

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

Parameters:
elem -
Returns:
boolean

isValidEvent

protected boolean isValidEvent(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 -
Returns:
boolean

fireContentsChanged

protected void fireContentsChanged(java.lang.Object source,
                                   int index0,
                                   int index1)
Overrides:
fireContentsChanged in class javax.swing.AbstractListModel
See Also:
AbstractListModel.fireContentsChanged(java.lang.Object, int, int)

fireIntervalAdded

protected void fireIntervalAdded(java.lang.Object source,
                                 int index0,
                                 int index1)
Overrides:
fireIntervalAdded in class javax.swing.AbstractListModel
See Also:
AbstractListModel.fireIntervalAdded(java.lang.Object, int, int)

fireIntervalRemoved

protected void fireIntervalRemoved(java.lang.Object source,
                                   int index0,
                                   int index1)
Overrides:
fireIntervalRemoved in class javax.swing.AbstractListModel
See Also:
AbstractListModel.fireIntervalRemoved(java.lang.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(org.argouml.ui.targetmanager.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(org.argouml.ui.targetmanager.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(org.argouml.ui.targetmanager.TargetEvent)


ArgoUML © 1996-2003 (20040229)ArgoUML Project HomeArgoUML Cookbook