net.sourceforge.java.util.gui.jface.viewers
Class MutableTreeElement

java.lang.Object
  extended bynet.sourceforge.java.util.gui.jface.viewers.MutableTreeElement
All Implemented Interfaces:
IMutableTreeElement, ITreeElement
Direct Known Subclasses:
Category, Favorite, Watch, WatchFolder

public class MutableTreeElement
extends Object
implements IMutableTreeElement

Default IMutableTreeElement implementation which can be used to create and organize hierarchical structures in JFace TreeViewer instances.

Author:
Sebastian Machhausen

Field Summary
private  boolean allowsSubElements
           true to allow, false to disallow sub elements
private  Object data
           The associated data Object
private  List elements
           The elements in a MutableTreeElement
private static ITreeElement[] EMPTY_ELEMENTS
           A predefined empty elements array if a MutableTreeElement does not hold any elements.
private  List eventListener
           The list of registered IMutableTreeElementListener instances.
private  IMutableTreeElement parent
           The parent of a MutableTreeElement
 
Constructor Summary
MutableTreeElement()
           Creates a new MutableTreeElement which is allowed to have sub elements by default.
MutableTreeElement(Object data)
           Creates a new MutableTreeElement associated to the specified data Object which is allowed to have sub elements by default.
MutableTreeElement(Object data, boolean allowsSubElements)
           Creates a new MutableTreeElement associated to the specified data Object and allowing sub elements depending on the given allowsSubElements flag.
 
Method Summary
 void add(IMutableTreeElement element)
           Adds the specified element to this MutableTreeElement.
 void addIMutableTreeElementListener(IMutableTreeElementListener listener)
           Adds the specified IMutableTreeElementListener to the list of registered listeners.
 boolean allowsSubElements()
           Returns true if this MutableTreeElement allows sub elements.
 ITreeElement[] collectLeafs()
           Recursively collects all leafs, i.e.
 void dispose()
           Disposes this MutableTreeElement.
protected  void fireElementAdded(IMutableTreeElement elementAdded)
           Notifies all registered IMutableTreeElementListener instances that the specified element has been added to this MutableTreeElement.
protected  void fireElementRemoved(IMutableTreeElement elementRemoved)
           Notifies all registered IMutableTreeElementListener instances that the specified element has been removed from this MutableTreeElement.
protected  void fireElementUpdated(IMutableTreeElement elementUpdated)
           Notifies all registered IMutableTreeElementListener instances that the specified element has been updated.
 Object getData()
           Gets the data Object associated to this MutableTreeElement.
 ITreeElement getElementAt(int index)
           Returns the IMutableTreeElement at the specified index.
 ITreeElement[] getElements()
           Returns the elements in this MutableTreeElement.
 int getIndex(ITreeElement element)
           Returns the index of the specified element in this MutableTreeElement.
 ITreeElement getParent()
           Returns the parent of this MutableTreeElement.
static String getPath(IMutableTreeElement element)
           Gets a String forming the path from the root to the specified ITreeElement using the > character as path delimiter.
 int getSize()
           Returns the number of elements in this MutableTreeElement.
 boolean hasSubElements()
           Returns true if this MutableTreeElement contains any sub elements.
private  void initializeEventListener()
           Initializes the internal event listener list structure.
 boolean isSubElement(ITreeElement element)
           Returns true if the specified element is a sub element, i.e. a descendant of this MutableTreeElement.
 void remove(IMutableTreeElement element)
           Removes the specified element from this MutableTreeElement.
 void removeIMutableTreeElementListener(IMutableTreeElementListener listener)
           Removes the specified IMutableTreeElementListener from the list of registered listeners.
 void setData(Object data)
           Sets an arbitrary data Object for this MutableTreeElement.
 void setParent(IMutableTreeElement parent)
           Sets this MutableTreeElement's parent to the specified element.
 String toString()
           Gets the textual represntation of this MutableTreeElement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_ELEMENTS

private static final ITreeElement[] EMPTY_ELEMENTS

A predefined empty elements array if a MutableTreeElement does not hold any elements.


elements

private List elements

The elements in a MutableTreeElement


parent

private IMutableTreeElement parent

The parent of a MutableTreeElement


data

private Object data

The associated data Object


allowsSubElements

private boolean allowsSubElements

true to allow, false to disallow sub elements


eventListener

private List eventListener

The list of registered IMutableTreeElementListener instances.

Constructor Detail

MutableTreeElement

public MutableTreeElement()

Creates a new MutableTreeElement which is allowed to have sub elements by default.

See Also:
MutableTreeElement(Object), MutableTreeElement(Object, boolean)

MutableTreeElement

public MutableTreeElement(Object data)

Creates a new MutableTreeElement associated to the specified data Object which is allowed to have sub elements by default.

Parameters:
data - the Object to associate this MutableTreeElement to
See Also:
MutableTreeElement(), MutableTreeElement(Object, boolean)

MutableTreeElement

public MutableTreeElement(Object data,
                          boolean allowsSubElements)

Creates a new MutableTreeElement associated to the specified data Object and allowing sub elements depending on the given allowsSubElements flag.

Parameters:
data - the Object to associate this MutableTreeElement to
allowsSubElements - true to allow, false to disallow sub elements
See Also:
MutableTreeElement(), MutableTreeElement(Object)
Method Detail

toString

public String toString()

Gets the textual represntation of this MutableTreeElement. Delegates to the ToString() method of this MutableTreeElement's data object.

Returns:
the textual representaion of this MutableTreeElement or null if this MutableTreeElement's data object is set to null, i.e. is not available

add

public void add(IMutableTreeElement element)

Adds the specified element to this MutableTreeElement. Notifies all registered IMutableTreeElementListener instances of the add operation. Note that this method has only effect if this MutableTreeElement is allowed to have sub elements, i.e. the allowsSubElements() methods has to return true.

Specified by:
add in interface IMutableTreeElement
Parameters:
element - the IMutableTreeElement to add
See Also:
allowsSubElements()

remove

public void remove(IMutableTreeElement element)

Removes the specified element from this MutableTreeElement. Notifies all registered IMutableTreeElementListener instances of the removal operation. Note that this method has only effect if this MutableTreeElement is allowed to have sub elements, i.e. the allowsSubElements() methods has to return true.

Specified by:
remove in interface IMutableTreeElement
Parameters:
element - the IMutableTreeElement to remove
Throws:
IllegalArgumentException - if element is null or is not an element of this MutableTreeElement
See Also:
allowsSubElements

getElements

public ITreeElement[] getElements()

Returns the elements in this MutableTreeElement.

Specified by:
getElements in interface ITreeElement
Returns:
the elements in this MutableTreeElement; an empty array if this MutableTreeElement does not hold any elements

allowsSubElements

public boolean allowsSubElements()

Returns true if this MutableTreeElement allows sub elements.

Specified by:
allowsSubElements in interface ITreeElement
Returns:
true if sub elements are allowed, false otherwise;

getElementAt

public ITreeElement getElementAt(int index)

Returns the IMutableTreeElement at the specified index.

Specified by:
getElementAt in interface ITreeElement
Parameters:
index - the index to query the IMutableTreeElement for
Returns:
the IMutableTreeElement at the specified index

getSize

public int getSize()

Returns the number of elements in this MutableTreeElement.

Specified by:
getSize in interface ITreeElement
Returns:
the number of elements in this MutableTreeElement

getIndex

public int getIndex(ITreeElement element)

Returns the index of the specified element in this MutableTreeElement.

Specified by:
getIndex in interface ITreeElement
Parameters:
element - the IMutableTreeElement to get the index for
Returns:
the index of the specified element in this MutableTreeElement

getParent

public ITreeElement getParent()

Returns the parent of this MutableTreeElement.

Specified by:
getParent in interface ITreeElement
Returns:
the parent of this MutableTreeElement
See Also:
setParent(IMutableTreeElement)

setParent

public void setParent(IMutableTreeElement parent)

Sets this MutableTreeElement's parent to the specified element.

Specified by:
setParent in interface IMutableTreeElement
Parameters:
parent - the new parent to set for this MutableTreeElement
See Also:
getParent()

hasSubElements

public boolean hasSubElements()

Returns true if this MutableTreeElement contains any sub elements.

Specified by:
hasSubElements in interface ITreeElement
Returns:
true if this MutableTreeElement has any sub elements; false otherwise

setData

public void setData(Object data)

Sets an arbitrary data Object for this MutableTreeElement.

Specified by:
setData in interface IMutableTreeElement
Parameters:
data - the Object to associate this MutableTreeElement to
See Also:
getData()

getData

public Object getData()

Gets the data Object associated to this MutableTreeElement.

Specified by:
getData in interface IMutableTreeElement
Returns:
the data Object associated to this MutableTreeElement
See Also:
setData(Object)

isSubElement

public boolean isSubElement(ITreeElement element)

Returns true if the specified element is a sub element, i.e. a descendant of this MutableTreeElement.

Specified by:
isSubElement in interface ITreeElement
Parameters:
element - the element for which to test the posterity
Returns:
true if the specified element is a sub element, i.e. a descendant of this MutableTreeElement; false otherwise

collectLeafs

public ITreeElement[] collectLeafs()

Recursively collects all leafs, i.e. IMutableTreeElements that do not have any sub elements, starting at this MutableTreeElement.

Returns:
the collected leafs

addIMutableTreeElementListener

public void addIMutableTreeElementListener(IMutableTreeElementListener listener)

Adds the specified IMutableTreeElementListener to the list of registered listeners.

Specified by:
addIMutableTreeElementListener in interface IMutableTreeElement
Parameters:
listener - the listener to add
See Also:
removeIMutableTreeElementListener(IMutableTreeElementListener)

removeIMutableTreeElementListener

public void removeIMutableTreeElementListener(IMutableTreeElementListener listener)

Removes the specified IMutableTreeElementListener from the list of registered listeners.

Specified by:
removeIMutableTreeElementListener in interface IMutableTreeElement
Parameters:
listener - the listener to remove
See Also:
addIMutableTreeElementListener(IMutableTreeElementListener)

dispose

public void dispose()

Disposes this MutableTreeElement.

Specified by:
dispose in interface IMutableTreeElement

getPath

public static String getPath(IMutableTreeElement element)

Gets a String forming the path from the root to the specified ITreeElement using the > character as path delimiter.

Parameters:
element - the ITreeElement to get the path for
Returns:
the path for the specified ITreeElement

fireElementAdded

protected void fireElementAdded(IMutableTreeElement elementAdded)

Notifies all registered IMutableTreeElementListener instances that the specified element has been added to this MutableTreeElement.

Parameters:
elementAdded - the element that was added to this MutableTreeElement

fireElementRemoved

protected void fireElementRemoved(IMutableTreeElement elementRemoved)

Notifies all registered IMutableTreeElementListener instances that the specified element has been removed from this MutableTreeElement.

Parameters:
elementRemoved - the element that was removed from this MutableTreeElement

fireElementUpdated

protected void fireElementUpdated(IMutableTreeElement elementUpdated)

Notifies all registered IMutableTreeElementListener instances that the specified element has been updated.

Parameters:
elementUpdated - the element that was updated

initializeEventListener

private void initializeEventListener()

Initializes the internal event listener list structure.