Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-discussion] LazyTreeRoot constructor

Tania Tudorache tudorache at stanford.edu
Wed Feb 21 10:24:22 PST 2007


Hi Philip,

The LazyTreeRoot/Node is a very useful tree component that is used by 
almost any tree in Protege, but which unfortunately does not have too 
much documentation :) So I will try to explain how it works.

As an idea, you can look at the implementation of ParentChildRoot and 
ParentChildNode, which is pretty straightforward (you can ignore all the 
listeners code).

So, the most important feature of LazyTree-s is that they don't load the 
whole tree at once, but load the children of a node only at request. 
This is very useful, especially, if you have large ontologies. For 
example, the class tree loads its children only when you open a node. 
The children of a node are the subclasses of the user object of that 
node, so the subclasses of a class are requested from the knowledge base 
only when you open the node.

So, to implement a LazyTree, let's call it MyLazyTree, you need to 
create two classes, MyLazyTreeRoot and MyLazyTreeNode which extend 
LazyTreeRoot and LazyTreeNode, respectively.

To build a tree, you need to call:

JTree myTree = new JTree(MyLazyTreeRoot(someRootObject));

The user objects of MyLazyTree can be anything. Usually, they are 
frames, but they can also be Strings or anything else.

The "someRootObject" can be anything (for example a Frame) that is the 
user object of the root of your tree.

There are some methods that are invoked for a LazyTree: 
getChildObjectCount() which is called to check whether a "+" sign should 
be added in front of a node (if it has more than 0 children) and the 
getChildObjects() which is called when the user actually opens a tree node.

So, if you implement only the abstract methods of LazyTreeNode/Root, 
your tree should work :)

Usually the constructor of the root, looks something like:

    protected MyLazyTreeRoot(Collection roots) {   
        super(roots);
    }
   
    public MyLazyTreeRoot(Frame root) {
        super(root);
    }

    @Override
    protected LazyTreeNode createNode(Object o) {
        return new MyLazyTreeNode(this, (Frame) o);
    }


In the last method, instead of casting "o" to a Frame, you can cast it 
to whatever your tree needs to show. Or, you don't cast it, and handle 
the object in the constructor of MyLazyTreeNode.

Probably if you look at the implementation of ParentChildRoot and 
ParentChildNode you will quickly see how to customize your tree.

I hope I didn't make things more unclear than at the beginning :)

Tania




Philip Ogren wrote:
> I am trying to understand how the LazyTree* classes work and am puzzled 
> by the constructor for LazyTreeRoot.  When it is called the object that 
> is passed in is immediately put into a collection and then passed on to 
> the super constructor.  The super constructor, LazyTreeNode, takes the 
> object - which is a collection - and sets the _userObject to this 
> collection.  I would think _userObject would typically be a Frame and 
> when I look at references to LazyTreeNode.getUserObject() the callers 
> always cast the object to a Frame.  How can this be? 
>
> The only place where _userObject gets set other than the constructor is 
> in reload(Object) method (it is a private member variable -so I don't 
> think it can get set outside of LazyTreeNode.)  But reload(Object) is 
> only called in a couple of places and does not seem to account for how 
> ReferenceNode can cast LazyTreeNode.getUserObject() into a Frame. 
>
> Any thoughts on this?  I must be reading the code wrong because all of 
> it seems to work when you run it - any pointers you can provide to help 
> me understand this clearly would be appreciated.  I would very much like 
> to understand how this works so that I can extend this code for my own 
> purposes. 
>
> Thanks,
> Philip
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
>
>   




More information about the protege-discussion mailing list