01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel.tree;
18:
19: import java.util.Collection;
20:
21: /**
22: * Data model for the {@link Tree} widget, inspired by Swing's <code>TreeModel</code>, with
23: * the difference that child nodes are accessed through keys rather than indices.
24: *
25: * @version $Id: TreeModel.java 449149 2006-09-23 03:58:05Z crossley $
26: */
27: public interface TreeModel {
28:
29: /**
30: * Returns the root of the tree. Returns <code>null</code>
31: * only if the tree has no nodes.
32: *
33: * @return the root of the tree
34: */
35: public Object getRoot();
36:
37: public Collection getChildren(Object 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 node);
51:
52: public String getChildKey(Object parent, Object child);
53:
54: public Object getChild(Object parent, String key);
55:
56: public Object 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: }
|