pl.edu.agh.cast.model.visual.backward
Class ModelElement

java.lang.Object
  extended by pl.edu.agh.cast.model.visual.backward.ModelElement
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, IPropertyChangeProvider, AttributeValueContainer
Direct Known Subclasses:
ConnectionGroup, Diagram, Legend, Node

public abstract class ModelElement
extends Object
implements Serializable, IPropertyChangeProvider, AttributeValueContainer, PropertyChangeListener

An abstract class for a visual model element. Provides implementation for property change support.

Author:
AGH CAST Team
See Also:
Serialized Form

Field Summary
static String ATTRIBUTE_CHANGE
          Id of an event informing of attribute value changes in model elements.
protected  SortedMap<Attribute,AttributeValue> attributeValues
           
 
Constructor Summary
protected ModelElement()
          Initializes new instance.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Add a property change listener to the object.
protected  void bindToAttributeManager()
          Registers this model elements to notifications from its attribute manager about changed properties.
protected  void copyAttributes(AttributeValueContainer target)
          Copies attributes present in current model element to another model element.
 void copyAttributeValues(Mappable mappable)
          Copies values of all Attributes of mappable that are registered in this ModelElement 's AttributeManager.
protected  void firePropertyChange(String property, Object oldValue, Object newValue)
          Notifies about property change.
 List<AttributeValue> getAllValues()
          Returns complete list of attribute values in this container.
abstract  AttributeManager getAttributeManager()
          Returns attribute manager for this container.
 AttributeValue getAttributeValue(String name)
          Returns the value of the attribute named name.
 long getMid()
           
 boolean isAttributeEditable(String attributeName)
          Checks if given attribute is editable.
 boolean isAttributeSettable(String name)
          Checks if an attribute value may be set.
 boolean isSaved()
           
 void propertyChange(PropertyChangeEvent evt)
          
protected  Object readResolve()
           
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a property change listener to the object.
 AttributeValue removePropertyValue(String name)
          Removes attribute value from this container.
 void setAttributeValue(String name, Object newValue)
          Sets a new attribute value, fires change event.
 void setAttributeValue(String name, Object newValue, AttributeMergePolicy policy)
          Sets a new attribute value according to given AttributeMergePolicy, fires change event.
 void setMid(long mid)
           
 void setSaved(boolean saved)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_CHANGE

public static final String ATTRIBUTE_CHANGE
Id of an event informing of attribute value changes in model elements. In the PropertyChangeEvent, old value is of type AttributeValue, and new value is the AttributeValue.getValue() of the new value.

See Also:
Constant Field Values

attributeValues

@XStreamConverter(value=AttributeValuesConverter.class)
protected SortedMap<Attribute,AttributeValue> attributeValues
Constructor Detail

ModelElement

protected ModelElement()
Initializes new instance.

Method Detail

getAttributeManager

public abstract AttributeManager getAttributeManager()
Returns attribute manager for this container.

Specified by:
getAttributeManager in interface AttributeValueContainer
Returns:
attribute manager for this container
See Also:
AttributeValueContainer.getAttributeManager()

getMid

public long getMid()

setMid

public void setMid(long mid)

isSaved

public boolean isSaved()

setSaved

public void setSaved(boolean saved)

readResolve

protected Object readResolve()

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Add a property change listener to the object.

Specified by:
addPropertyChangeListener in interface IPropertyChangeProvider
Parameters:
l - property change listener
See Also:
IPropertyChangeProvider.addPropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove a property change listener to the object.

Specified by:
removePropertyChangeListener in interface IPropertyChangeProvider
Parameters:
l - property change listener
See Also:
#removePropertyChangeListener(java.beans.PropertyChangeListener)

firePropertyChange

protected void firePropertyChange(String property,
                                  Object oldValue,
                                  Object newValue)
Notifies about property change.

Parameters:
property - name of the property
oldValue - old value of the property
newValue - new value of the property

getAttributeValue

public AttributeValue getAttributeValue(String name)
Returns the value of the attribute named name.

Specified by:
getAttributeValue in interface AttributeValueContainer
Parameters:
name - name of the attribute
Returns:
an AttributeValue instance for the given attribute
See Also:
AttributeValueContainer.getAttributeValue(java.lang.String)

isAttributeSettable

public boolean isAttributeSettable(String name)
Checks if an attribute value may be set.

Parameters:
name - name of the attribute
Returns:
true if attribute value may be set

setAttributeValue

public void setAttributeValue(String name,
                              Object newValue)
Sets a new attribute value, fires change event.

Specified by:
setAttributeValue in interface AttributeValueContainer
Parameters:
name - name of the attribute to change
newValue - new value of the attribute
See Also:
AttributeValueContainer.setAttributeValue(java.lang.String, java.lang.Object)

setAttributeValue

public void setAttributeValue(String name,
                              Object newValue,
                              AttributeMergePolicy policy)
Sets a new attribute value according to given AttributeMergePolicy, fires change event. If policy is null then acts the same as AttributeValueContainer.setAttributeValue(String, Object).

Specified by:
setAttributeValue in interface AttributeValueContainer
Parameters:
name - name of the attribute to change
newValue - new value of the attribute
policy - merge policy
See Also:
AttributeValueContainer.setAttributeValue(java.lang.String, java.lang.Object, pl.edu.agh.cast.model.attributes.AttributeMergePolicy)

isAttributeEditable

public boolean isAttributeEditable(String attributeName)
Checks if given attribute is editable.

Specified by:
isAttributeEditable in interface AttributeValueContainer
Parameters:
attributeName - name of the attribute
Returns:
editable flag
See Also:
AttributeValueContainer.isAttributeEditable(java.lang.String)

getAllValues

public List<AttributeValue> getAllValues()
Returns complete list of attribute values in this container. Takes into consideration that registered properties may have changed in the manager, i.e. some values may be obsolete.

Specified by:
getAllValues in interface AttributeValueContainer
Returns:
list of all contained AttributeValues
See Also:
AttributeValueContainer.getAllValues()

removePropertyValue

public AttributeValue removePropertyValue(String name)
Removes attribute value from this container.

Specified by:
removePropertyValue in interface AttributeValueContainer
Parameters:
name - name of attribute to remove
Returns:
removed AttributeValue, or null if this attribute's value was not set (see Collection.remove(Object))
See Also:
AttributeValueContainer.removePropertyValue(java.lang.String)

copyAttributes

protected void copyAttributes(AttributeValueContainer target)
Copies attributes present in current model element to another model element.

Parameters:
target - AttributeValueContainer to copy to

propertyChange

public void propertyChange(PropertyChangeEvent evt)

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

bindToAttributeManager

protected final void bindToAttributeManager()
Registers this model elements to notifications from its attribute manager about changed properties.


copyAttributeValues

public void copyAttributeValues(Mappable mappable)
Copies values of all Attributes of mappable that are registered in this ModelElement 's AttributeManager. If defined, the Attribute.getDefaultMergePolicy() policies are used in order to update particular attribute value.

Parameters:
mappable - Mappable to copy attribute values' from


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.