org.argouml.uml.ui
Class UMLModelElementListModel2

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by javax.swing.DefaultListModel
          extended by org.argouml.uml.ui.UMLModelElementListModel2
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.ListModel, TargetListener
Direct Known Subclasses:
PropPanelActivityGraph.UMLActivityGraphPartiitionListModel, UMLAssociationAssociationRoleListModel, UMLAssociationEndAssociationListModel, UMLAssociationEndRoleBaseListModel, UMLAssociationEndSpecificationListModel, UMLAssociationLinkListModel, UMLAssociationRoleAssociationEndRoleListModel, UMLAssociationRoleMessageListModel, UMLAttributeInitialValueListModel, UMLClassifierAssociationEndListModel, UMLClassifierCreateActionListModel, UMLClassifierPowertypeRangeListModel, UMLClassifierRoleAvailableContentsListModel, UMLClassifierRoleAvailableFeaturesListModel, UMLClassifierRoleBaseListModel, UMLCollaborationConstrainingElementListModel, UMLCollaborationInteractionListModel, UMLCommentAnnotatedElementListModel, UMLComponentResidentListModel, UMLCompositeStateSubvertexListModel, UMLConstraintConstrainedElementListModel, UMLContainerResidentListModel, UMLCreateActionClassifierListModel, UMLDependencyClientListModel, UMLDependencySupplierListModel, UMLDirectedRelationshipSourceListModel, UMLDirectedRelationshipTargetListModel, UMLEventTransitionListModel, UMLExtendBaseListModel, UMLExtendExtensionListModel, UMLExtensionPointExtendListModel, UMLExtensionPointUseCaseListModel, UMLFeatureOwnerListModel, UMLGeneralizableElementGeneralizationListModel, UMLGeneralizableElementSpecializationListModel, UMLGeneralizationChildListModel, UMLGeneralizationParentListModel, UMLGuardTransitionListModel, UMLIncludeListModel, UMLInstanceClassifierListModel, UMLInstanceLinkEndListModel, UMLInstanceReceiverStimulusListModel, UMLInstanceSenderStimulusListModel, UMLInteractionContextListModel, UMLInteractionMessagesListModel, UMLMessageActionListModel, UMLMessageInteractionListModel, UMLMessagePredecessorListModel, UMLMessageReceiverListModel, UMLMessageSenderListModel, UMLModelElementClientDependencyListModel, UMLModelElementConstraintListModel, UMLModelElementElementResidenceListModel, UMLModelElementElementResidenceListModel, UMLModelElementNamespaceListModel, UMLModelElementOrderedListModel2, UMLModelElementSourceFlowListModel, UMLModelElementStereotypeListModel, UMLModelElementSupplierDependencyListModel, UMLModelElementTargetFlowListModel, UMLNamespaceOwnedElementListModel, UMLOperationMethodsListModel, UMLOperationRaisedExceptionsListModel, UMLOperationRaisedSignalsListModel, UMLParameterBehavioralFeatListModel, UMLSignalContextListModel, UMLStateDeferrableEventListModel, UMLStateDoActivityListModel, UMLStateEntryListModel, UMLStateExitListModel, UMLStateInternalTransition, UMLStateMachineContextListModel, UMLStateMachineSubmachineStateListModel, UMLStateMachineTopListModel, UMLStateMachineTransitionListModel, UMLStateVertexContainerListModel, UMLStateVertexIncomingListModel, UMLStateVertexOutgoingListModel, UMLStimulusReceiverListModel, UMLStimulusSenderListModel, UMLTransitionEffectListModel, UMLTransitionGuardListModel, UMLTransitionSourceListModel, UMLTransitionStateListModel, UMLTransitionStatemachineListModel, UMLTransitionTargetListModel, UMLTransitionTriggerListModel, UMLUseCaseExtendListModel, UMLUseCaseIncludeListModel

public abstract class UMLModelElementListModel2
extends javax.swing.DefaultListModel
implements TargetListener, java.beans.PropertyChangeListener

The model for a list that contains ModelElements. The state of the Element is still kept in the model subsystem itself. This list is only to be used as the model for some GUI element like UMLLinkedList.

Since:
Oct 2, 2002
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
UMLModelElementListModel2()
          Constructor to be used if the subclass does not depend on the MELementListener methods and setTarget method implemented in this class.
UMLModelElementListModel2(java.lang.String name)
          Constructor for UMLModelElementListModel2.
UMLModelElementListModel2(java.lang.String name, java.lang.Object theMetaType)
          Constructor for UMLModelElementListModel2.
UMLModelElementListModel2(java.lang.String name, java.lang.Object theMetaType, boolean reverseTheDropConnection)
          Constructor for UMLModelElementListModel2.
 
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 obj)
           
protected  void addOtherModelEventListeners(java.lang.Object newTarget)
          This function allows subclasses to listen to more modelelements.
protected abstract  void buildModelList()
          Builds the list of elements.
 boolean buildPopup(javax.swing.JPopupMenu popup, int index)
          Override this if you want a popup menu.
 boolean contains(java.lang.Object elem)
           
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(java.beans.PropertyChangeEvent e)
          Utility method to get the changed element from some event e
 java.lang.Object getMetaType()
          Get the type of objects that this list model is designed to contain.
 java.lang.Object getTarget()
          Utility method to get the target.
protected  boolean hasPopup()
           
 boolean isReverseDropConnection()
           
protected abstract  boolean isValidElement(java.lang.Object element)
          Returns true if the given element is valid, i.e.
protected  boolean isValidEvent(java.beans.PropertyChangeEvent e)
          Returns true if some event is valid.
 void propertyChange(java.beans.PropertyChangeEvent e)
           
protected  void removeOtherModelEventListeners(java.lang.Object oldTarget)
          This function allows subclasses to listen to more modelelements.
protected  void setAllElements(java.util.Collection col)
          Utility method to set the elements of this list to the contents of the given collection.
protected  void setBuildingModel(boolean building)
           
protected  void setEventName(java.lang.String theEventName)
          Sets the eventName.
protected  void setListTarget(java.lang.Object t)
           
 void setTarget(java.lang.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.DefaultListModel
add, capacity, clear, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, setSize, size, toArray, toString, trimToSize
 
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, wait, wait, wait
 

Constructor Detail

UMLModelElementListModel2

public UMLModelElementListModel2()
Constructor to be used if the subclass does not depend on the MELementListener methods and setTarget method implemented in this class.


UMLModelElementListModel2

public UMLModelElementListModel2(java.lang.String name)
Constructor for UMLModelElementListModel2.

Parameters:
name - the name of the event to listen to, which triggers us to update the list model from the UML data

UMLModelElementListModel2

public UMLModelElementListModel2(java.lang.String name,
                                 java.lang.Object theMetaType)
Constructor for UMLModelElementListModel2.

Parameters:
name - the name of the event to listen to, which triggers us to update the list model from the UML data
theMetaType - the type of model element that the list model is designed to contain.

UMLModelElementListModel2

public UMLModelElementListModel2(java.lang.String name,
                                 java.lang.Object theMetaType,
                                 boolean reverseTheDropConnection)
Constructor for UMLModelElementListModel2.

Parameters:
name - the name of the event to listen to, which triggers us to update the list model from the UML data
theMetaType - the type of model element that the list model is designed to contain.
reverseTheDropConnection - tells the JList to reverse the connection made and drop during dnd.
Method Detail

getMetaType

public java.lang.Object getMetaType()
Get the type of objects that this list model is designed to contain.

Returns:
metaType the meta type.

isReverseDropConnection

public boolean isReverseDropConnection()

setBuildingModel

protected void setBuildingModel(boolean building)
Parameters:
building - The buildingModel to set.

setListTarget

protected void setListTarget(java.lang.Object t)
Parameters:
t - the list target to set

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

buildModelList

protected abstract void buildModelList()
Builds the list of elements. Called from targetChanged every time the target of the proppanel is changed. Usually the method setAllElements is called with the result.


setAllElements

protected void setAllElements(java.util.Collection col)
Utility method to set the elements of this list to the contents of the given collection.

Parameters:
col - the given collection

addAll

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

Parameters:
col - the given collection

getTarget

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

Returns:
MModelElement

getChangedElement

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

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

contains

public boolean contains(java.lang.Object elem)
Overrides:
contains in class javax.swing.DefaultListModel

setTarget

public void setTarget(java.lang.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 instanceof 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 UMLComboBoxModel2.

Parameters:
theNewTarget - the new target

removeOtherModelEventListeners

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

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 - the element to be tested
Returns:
true if valid

isValidEvent

protected boolean isValidEvent(java.beans.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 valid

addElement

public void addElement(java.lang.Object obj)
Overrides:
addElement in class javax.swing.DefaultListModel

setEventName

protected void setEventName(java.lang.String theEventName)
Sets the eventName. The eventName is the name of the MElementEvent to which the list should listen. The list is registred with UMLModelEventPump and only gets events that have a name like eventName. This method should be called in the constructor of every subclass.

Parameters:
theEventName - The eventName to set

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

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

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

fireContentsChanged

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

fireIntervalAdded

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

fireIntervalRemoved

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

buildPopup

public boolean buildPopup(javax.swing.JPopupMenu popup,
                          int index)
Override this if you want a popup menu. See for an example UMLModelElementOrderedListModel2.

Parameters:
popup - the popup menu
index - the selected item in the list at the moment the mouse was clicked
Returns:
true if a popup menu is created, and needs to be shown

hasPopup

protected boolean hasPopup()


ArgoUML © 1996-2006ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook