1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.custom.tree.model;
20
21 import java.util.Collection;
22
23
24 /**
25 * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
26 * @version $Revision: 472638 $ $Date: 2006-11-08 15:54:13 -0500 (Wed, 08 Nov 2006) $
27 */
28 public interface TreeModel
29 {
30
31 /**
32 * Return the root of the tree.
33 *
34 * @return the root of the tree or null, it this tree has no nodes
35 */
36 public Object getRoot();
37
38
39 /**
40 * Return the child of <code>parent</code> at index <code>index</code>
41 * in the parent's child array.
42 *
43 * @param parent a node in the tree
44 * @return the child of <code>parent</code> at index <code>index</code>
45 */
46 public Object getChild(Object parent, int index);
47
48
49 /**
50 * Answer the number of children of <code>parent</code>.
51 *
52 * @param parent a node in the tree
53 * @return the number of children of the node <code>parent</code>
54 */
55 public int getChildCount(Object parent);
56
57
58 /**
59 * Answer <code>true</code> if <code>node</code> is a leaf.
60 *
61 * @param node a node in the tree
62 * @return true if <code>node</code> is a leaf
63 */
64 public boolean isLeaf(Object node);
65
66
67 /**
68 * Called when the value for the item identified
69 * by <code>path</code> has changed to <code>newValue</code>.
70 * If <code>newValue</code> signifies a truly new value
71 * the model should post a <code>treeNodesChanged</code> event.
72 *
73 * @param path path to the node that has been altered
74 * @param newValue the new value from the TreeCellEditor
75 */
76 public void valueForPathChanged(TreePath path, Object newValue);
77
78
79 /**
80 * Return the index of child in parent.
81 *
82 * @param parent a node in the tree
83 * @param child the node we are interested in
84 * @return the index of the child in the parent, or -1 if either
85 * <code>child</code> or <code>parent</code> are <code>null</code>
86 */
87 public int getIndexOfChild(Object parent, Object child);
88
89
90 /**
91 * Answer the mutable collection of tree model listeners.
92 *
93 * @return Collection
94 */
95 Collection getTreeModelListeners();
96 }