pl.edu.agh.cast.data.model.visual
Class VisualElement<M extends IPresentationElement<? extends IElement>>

java.lang.Object
  extended by pl.edu.agh.cast.data.model.property.PropertyContainer
      extended by pl.edu.agh.cast.data.model.AbstractElement
          extended by pl.edu.agh.cast.data.model.visual.VisualElement<M>
Type Parameters:
M - type of wrapped presentation element
All Implemented Interfaces:
Serializable, Observer, IDisposable, IReplicable, IValidatable, Identifiable, IElement, IPropertyChangeProvider, IPropertyContainer, IVisualElement<M>
Direct Known Subclasses:
VisualSchemaConnection, VisualSchemaNode

public abstract class VisualElement<M extends IPresentationElement<? extends IElement>>
extends AbstractElement
implements IVisualElement<M>

Abstract implementation of IVisualElement.

Author:
AGH CAST Team
See Also:
IVisualElement, IVisualDataSet, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface pl.edu.agh.cast.data.model.visual.IVisualElement
IVisualElement.Properties
 
Field Summary
protected  M presentationElement
          A reference to presentation element which is described by this visual element.
 
Fields inherited from interface pl.edu.agh.cast.data.model.visual.IVisualElement
DEFAULT_VISUAL_LABEL_ID, TYPE
 
Constructor Summary
protected VisualElement(IVisualDataSet<? extends IVisualElement<?>,? extends IPresentationDataSet<?>> dataSet, Type type, M presentationElement)
          Constructor.
protected VisualElement(IVisualDataSet<? extends IVisualElement<?>,? extends IPresentationDataSet<?>> dataSet, Type type, UUID id, M presentationElement)
          Constructor.
protected VisualElement(Type type)
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Add a property change listener to the object.
protected  boolean checkIfValid()
          Checks if the element is valid - the element reference is not null and the referenced element is valid.
protected  boolean checkIfValidVisualElement()
          Checks if the visual element is valid.
protected  void firePropertyChange(String property, Object oldValue, Object newValue)
          Fires the property change event.
 M getPresentationElement()
          Gets element from presentation model which is described by this visual element.
 Collection<Property<? extends MetaProperty>> getPropertiesMarkedAsLabel()
          Gets collection of properties marked as label (including properties of presentation, visual and original elements).
 String getVisualLabel()
          Gets visual label which is created from all properties returned by IVisualDataSet.getPropertiesMarkedAsLabel(Type).
 void markPropertyAsLabel(PresentationPropertyDescriptor desc, boolean flag)
          Marks given property as label.
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a property change listener to the object.
 VisualElement<M> replicateTo(Object replica)
          Replicates this instance state to given replica object.
 void setPresentationElement(M pe)
          Sets the element from presentation model which is described by this visual element.
 
Methods inherited from class pl.edu.agh.cast.data.model.AbstractElement
afterSetMetaPropertyManager, canReplicateTo, equals, getDataSet, getDescString, getId, getType, hashCode, isValid, replicate, setDataSet, setId, setType, toString
 
Methods inherited from class pl.edu.agh.cast.data.model.property.PropertyContainer
addProperty, createProperty, dispose, getCustomProperties, getMetaPropertyManager, getPermanentProperties, getProperties, getProperty, getTransientProperties, initializeProperties, matches, removeProperty, setMetaPropertyManager, setProperty, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface pl.edu.agh.cast.data.model.IElement
getDataSet
 
Methods inherited from interface pl.edu.agh.cast.data.model.Identifiable
getId, getType
 
Methods inherited from interface pl.edu.agh.cast.data.model.property.IPropertyContainer
addProperty, getCustomProperties, getMetaPropertyManager, getPermanentProperties, getProperties, getProperty, getTransientProperties, matches, removeProperty, setProperty
 
Methods inherited from interface java.util.Observer
update
 
Methods inherited from interface pl.edu.agh.cast.common.IValidatable
isValid
 
Methods inherited from interface pl.edu.agh.cast.common.IDisposable
dispose
 
Methods inherited from interface pl.edu.agh.cast.common.IReplicable
replicate
 

Field Detail

presentationElement

protected M extends IPresentationElement<? extends IElement> presentationElement
A reference to presentation element which is described by this visual element.

Constructor Detail

VisualElement

protected VisualElement(Type type)

VisualElement

protected VisualElement(IVisualDataSet<? extends IVisualElement<?>,? extends IPresentationDataSet<?>> dataSet,
                        Type type,
                        M presentationElement)
Constructor.

Parameters:
dataSet - data set which this element belongs to
type - element type
presentationElement - a presentation element which is described by this visual element.

VisualElement

protected VisualElement(IVisualDataSet<? extends IVisualElement<?>,? extends IPresentationDataSet<?>> dataSet,
                        Type type,
                        UUID id,
                        M presentationElement)
Constructor.

Parameters:
dataSet - data set which this element belongs to
type - element type
id - the ID of the element
presentationElement - a presentation element which is described by this visual element.
Method Detail

checkIfValid

protected boolean checkIfValid()
Checks if the element is valid - the element reference is not null and the referenced element is valid.

In order to allow for additional validation by subclasses, the result of checkIfValidVisualElement() method is checked.

Overrides:
checkIfValid in class AbstractElement
Returns:
true if the element is valid, false otherwise
See Also:
AbstractElement.checkIfValid(), checkIfValidVisualElement(), IValidatable.isValid()

checkIfValidVisualElement

protected boolean checkIfValidVisualElement()
Checks if the visual element is valid.

This method is called by the checkIfValid() method. By default it always returns true, however it can be overridden in order to define new validation rules. In such case the implementation from base class should be called inside the overridden method in order to preserve data consistency.

Returns:
true if the visual element is valid, false otherwise

getPresentationElement

public M getPresentationElement()
Gets element from presentation model which is described by this visual element.

Specified by:
getPresentationElement in interface IVisualElement<M extends IPresentationElement<? extends IElement>>
Returns:
presentation element
See Also:
IVisualElement.getPresentationElement()

setPresentationElement

public void setPresentationElement(M pe)
Sets the element from presentation model which is described by this visual element.

Specified by:
setPresentationElement in interface IVisualElement<M extends IPresentationElement<? extends IElement>>
Parameters:
pe - presentation element to set
See Also:
#setPresentationElement(pl.edu.agh.cast.data.model.presentation.IPresentationElement)

getVisualLabel

public final String getVisualLabel()
Gets visual label which is created from all properties returned by IVisualDataSet.getPropertiesMarkedAsLabel(Type). If marked property does not exists in given element it is ignored. This method should be used by editor to display elements' labels.

Specified by:
getVisualLabel in interface IVisualElement<M extends IPresentationElement<? extends IElement>>
Returns:
visual label which at least contains one property
See Also:
IVisualElement.getVisualLabel()

getPropertiesMarkedAsLabel

public final Collection<Property<? extends MetaProperty>> getPropertiesMarkedAsLabel()
Gets collection of properties marked as label (including properties of presentation, visual and original elements). If always return collection which contains at least one property. If no properties is marked as label the IVisualElement.DEFAULT_VISUAL_LABEL_ID.

Specified by:
getPropertiesMarkedAsLabel in interface IVisualElement<M extends IPresentationElement<? extends IElement>>
Returns:
collection of properties marked as label
See Also:
IVisualElement.getPropertiesMarkedAsLabel()

markPropertyAsLabel

public final void markPropertyAsLabel(PresentationPropertyDescriptor desc,
                                      boolean flag)
Marks given property as label. If flag is true the property is added to label, otherwise it is removed from label.

Specified by:
markPropertyAsLabel in interface IVisualElement<M extends IPresentationElement<? extends IElement>>
Parameters:
desc - object which describes property to be added or removed from label
flag - flag which indicate is given property is to be added or removed from label
See Also:
#markPropertyAsLabel(pl.edu.agh.cast.data.model.presentation.PresentationPropertyDescriptor, boolean)

addPropertyChangeListener

public final 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:
#addPropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public final 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 final void firePropertyChange(String property,
                                        Object oldValue,
                                        Object newValue)
Fires the property change event.

Parameters:
property - the name of the property
oldValue - the old value of the property
newValue - the new value of the property
See Also:
PropertyChangeProviderHelper.firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

replicateTo

public VisualElement<M> replicateTo(Object replica)
                                                                              throws IllegalArgumentException,
                                                                                     ReplicationException
Replicates this instance state to given replica object. The replica should be an instance of replicated instance's class (same class or subclass).

Replicates element type and ID.

Specified by:
replicateTo in interface IReplicable
Overrides:
replicateTo in class AbstractElement
Parameters:
replica - the object to replicate to
Returns:
the replica object (the same instance as given)
Throws:
IllegalArgumentException - if given object is null or of invalid type
ReplicationException - if replication fails
See Also:
AbstractElement.replicateTo(java.lang.Object)


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