cz.cuni.amis.pogamut.sposh.elements
Class PoshElement<T extends PoshElement,PARENT extends PoshElement>

Package class diagram package PoshElement
java.lang.Object
  extended by cz.cuni.amis.pogamut.sposh.elements.PoshElement<T,PARENT>
Direct Known Subclasses:
PoshDummyElement

public abstract class PoshElement<T extends PoshElement,PARENT extends PoshElement>
extends Object

Ancestor of representative of one element in Posh plan. Listens for various modifications in POSH tree structure. Listener is connected on one particular PoshElement, so many events are neighbours and so on. Various uses, manily during construction of new tree from file. BASIC LEMMA IS: Reality DataNode, Representation PoshWidget (Model, view, controller)

Add new node:

Delete node: Result: PoshElement DN will be deleted along with all associated PoshWidgets

Author:
HonzaH

Constructor Summary
PoshElement()
           
 
Method Summary
 boolean addElementListener(PoshElementListener<T> listener)
          Add new listener for events of this node.
protected  void emitChildDeleted(PoshElement child, int removedChildPosition)
          Tell all listeners that a child of this element has been deleted.
protected  void emitChildMove(PoshElement childNode, int oldIndex, int newIndex)
          Notify all listeners (associated Widgets) that one child of this node has changed order(position).
protected  void emitChildNode(PoshElement emitedChild)
          Notify all listeners (mostly associated Widgets) that this dataNode has a new child.
protected  void firePropertyChange(String name, Object o, Object n)
          Notify all listeners about change of a property.
abstract  List<? extends PoshElement> getChildDataNodes()
          Get list of children of this node.
 int getChildId(PoshElement child)
          Get index of a @child.
 List<? extends PoshElement> getChildren(LapType selectType)
          Get all children of this element that have @selectType.
abstract  DataFlavor getDataFlavor()
          Get data flavour of posh plan element,used during DnD from palette to PoshScene.
 Set<PoshElementListener<T>> getElementListeners()
          Get list of listeners that listen for changes of this node (new child, node deletion, childMoved and change of properties)
 int getId()
          Get Id of this element.
 PARENT getParent()
          Get parent of the node.
 PoshPlan getRootNode()
          Get root node of POSH plan this node belongs to.
abstract  LapType getType()
          Get type of the element.
protected  boolean isChildOfParent()
          Is this element present as a a child in its parent? If element has no parent, return false.
abstract  boolean moveChild(int newIndex, PoshElement child)
          Move child to the @newIndex.
 boolean removeElementListener(PoshElementListener<T> listener)
          Remove listener from list of listeners of this node.
protected  void setParent(PARENT parent)
          Set parent PoshElement of the node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoshElement

public PoshElement()
Method Detail

getElementListeners

public final Set<PoshElementListener<T>> getElementListeners()
Get list of listeners that listen for changes of this node (new child, node deletion, childMoved and change of properties)

Returns:
unmodifiable list of listeners, never null,

addElementListener

public final boolean addElementListener(PoshElementListener<T> listener)
Add new listener for events of this node.

Parameters:
listener - listener to add
Returns:
true if listener was added. false if listener was already among listeners.

removeElementListener

public final boolean removeElementListener(PoshElementListener<T> listener)
Remove listener from list of listeners of this node.

Parameters:
listener - listener to remove
Returns:
Did listeners of this element of this element contain passed listener?

firePropertyChange

protected final void firePropertyChange(String name,
                                        Object o,
                                        Object n)
Notify all listeners about change of a property.

Parameters:
name - name of property
o - old value, can be null, but reciever has to be able to handle it
n - new value, can be null, but reciever has to be able to handle it

getDataFlavor

public abstract DataFlavor getDataFlavor()
Get data flavour of posh plan element,used during DnD from palette to PoshScene.

Returns:
dataFlavour of posh plan element, never null.

getType

public abstract LapType getType()
Get type of the element.

Returns:
Type of element.

getChildDataNodes

public abstract List<? extends PoshElement> getChildDataNodes()
Get list of children of this node. Most likely auto generated every time this method is called.

Returns:
List of all children of this node.

emitChildNode

protected final void emitChildNode(PoshElement emitedChild)
Notify all listeners (mostly associated Widgets) that this dataNode has a new child. After that emit recursivly children of added element in.

Parameters:
childNode -

emitChildMove

protected final void emitChildMove(PoshElement childNode,
                                   int oldIndex,
                                   int newIndex)
Notify all listeners (associated Widgets) that one child of this node has changed order(position).

Parameters:
childNode -

emitChildDeleted

protected final void emitChildDeleted(PoshElement child,
                                      int removedChildPosition)
Tell all listeners that a child of this element has been deleted. Dont remove listeners, it is job of listener to remove itself.


setParent

protected void setParent(PARENT parent)
Set parent PoshElement of the node.

Parameters:
parent -

getParent

public PARENT getParent()
Get parent of the node. Null, if the node is root.

Returns:
parent of the node, or null if node is root.

getRootNode

public final PoshPlan getRootNode()
Get root node of POSH plan this node belongs to.

Returns:
Root node of POSH plan or null if I am unable to reach it.

moveChild

public abstract boolean moveChild(int newIndex,
                                  PoshElement child)
Move child to the @newIndex. After child was moved (if it was moved), notify listeners.

Returns:
if node succesfully moved

isChildOfParent

protected final boolean isChildOfParent()
Is this element present as a a child in its parent? If element has no parent, return false. Used during adding of a new element as a sanity check (two elements could think that the node is their child).

Returns:
true if element is a child of parent, false if element is not a child of its parent or it has no parent at all (null).

getChildren

public final List<? extends PoshElement> getChildren(LapType selectType)
Get all children of this element that have @selectType.

Parameters:
selectType - Type of children we are looking for.
Returns:
Newly allocated list of all children of this node that have getType() == @selectType.

getChildId

public final int getChildId(PoshElement child)
Get index of a @child. Id is determined as index of @child in all children of same type.


getId

public final int getId()
Get Id of this element.

Throws:
NullPointerException - if parent is null.


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.