KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > tree > TreeModel


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.formmodel.tree;
17
18 import java.util.Collection JavaDoc;
19
20 /**
21  * Data model for the {@link Tree} widget, inspired by Swing's <code>TreeModel</code>, with
22  * the difference that child nodes are accessed through keys rather than indices.
23  *
24  * @version $Id: TreeModel.java 190962 2005-06-16 17:17:00Z sylvain $
25  */

26 public interface TreeModel {
27
28     /**
29      * Returns the root of the tree. Returns <code>null</code>
30      * only if the tree has no nodes.
31      *
32      * @return the root of the tree
33      */

34     public Object JavaDoc getRoot();
35
36
37     public Collection JavaDoc getChildren(Object JavaDoc parent);
38
39     /**
40      * Returns <code>true</code> if <code>node</code> is a leaf.
41      * It is possible for this method to return <code>false</code>
42      * even if <code>node</code> has no children.
43      * A directory in a filesystem, for example,
44      * may contain no files; the node representing
45      * the directory is not a leaf, but it also has no children.
46      *
47      * @param node a node in the tree, obtained from this data source
48      * @return true if <code>node</code> is a leaf
49      */

50     public boolean isLeaf(Object JavaDoc node);
51
52     public String JavaDoc getChildKey(Object JavaDoc parent, Object JavaDoc child);
53     
54     public Object JavaDoc getChild(Object JavaDoc parent, String JavaDoc key);
55     
56     public Object JavaDoc getNode(TreePath path);
57
58     /**
59      * Adds a listener for the {@link TreeModelEvent} posted after the tree changes.
60      *
61      * @param l the listener to add
62      */

63     void addTreeModelListener(TreeModelListener l);
64
65     /**
66      * Removes a listener previously added with {@link #addTreeModelListener(TreeModelListener)}.
67      *
68      * @param l the listener to remove
69      */

70     void removeTreeModelListener(TreeModelListener l);
71
72 }
73
Popular Tags