001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.uilib.tree;
016:
017: import java.io.Serializable;
018: import java.util.List;
019: import org.araneaframework.OutputData;
020: import org.araneaframework.Widget;
021:
022: /**
023: * Tree node context. General interface that can be used to access current tree
024: * node configuration.
025: *
026: * @author Alar Kvell (alar@araneaframework.org)
027: * @since 1.0.7
028: */
029: public interface TreeNodeContext extends Serializable {
030:
031: /**
032: * Returns if tree node is collapsed (children hidden).
033: */
034: boolean isCollapsed();
035:
036: /**
037: * Sets collapsed state of tree node. If <code>true</code>, child nodes are
038: * hidden, otherwise child nodes are shown. This may trigger removal or
039: * retrieval of child nodes using {@link TreeDataProvider} if
040: * {@link TreeContext#isRemoveChildrenOnCollapse()} is <code>true</code>.
041: */
042: void setCollapsed(boolean collapsed);
043:
044: /**
045: * Inverts collapsed state of tree node, collapsing expanded node and vice
046: * versa.
047: */
048: void toggleCollapsed();
049:
050: /**
051: * Renders tree node and all of its children to specified {@link OutputData}.
052: * Could be called from action listener of tree node display widget.
053: */
054: void renderNode(OutputData data) throws Exception;
055:
056: /**
057: * Returns the number of child nodes this tree node has. The display widget is
058: * not counted as a child node.
059: */
060: int getNodeCount();
061:
062: /**
063: * Adds the given node as the last child node of this tree node.
064: *
065: * @param node
066: * child node to be added.
067: * @return index of the added child node.
068: */
069: int addNode(TreeNodeWidget node);
070:
071: /**
072: * Adds the given node to the specified position. Moves all subsequent nodes
073: * one position further.
074: *
075: * @param index
076: * Position of the added node
077: * @param node
078: * Node to add
079: */
080: void addNode(int index, TreeNodeWidget node);
081:
082: /**
083: * Removes child node at the specified position.
084: *
085: * @param index
086: * Position of the removed node
087: * @return Node that was removed
088: */
089: TreeNodeWidget removeNode(int index);
090:
091: /**
092: * Appends all given nodes to this tree node.
093: *
094: * @param nodes
095: * list of {@link TreeNodeWidget}s to be added.
096: */
097: void addAllNodes(List nodes);
098:
099: /**
100: * Removes all child nodes of this tree node.
101: */
102: void removeAllNodes();
103:
104: /**
105: * Returns the display widget of this tree node. Root node of the tree ({@link TreeWidget})
106: * has no display widget ({@link #getDisplayWidget()} is <code>null</code>).
107: */
108: Widget getDisplayWidget();
109:
110: /**
111: * Returns a child node of this tree node.
112: *
113: * @param index
114: * index of the returned child node.
115: */
116: TreeNodeContext getNode(int index);
117:
118: /**
119: * Returns all child nodes of this tree node.
120: *
121: * @return list of {@link TreeNodeWidget}s.
122: */
123: List getNodes();
124:
125: /**
126: * Returns if this tree node has any child nodes.
127: */
128: boolean hasNodes();
129:
130: /**
131: * Returns how many parent nodes this TreeNodeWidget has. TreeWidget (root
132: * node) has zero parents, it's immediate children have one parent, etc.
133: *
134: * @return number of parents in hierarchy.
135: */
136: int getParentCount();
137:
138: /**
139: * Returns parent node of this tree node or null if called on the root node.
140: */
141: TreeNodeContext getParentNode();
142:
143: /**
144: * Returns the index this node has under its parent.
145: */
146: int getIndex();
147:
148: /**
149: * Returns the full id of this tree node.
150: *
151: * @since 1.1
152: */
153: String getFullId();
154:
155: }
|