org.ceryle.ui.tree
Class TopicTreeModel

java.lang.Object
  extended by org.ceryle.ui.tree.TopicTreeModel
All Implemented Interfaces:
TreeModel

public class TopicTreeModel
extends Object
implements TreeModel

Implements TreeModel as the model used for displaying a set of hierarchical Topics in tree form. Because multiple traversals of a graph may generate different orderings of parent (superclass) or child (subclass) nodes, the generated, ordered lists for each Topic are cached. Clearing the TreeModel or setting the root clears these caches.

Since:
JDK1.4
Version:
$Id: TopicTreeModel.java,v 3.7 2007-06-15 12:09:52 altheim Exp $
Author:
Murray Altheim

Field Summary
protected  int facetMode
          An indicator of whether or not facets should be shown in the generated list, and if so, prior to or after the superclasses or subclasses.
protected  Inferencer m_infer
           
static int NO_FACETS
          An enumerated constant indicating that no facets should be shown in the list.
static int POST_FACETS
          An enumerated constant indicating that facets should be shown after the superclasses or subclasses in the list.
static int PRE_FACETS
          An enumerated constant indicating that facets should be shown prior to superclasses or subclasses in the list.
 
Constructor Summary
TopicTreeModel(List list, Inferencer inferencer, boolean superclasses)
          Constructor for a TopicTreeModel, provided with a List container of initial Topics, an Inferencer (for traversal), and the traversal direction (when superclasses is true, shows superclasses, otherwise subclasses), and defaults to showing no facets (i.e., facetMode is set to NO_FACETS).
TopicTreeModel(List list, Inferencer inferencer, boolean superclasses, int facetMode)
          Constructor for a TopicTreeModel, provided with a List container of initial Topics, an Inferencer (for traversal), the traversal direction (when superclasses is true, shows superclasses, otherwise subclasses), and a facet setting.
 
Method Summary
 void addTreeModelListener(TreeModelListener listener)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 void clearCaches()
          Clears the traversal caches.
protected  void fireTreeStructureChanged(TopicTreeNode oldRoot)
          The only event raised by this model is TreeStructureChanged with the root as path: that is, the whole tree has changed.
 Object getChild(Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
 int getChildCount(Object parent)
          Returns the number of children of parent.
 int getFacetMode()
          Returns the current facet mode.
 int getIndexOfChild(Object parent, Object child)
          Returns the index of child in parent.
 Object getRoot()
          Returns the root of the tree (a TopicTreeNode whose user object is a List containing zero or more Topics).
 List getSubclassesForTopic(Topic topic)
          Returns a Vector-backed List of the subclasses for Topic topic, The result is cached, so that subsequent requests don't require a re-traversal of the graph, and list order remains the same.
 List getSuperclassesForTopic(Topic topic)
          Returns a Vector-backed List of the superclasses for Topic topic, The result is cached, so that subsequent requests don't require a re-traversal of the graph, and list order remains the same.
 boolean isLeaf(Object node)
          Returns true if node is a leaf.
 boolean isRoot(Object o)
          Returns true if Object o is the root of the tree.
 void removeTreeModelListener(TreeModelListener listener)
          Removes a listener previously added with addTreeModelListener().
 void setFacetMode(int mode)
          Sets whether or not facets should be shown in the generated list, and if so, prior to or after the superclasses or subclasses.
 void showRelations(List list, boolean superclasses)
          Used to toggle between show superclass/show subclass mode and to change the root of the tree (when non-null, this also clears the traversal caches).
 void showSubclassesOf(List list)
          Show the subclasses of the List of Topics list (as an Object).
 void showSuperclassesOf(List list)
          Show the superclasses of the List of Topics list (as an Object).
 void valueForPathChanged(TreePath path, Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_FACETS

public static final int NO_FACETS
An enumerated constant indicating that no facets should be shown in the list.

See Also:
Constant Field Values

PRE_FACETS

public static final int PRE_FACETS
An enumerated constant indicating that facets should be shown prior to superclasses or subclasses in the list.

See Also:
Constant Field Values

POST_FACETS

public static final int POST_FACETS
An enumerated constant indicating that facets should be shown after the superclasses or subclasses in the list.

See Also:
Constant Field Values

facetMode

protected int facetMode
An indicator of whether or not facets should be shown in the generated list, and if so, prior to or after the superclasses or subclasses. Permitted values include NO_FACETS, PRE_FACETS (the default), and POST_FACETS.


m_infer

protected Inferencer m_infer
Constructor Detail

TopicTreeModel

public TopicTreeModel(List list,
                      Inferencer inferencer,
                      boolean superclasses)
               throws TopicMapException
Constructor for a TopicTreeModel, provided with a List container of initial Topics, an Inferencer (for traversal), and the traversal direction (when superclasses is true, shows superclasses, otherwise subclasses), and defaults to showing no facets (i.e., facetMode is set to NO_FACETS).

Throws:
TopicMapException

TopicTreeModel

public TopicTreeModel(List list,
                      Inferencer inferencer,
                      boolean superclasses,
                      int facetMode)
               throws TopicMapException
Constructor for a TopicTreeModel, provided with a List container of initial Topics, an Inferencer (for traversal), the traversal direction (when superclasses is true, shows superclasses, otherwise subclasses), and a facet setting. (This defaults to not showing facets if the value is not acceptable, rather than throwing an exception.)

Throws:
TopicMapException
Method Detail

setFacetMode

public void setFacetMode(int mode)
Sets whether or not facets should be shown in the generated list, and if so, prior to or after the superclasses or subclasses. Permitted values include NO_FACETS (no facets), PRE_FACETS (prior to superclasses or subclasses), and POST_FACETS (after superclasses or subclasses). Values outside this range are ignored.


getFacetMode

public int getFacetMode()
Returns the current facet mode.

See Also:
setFacetMode(int)

showSuperclassesOf

public void showSuperclassesOf(List list)
Show the superclasses of the List of Topics list (as an Object). This also clears any existing traversal caches and sets the new root to the parent TopicMap (which is generally not displayed).

This is a convenience method that calls showRelations(List,boolean).


showSubclassesOf

public void showSubclassesOf(List list)
Show the subclasses of the List of Topics list (as an Object). This will set the model's root to the TopicMap origin of the Topics (this is generally not displayed). This also clears any existing traversal caches and sets the new root.

This is a convenience method that calls showRelations(List,boolean).


showRelations

public void showRelations(List list,
                          boolean superclasses)
Used to toggle between show superclass/show subclass mode and to change the root of the tree (when non-null, this also clears the traversal caches). Shows superclasses when superclasses is true, subclasses when false.


fireTreeStructureChanged

protected void fireTreeStructureChanged(TopicTreeNode oldRoot)
The only event raised by this model is TreeStructureChanged with the root as path: that is, the whole tree has changed.


addTreeModelListener

public void addTreeModelListener(TreeModelListener listener)
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface TreeModel

getChild

public Object getChild(Object parent,
                       int index)
Returns the child of parent at index index in the parent's child array.

Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Returns the number of children of parent.

Specified by:
getChildCount in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Returns the index of child in parent.

Specified by:
getIndexOfChild in interface TreeModel

getRoot

public Object getRoot()
Returns the root of the tree (a TopicTreeNode whose user object is a List containing zero or more Topics).

Specified by:
getRoot in interface TreeModel

isRoot

public boolean isRoot(Object o)
Returns true if Object o is the root of the tree.


isLeaf

public boolean isLeaf(Object node)
Returns true if node is a leaf.

Specified by:
isLeaf in interface TreeModel

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener listener)
Removes a listener previously added with addTreeModelListener().

Specified by:
removeTreeModelListener in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. Not used by this model.

Specified by:
valueForPathChanged in interface TreeModel

clearCaches

public void clearCaches()
Clears the traversal caches.


getSuperclassesForTopic

public List getSuperclassesForTopic(Topic topic)
                             throws InferenceException
Returns a Vector-backed List of the superclasses for Topic topic, The result is cached, so that subsequent requests don't require a re-traversal of the graph, and list order remains the same.

Throws:
InferenceException

getSubclassesForTopic

public List getSubclassesForTopic(Topic topic)
                           throws InferenceException
Returns a Vector-backed List of the subclasses for Topic topic, The result is cached, so that subsequent requests don't require a re-traversal of the graph, and list order remains the same.

Throws:
InferenceException


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.