DisclosureIcon on empty branches in Tree
Hello,
I'm trying to display XML data in a tree. Because of the way
the XML looks, I needed to write a custom data descriptor (I'll
explain the XML structure at the end of the post) with custom
hasChildren and
isBranch methods.
Now I've got the problem that everything works fine, but
empty branches will still have the disclosure icon displayed. So
apparently the data passed to the default itemRenderer is not
"delivered" by the data descriptor - or the data descriptor
delivers something to the renderer in a way that's incorrect.
Either way, the TreeItemRenderer will show
_listData.hasChildren to be true, while the data
descriptor's
hasChildren will show it to be false.
Assuming the data descriptor is okay, is there any way to
access the original XML from within a custom treeItemRenderer so
that I can "check for children myself"?
(on a second issue, I would also need to display a specific
image with each tree leaf, depending on how an XML attribute of the
leaf is set - similar to the Windows Explorer showing different
icons for different file types - again, this would only work if I
had access to the XML structure from within the renderer)
Any help is much appreciated,
cheers,
Fabian
XML Structure:
Branches and Leaves are both received as <folder> tags.
Both leaves and branches can have <property> tags, which are
not to be displayed. The only difference between a branch and a
leaf is that the leaves have a <property
name='url'>url</property> tag, while the branches do not
have property tags with a "name" attribute set to "url".
Example:
<folder id="thisIsTheRootFolder>
<property name="someProp">someValue</property>
/not to be displayed at all
<folder id="firstSubfolder">
/this should be an empty subfolder
<property
name="someOtherProp">someOtherValue</property>
</folder>
<folder id="secondSubfolder">
<folder id="thisIsALeaf">
<property name="url">
http://www.adobe.com</property>
</folder>
</folder>
</folder>
Nodes of the tree are represented by the TreeDataProvider
control. For each node in the tree, the TreeDataProvider control
can define the following properties:
data - The data to associate with a node, if any.
label - The text to be displayed in the Tree for a node.
isBranch - If true, the node is a branch: if false, it is not
a branch. If not specified, the Tree control determines if the node
is a branch based on whether it contains any child nodes.
Similar Messages
-
Hello,
The problem I'm having is how to empty a binary tree. Here is my code for MyBinaryTree:
public class MyBinaryTree implements BinaryTree {
private BinaryTreeNode root;
protected static int numNodes;
private static String tree = "";
* Constructor that creates a binary tree with a root.
* @param r The root node
* @param num The number of nodes
public MyBinaryTree(BinaryTreeNode r, int num) {
root = r;
numNodes = num;
* Method to make the binary tree empty.
public void makeEmpty() {
root.left = null;
root.right = null;
root = new BinaryTreeNode(null,null,null,null,null);
numNodes = 0;
* Method to make a root with key k and element el.
* @param k The key of the root
* @param el The element in the root
public void makeRoot(Comparable k, Object el) {
root = new BinaryTreeNode(k,el);
numNodes++;
* Method to return the root of the binary tree.
* @return The root of the tree
public BinaryTreeNode root() {
return root;
* Method to return the left child of a node.
* @param node The node whose left child is wanted.
* @return The left child of the node
* @see NoNodeException
public BinaryTreeNode leftChild(BinaryTreeNode node) throws NoNodeException {
if (node.left == null) throw new NoNodeException("No left child!");
else return node.leftChild();
* Method to set the left child of node "node".
* @param node The node to be given a left child
* @param child The node to be set as left child
public void setLeftChild(BinaryTreeNode node, BinaryTreeNode child) {
node.setLeftChild(child);
numNodes++;
* Method to return the right child of a node.
* @param node The node whose right child is wanted.
* @return The right child of the node
* @see NoNodeException
public BinaryTreeNode rightChild(BinaryTreeNode node) throws NoNodeException{
if (node.right == null) throw new NoNodeException("No right child!");
else return node.rightChild();
* Method to set the right child of node "node".
* @param node The node to be given a right child
* @param child The node to be set as right child
public void setRightChild(BinaryTreeNode node, BinaryTreeNode child) {
node.setRightChild(child);
numNodes++;
* Method to return the parent of a node.
* @param node The node whose parent is wanted.
* @return The parent of the node
* @see NoNodeException
public BinaryTreeNode parent(BinaryTreeNode node) throws NoNodeException {
if (node.p == null) throw new NoNodeException("No parent!");
else return node.parent();
* Method to set the parent of node "node".
* @param node The node to be given a parent
* @param pt The node to be set as parent
public void setparent(BinaryTreeNode node, BinaryTreeNode pt) {
node.setParent(pt);
numNodes++;
* Method to return the key of the specified node.
* @param node The node with the key to be returned
* @return The key of the node
public Comparable getKey(BinaryTreeNode node) {
return node.getKey();
* Method to set the key of the specified node.
* @param node The node for which the key will be set.
* @param k The key to be set.
public void setKey(BinaryTreeNode node, Comparable k) {
node.setKey(k);
* Method to get the element in the specified node.
* @param node The node with the element to be returned.
* @return The element in the node.
public Object getElement(BinaryTreeNode node) {
return node.getElement();
* Method to put an element into the specified node.
* @param node The node that will have an element put in it.
* @param o The element to be inserted.
public void setElement(BinaryTreeNode node, Object o) {
node.setElement(o);
* Method to add a left child to the specified node.
* @param theNode The node that the left child will be added to.
* @param k The key associated with the left child.
* @param el The element in the left child.
public void addLeftChild (BinaryTreeNode theNode, Comparable k, Object el) {
BinaryTreeNode temp = new BinaryTreeNode(k,el);
temp.setParent(theNode);
theNode.setLeftChild(temp);
numNodes++;
* Method to add a right child to the specified node.
* @param theNode The node that the right child will be added to.
* @param k The key associated with the right child.
* @param el The element in the right child.
public void addRightChild (BinaryTreeNode theNode, Comparable k, Object el) {
BinaryTreeNode temp = new BinaryTreeNode(k,el);
temp.setParent(theNode);
theNode.setRightChild(temp);
numNodes++;
* Method to remove the left child of the specified node.
* @param theNode The node which the left child will be removed.
public void removeLeftChild(BinaryTreeNode theNode) {
((BinaryTreeNode)(theNode.left)).p = null;
theNode.left = null;
numNodes--;
* Method to remove the right child of the specified node.
* @param theNode The node which the right child will be removed.
public void removeRightChild(BinaryTreeNode theNode) {
((BinaryTreeNode)(theNode.right)).p = null;
theNode.right = null;
numNodes--;
* Private method to perform an inorder traversal on the tree.
* @param t A MyBinaryTree object
* @param n The starting node.
private static String inorderPrint(MyBinaryTree t, BinaryTreeNode n) {
String spaces = "";
for (int i = 0; i < (numNodes - 1)/2; i++) spaces += " ";
if (n.left != null || n.right != null) inorderPrint(t,t.leftChild(n));
tree += spaces + n.getElement();
if (n.left != null || n.right != null) inorderPrint(t,t.rightChild(n));
return tree;
* Private method to perform an inorder traversal on the tree.
* @param t A MyBinaryTree object
* @param n The starting node.
* @param pos The current position in the tree.
* @return A tree with an asterix beside the current position
private static String inorderPrint2(MyBinaryTree t, BinaryTreeNode n,
BinaryTreeNode pos) {
String spaces = "";
for (int i = 0; i < (numNodes - 1)/2; i++) spaces += " ";
if (n.left != null || n.right != null) inorderPrint2(t,t.leftChild(n),pos);
if (n.getElement() == pos.getElement()) tree += spaces + n.getElement() + "*";
else tree += spaces + n.getElement();
if (n.left != null || n.right != null) inorderPrint2(t,t.rightChild(n),pos);
return tree;
* Method to return a String representation of the binary tree.
* @return String representation of the binary tree
public String toString() {
if (root.getElement() == null) return "*** Tree is empty ***";
else {
MyBinaryTree temp = new MyBinaryTree(root,numNodes);
return inorderPrint(temp,root);
* Method to return a String of the binary tree with an asterix beside the
* current position.
* @param currentPosition The current position.
* @return A String of the tree with an asterix by the current position
public String toString(BinaryTreeNode currentPosition) {
if (root.getElement() == null) return "*** Tree is empty ***";
else {
MyBinaryTree temp = new MyBinaryTree(root,numNodes);
return inorderPrint2(temp,root,currentPosition);
}Those are all the methods I'm allowed to have. When I run makeEmpty, it seems to work, but then if I do makeRoot, the old tree prints again. It's quite bizarre. Any tips on how to empty the tree correctly?Here is the BinaryTreeNode code.
public class BinaryTreeNode {
// Instance variables (Note: they are all "private")
protected Comparable key; // The key at this node
protected Object element; // The data at this node
protected BinaryTreeNode left; // Left child
protected BinaryTreeNode right; // Right child
protected BinaryTreeNode p; // The Parent
// Constructors
BinaryTreeNode( Comparable theKey, Object theElement, BinaryTreeNode lt,
BinaryTreeNode rt, BinaryTreeNode pt ) {
key = theKey;
element = theElement;
left = lt;
right = rt;
p = pt;
BinaryTreeNode( Comparable theKey, Object theElement) {
key = theKey;
element = theElement;
left = null;
right = null;
p = null;
// return the key attached to this node
public Comparable getKey() {
return key;
// set the key attached to this node to be Comparable k
public void setKey(Comparable k) {
key = k;
// return the element attached to this node
public Object getElement() {
return element;
// set the element attached to this node to be Object o
public void setElement(Object o) {
element = o;
// return left child
public BinaryTreeNode leftChild() {
return left;
// set left child to be node n
public void setLeftChild(BinaryTreeNode n) {
left = n;
// return right child
public BinaryTreeNode rightChild() {
return right;
// set right child to be node n
public void setRightChild(BinaryTreeNode n) {
right = n;
// return parent
public BinaryTreeNode parent() {
return p;
// set parent to be node n
public void setParent(BinaryTreeNode n) {
p = n;
} -
Hi..All!
I am using tree controll. I want to allow user to add item to
seleceted node runtime.
I m using a button to add or remove child. On clicking of add
button child should be added to selected node.
Thanks In advance
VishalThank you for you answer. I have a custom repository with no Taxanomy table.
May be that's why the "Add Branch" option was disabled.
Now the question is, Why do you need to have a Taxonomy to enable the "Add branch" feature?
Here is my scenario:
I want to run series of Assignments.
I defined 5 assignments. Thought that I can use MDM Workflow to call them in series. However MDM Workflow does not let me connect one Assignmen Task to next Assignment Task. So though Branched Assignment would be helpful.
However looks like can not use "Add Branch" to assignment to run them in series.
May be I will put a new post.
Abhay -
Several branches in tree control binding. How?
I have set up a tree control binding which represents a master-detail relationship between two database-tables in my ADF-application.
In my JSP i show all rows from the "customer" table and all related "order" rows for that customer. It looks like this:
Customer1
- Order 1
- Order 2
- Order 3
Customer2
- Order 1
Customer3
- Order 1
- Order 2
This works very well, but now I need to add a new detail-table to this relationship; For every customer I want to show all orders and all documents related to that customer. The result should be something like this:
Customer1
- Order 1
- Order 2
- Order 3
- Document 1
Customer2
- Order 1
- Document 1
- Document 2
Customer3
- Order 1
- Order 2
- Document 1
- Document 2
- Document 3
Is there a way to set up a tree binding with one root and several branches? I need to have them in the same binding because I only want to loop the root-nodes once. I tried to add another rule to my existing tree binding, but how can I refer to which children I want to display in my jsp code (i.e orders or customers)? I loop through my rootnodes with the following code:
<c:forEach var="Row" items="${bindings.DCTree.rootNodeBinding.children}">
How can I refer to my "orders"-children og "documents" children in order to choose which branch to loop?
A bit difficult to explain my problem, but I hope anyone can help me out!
Thanx
TomRepost
-
How to make a rectangle at say 75 degrees to simulate as branch of a tree
I am making a game, I need to make a tree with branches with which, leaves can be attached. I am using rectangle as trunk of tree. What I want now is to use rectangles as branches of tree. I need to make rectangle like structure that is biased to say 75 degrees & attach it with trunk.
How to make a rectangle that is biased to 75 degree OR is there any other object in java that I can use for this purpose.
Thanks a lot for any help.Darryl.Burke wrote:
AffineTransform#createTransformedShape
dbarr db, thankya. I was looking for that one. -
Can't remove a node from a tree
I am using the custom tree dataDescriptor provided in Flex live
doc. It works for creating the tree and add notes, however when I
try to remove a node from the tree it cant work. Does anyone have
any idea?
This is the code for MyCustomeTreeDataDescriptor.as
package
import mx.collections.ArrayCollection;
import mx.collections.CursorBookmark;
import mx.collections.ICollectionView;
import mx.collections.IViewCursor;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
import mx.controls.treeClasses.*;
public class MyCustomTreeDataDescriptor implements
ITreeDataDescriptor
// The getChildren method requires the node to be an Object
// with a children field.
// If the field contains an ArrayCollection, it returns the
field
// Otherwise, it wraps the field in an ArrayCollection.
public function getChildren(node:Object,
model:Object=null):ICollectionView
try
if (node is Object) {
if(node.children is ArrayCollection){
return node.children;
}else{
return new ArrayCollection(node.children);
catch (e:Error) {
trace("[Descriptor] exception checking for getChildren");
return null;
// The isBranch method simply returns true if the node is an
// Object with a children field.
// It does not support empty branches, but does support null
children
// fields.
public function isBranch(node:Object,
model:Object=null):Boolean {
try {
if (node is Object) {
if (node.children != null) {
return true;
catch (e:Error) {
trace("[Descriptor] exception checking for isBranch");
return false;
// The hasChildren method Returns true if the node actually
has children.
public function hasChildren(node:Object,
model:Object=null):Boolean {
if (node == null)
return false;
var children:ICollectionView = getChildren(node, model);
try {
if (children.length > 0)
return true;
catch (e:Error) {
return false;
// The getData method simply returns the node as an Object.
public function getData(node:Object,
model:Object=null):Object {
try {
return node;
catch (e:Error) {
return null;
// The addChildAt method does the following:
// If the parent parameter is null or undefined, inserts
// the child parameter as the first child of the model
parameter.
// If the parent parameter is an Object and has a children
field,
// adds the child parameter to it at the index parameter
location.
// It does not add a child to a terminal node if it does not
have
// a children field.
public function addChildAt(parent:Object, child:Object,
index:int,
model:Object=null):Boolean {
var event:CollectionEvent = new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
event.kind = CollectionEventKind.ADD;
event.items = [child];
event.location = index;
if (!parent) {
var iterator:IViewCursor = model.createCursor();
iterator.seek(CursorBookmark.FIRST, index);
iterator.insert(child);
else if (parent is Object) {
if (parent.children != null) {
if(parent.children is ArrayCollection) {
parent.children.addItemAt(child, index);
if (model){
model.dispatchEvent(event);
model.itemUpdated(parent);
return true;
else {
parent.children.splice(index, 0, child);
if (model)
model.dispatchEvent(event);
return true;
return false;
// The removeChildAt method does the following:
// If the parent parameter is null or undefined, removes
// the child at the specified index in the model.
// If the parent parameter is an Object and has a children
field,
// removes the child at the index parameter location in the
parent.
public function removeChildAt(parent:Object, child:Object,
index:int, model:Object=null):Boolean
var event:CollectionEvent = new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
event.kind = CollectionEventKind.REMOVE;
event.items = [child];
event.location = index;
//handle top level where there is no parent
if (!parent)
var iterator:IViewCursor = model.createCursor();
iterator.seek(CursorBookmark.FIRST, index);
iterator.remove();
if (model)
model.dispatchEvent(event);
return true;
else if (parent is Object)
if (parent.children != undefined)
parent.children.splice(index, 1);
if (model)
model.dispatchEvent(event);
return true;
return false;
This is my tree definition:
<mx:Tree width="143" top="0" bottom="0" left="0"
height="100%"
id="publicCaseTree"
dataDescriptor="{new MyCustomTreeDataDescriptor()}"
dataProvider="{ac}"
defaultLeafIcon="@Embed('assets/caseIcon.png')"
change="publicTreeChanged(event)"
dragEnabled="true"
dragMoveEnabled="false"/>
This is how I remove the selected node from the tree. When
Delete button is clicked, the doDeleteCase function is
exectuted.
public function publicTreeChanged(event:Event):void {
selectedNode =
publicCaseTree.dataDescriptor.getData(Tree(event.target).selectedItem,
ac);
public function doDeleteCase(event:Event):void{
publicCaseTree.dataDescriptor.removeChildAt(publicCaseTree.firstVisibleItem,
selectedNode, 0, ac);
Any help would be appreciated.Thanks.Finally I removed nodes from tree, but not sure I did in the
right way. Anybody encounter the same problem, please
discuss. -
Hi,
I'm trying to compile an example from the documentation:
I have two files :
treeEx1.mxml
<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
creationComplete="initCollections()">
<mx:Script>
<![CDATA[
import mx.collections.*;
import mx.controls.treeClasses.*;
import customComp.MyCustomTreeDataDescriptor;
//Variables used to construct the ArrayCollection data
provider
//First top-level node and its children.
public var nestArray1:Object = [
{label:"item1", children: [
{label:"item1 child", children: [
{label:"item 1 child child", data:"child data"}
//Second top-level node and its children.
public var nestArray2:Object = [
{label:"item2", children: [
{label:"item2 child", children: [
{label:"item 2 child child", data:"child data"}
//Second top-level node and its children.
public var nestArray3:Object = [
{label:"item3", children: [
{label:"item3 child", children: [
{label:"item 3 child child", data:"child data"}
//Variable for the tree array.
public var treeArray:Object
//Variables for the three Array collections that correspond
to the
//top-level nodes.
public var col1:ArrayCollection;
public var col2:ArrayCollection;
public var col3:ArrayCollection;
//Variable for the ArrayCollection used as the Tree data
provider.
[Bindable]
public var ac:ArrayCollection;
//build the ac ArrayCollection from its parts.
public function initCollections():void{
// Wrap each top-level node in an ArrayCollection.
col1 = new ArrayCollection(nestArray1);
col2 = new ArrayCollection(nestArray2);
col3 = new ArrayCollection(nestArray3);
// Put the three top-level node ArrayCollections in the
treeArray.
treeArray = [
{label:"first thing", children: col1},
{label:"second thing", children: col2},
{label:"third thing", children: col3},
//Wrap the treeArray in an ArrayCollection.
ac = new ArrayCollection(treeArray);
// Adds a child node as the first child of the selected
node,
// if any. The default selectedNode is null, which causes
the
// data descriptor addChild method to add it as the first
child
// of the ac ArrayCollection.
public function clickAddChildren():void {
var newChild:Object = new Object();
newChild.label = "New Child";
newChild.children = new ArrayCollection();
tree.treeDataDescriptor.addChildAt(tree.selectedNode,
newChild, 0, ac);
]]>
</mx:Script>
<mx:Tree width="200" id="tree" dataProvider="{ac}"
treeDataDescriptor="{new MyCustomTreeDataDescriptor()}"/>
<mx:Button label="add children"
click="clickAddChildren()"/>
</mx:Application>
and
and MyCustomTreeDataDescriptor.as :
package customComp.MyCustomTreeDataDescriptor
import mx.collections.ICollectionView;
import mx.collections.IViewCursor;
import mx.events.TreeModelChangedEvent;
import mx.events.TreeModelChangedEventDetail;
import mx.controls.treeClasses.*;
public class MyCustomTreeDataDescriptor implements
ITreeDataDescriptor
// The getChildren method requires the node to be an Object
// with a children field.
// If the field contains an ArrayCollection, it returns the
field
// Otherwise, it wraps the field in an ArrayCollection.
public function getChildren(node:Object,
model:Object=null):ICollectionView
try
if (node is Object)
if(node.children is ArrayCollection){
return node.children;
}else{
return new ArrayCollection(node.children);
catch (e:Error)
trace("[Descriptor] exception checking for getChildren");
return null;
// The isBranch method simply returns true if the node is an
// Object with a children field.
// It does not support empty branches, but does support null
children
// fields.
public function isBranch(node:Object,
model:Object=null):Boolean
try
if (node is Object)
if (node.children != null)
return true;
catch (e:Error)
trace("[Descriptor] exception checking for isBranch");
return false;
// The getData method simply returns the node as an Object.
public function getData(node:Object,
model:Object=null):Object
try
return Object(node);
catch (e:Error)
return null;
// The addChildAt method does the following:
// If the node parameter is null or undefined, inserts
// the child parameter as the first child of the model
parameter.
// If the node parameter is an Object and has a children
field,
// adds the child parameter to it at the index parameter
location.
// It does not add a child to a terminal node if it does not
have
// a children field.
public function addChildAt(node:Object, child:Object,
index:int, model:Object=null):Boolean
var event:TreeModelChangedEvent = new
TreeModelChangedEvent("modelChanged", false, false,
TreeModelChangedEventDetail.ADD_NODE, child, node, index);
if (!node)
var iterator:IViewCursor = model.createCursor();
iterator.seek(CursorBookmark.FIRST, index);
iterator.insert(child);
else if (node is Object)
if (node.children != null)
if(node.children is ArrayCollection) {
node.children.addItemAt(child, index);
if (model){
model.dispatchEvent(event);
model.itemUpdated(node);
return true;
else {
node.children.splice(index, 0, child);
if (model)
model.dispatchEvent(event);
return true;
return false;
I have read the docs and looked through some example on this
form but I still can't figure it out .
Thanks
The code above is from:
http://127.0.0.1:56812/help/topic/com.adobe.flexbuilder.help/html/Part2_DevApps.html
Using hierarchical data providersI hav echnaged it and now I get :
A file found in an source-path must have the same package
structure 'customComp', as the definition's package,
'customComp.MyCustomTreeDataDescriptor'.
I tried different variations but nothing seems to work. I
have the following folder structure:
\Lessons
\customComp
.MyCustomTreeDataDescriptor.as
treeEx1.mxml
Thanks -
Listing File Hierarchy in console using a Tree structure
first off i'm a college student. i'm not that good at java... we got this CA in class and try as i might i just can't get my head around it
i was wondering if someone who know a bit more about java then i do would point me in the right direction, were i'm going wrong in my code
i have to list out sub-files and sub-directorys of a folder (i.e. C:/test) to console using tree structure
like this
startingdir
dir1 //subfolder of startingdir
dir11 //subfolder of dir1
dir111 //subfolder of dir11
dir12 //subfolder of dir1
file1A // document on dir1
dir2 //subfolder of startingdir
Tree.java
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Deque;
public class Tree<E> {
// Each Tree object is an unordered tree whose
// elements are arbitrary objects of type E.
// This tree is represented by a reference to its root node (root), which
// is null if the tree is empty. Each tree node contains a link to its
// parent and a LinkedList of child nodes
private Node root;
//////////// Constructor ////////////
public Tree () {
// Construct a tree, initially empty.
root = null;
//////////// Accessors ////////////
public boolean isEmpty () {
// Return true is and only if this tree is empty.
return (root == null);
public Node root () {
// Return the root node of this tree, or null if this tree is empty.
return root;
public Node parent (Node node) {
// Return the parent of node in this tree, or null if node is the root node.
return node.parent;
public void makeRoot (E elem) {
// Make this tree consist of just a root node containing element elem.
root = new Node(elem);
public Node addChild (Node node, E elem) {
// Add a new node containing element elem as a child of node in this
// tree. The new node has no children of its own. Return the node
// just added.
Node newChild = new Node(elem);
newChild.parent = node;
node.children.addLast(newChild);
return newChild;
public E element (Node node) {
return node.getElement();
//////////// Iterators ////////////
public Iterator childrenIterator (Node node) {
return node.children.iterator();
public Iterator nodesPreOrder () {
// Return an iterator that visits all nodes of this tree, with a pre-order
// traversal.
return new Tree.PreOrderIterator();
//////////// Inner classes ////////////
public class Node {
// Each Tree.Node object is a node of an
// unordered tree, and contains a single element.
// This tree node consists of an element (element),
// a link to its parent
// and a LinkedList of its children
private E element;
private Node parent;
private LinkedList<Node> children;
private Node (E elem) {
// Construct a tree node, containing element elem, that has no
// children and no parent.
this.element = elem;
this.parent = null;
children = new LinkedList<Node>();
public E getElement () {
// Return the element contained in this node.
return this.element;
public String toString () {
// Convert this tree node and all its children to a string.
String children = "";
// write code here to add all children
return element.toString() + children;
public void setElement (E elem) {
// Change the element contained in this node to be elem.
this.element = elem;
public class PreOrderIterator implements Iterator {
private Deque<Node> track; //Java recommends using Deque rather
// than Stack. This is used to store sequence of nomempty subtrees still
//to be visited
private PreOrderIterator () {
track = new LinkedList();
if (root != null)
track.addFirst(root);
public boolean hasNext () {
return (! track.isEmpty());
public E next () {
Node place = track.removeFirst();
//stack the children in reverse order
if (!place.children.isEmpty()) {
int size = place.children.size(); //number of children
ListIterator<Node> lIter =
place.children.listIterator(size); //start iterator at last child
while (lIter.hasPrevious()) {
Node element = lIter.previous();
track.addFirst(element);
return place.element;
public void remove () {
throw new UnsupportedOperationException();
FileHierarchy.java
import java.io.File;
import java.util.Iterator;
public class FileHierarchy {
// Each FileHierarchy object describes a hierarchical collection of
// documents and folders, in which a folder may contain any number of
// documents and other folders. Within a given folder, all documents and
// folders have different names.
// This file hierarchy is represented by a tree, fileTree, whose elements
// are Descriptor objects.
private Tree fileTree;
//////////// Constructor ////////////
public FileHierarchy (String startingDir, int level) {
// Construct a file hierarchy with level levels, starting at
// startingDir
// Can initially ignore level and construct as many levels as exist
fileTree = new Tree();
Descriptor descr = new Descriptor(startingDir, true);
fileTree.makeRoot(descr);
int currentLevel = 0;
int maxLevel = level;
addSubDirs(fileTree.root(), currentLevel, maxLevel);
//////////// File hierarchy operations ////////////
private void addSubDirs(Tree.Node currentNode, int currentLevel,
int maxLevel) {
// get name of directory in currentNode
// then find its subdirectories (can add files later)
// for each subdirectory:
// add it to children of currentNode - call addChild method of Tree
// call this method recursively on each child node representing a subdir
// can initially ignore currentLevel and maxLevel
Descriptor descr = (Descriptor) currentNode.getElement();
File f = new File(descr.name);
File[] list = f.listFiles();
for (int i = 0; i < list.length; ++i) {
if (list.isDirectory()) {
File[] listx = null;
fileTree.addChild(currentNode, i);
if (list[i].list().length != 0) {
listx = list[1].listFiles();
addSubDirs(currentNode,i,1);
} else if (list[i].isFile()) {
fileTree.addChild(currentNode, i);
// The following code is sample code to illustrate how File class is
// used to get a list of subdirectories from a starting directory
// list now contains subdirs and files
// contained in dir descr.name
////////// Inner class for document/folder descriptors. //////////
private static class Descriptor {
// Each Descriptor object describes a document or folder.
private String name;
private boolean isFolder;
private Descriptor (String name, boolean isFolder) {
this.name = name;
this.isFolder = isFolder;
FileHierarchyTest.javapublic class FileHierarchyTest {
private static Tree fileTree;
public static void main(String[] args) {
FileHierarchy test = new FileHierarchy ("//test", 1);
System.out.println(test.toString());Denis,
Do you have [red hair|http://www.dennisthemenace.com/]? ;-)
My advise with the tree structure is pretty short and sweet... make each node remember
1. it's parent
2. it's children
That's how the file system (inode) actually works.
<quote>
The exact reasoning for designating these as "i" nodes is unsure. When asked, Unix pioneer Dennis Ritchie replied:[citation needed]
In truth, I don't know either. It was just a term that we started to use. "Index" is my best guess, because of the
slightly unusual file system structure that stored the access information of files as a flat array on the disk, with all
the hierarchical directory information living aside from this. Thus the i-number is an index in this array, the
i-node is the selected element of the array. (The "i-" notation was used in the 1st edition manual; its hyphen
became gradually dropped).</quote> -
A Binary Tree Implementation in ABAP
Hi,
Can any one explaine me how to create a binary tree of random numbers with dynamic objects.
Thanks,
Manjula.Hi manjula,
This sample code uses dynamic objects to create a binary tree of random numbers as per your requirement ...pls go through It.
It stores numbers on the left node or right node depending on the value comparison with the current value. There are two recursive subrotines used for the building of the tree and printing through the tree.
For comparison purpose, the same random numbers are stored and sorted in an internal table and printed.
*& Report YBINTREE - Build/Print Binary Tree of numbers *
report ybintree .
types: begin of stree,
value type i,
left type ref to data,
right type ref to data,
end of stree.
data: tree type stree.
data: int type i.
data: begin of rnd occurs 0,
num type i,
end of rnd.
start-of-selection.
do 100 times.
generate random number between 0 and 100
call function 'RANDOM_I4'
exporting
rnd_min = 0
rnd_max = 100
importing
rnd_value = int.
store numbers
rnd-num = int.
append rnd.
build binary tree of random numbers
perform add_value using tree int.
enddo.
stored numbers are sorted for comparison
sort rnd by num.
print sorted random numbers
write: / 'Sorted Numbers'.
write: / '=============='.
skip.
loop at rnd.
write: rnd-num.
endloop.
skip.
print binary tree. This should give the same result
as the one listed from the internal table
write: / 'Binary Tree List'.
write: / '================'.
skip.
perform print_value using tree.
skip.
*& Form add_value
text - Build tree with value provided
-->TREE text
-->VAL text
form add_value using tree type stree val type i.
field-symbols: <ltree> type any.
data: work type stree.
if tree is initial. "When node has no values
tree-value = val. " assign value
clear: tree-left, tree-right.
create data tree-left type stree. "Create an empty node for left
create data tree-right type stree. "create an empty node for right
else.
if val le tree-value. "if number is less than or equal
assign tree-left->* to <ltree>. "assign the left node to fs
call add_value recursively with left node
perform add_value using <ltree> val.
else. "if number is greater
assign tree-right->* to <ltree>. "assign the right node to fs
call add_value recursively with right node
perform add_value using <ltree> val.
endif.
endif.
endform. "add_value
*& Form print_value
text - traverse tree from left-mid-right order
automatically this will be sorted list
-->TREE text
form print_value using tree type stree.
field-symbols: <ltree> type any.
if tree is initial. "node is empty
else. "non-empty node
assign tree-left->* to <ltree>. "left node
perform print_value using <ltree>. "print left
write: tree-value. "print the current value
assign tree-right->* to <ltree>. "right node
perform print_value using <ltree>. "print right
endif.
endform. "print_value
pls reward if helps,
regards. -
ADF Query Panel with Tree Table
I am using JDev 11g to create ADF Query Panel withTree Table. Basically it's working on data part.
But on presentation part it looks awkward. The tree table's master row and child row share first row for column name
ColumnMaster1 ColumnMaster2 ColumnMaster3 ColumnChild1 ColumnChild2 ColumnChild3
So when tree closed, the master side filled. Child side empty. When tree opened, master side empty and child side filled.
Are there any way, to make it inline looking with it's own column name for child?
Thanks in advance.
Edited by: kxc on Oct 30, 2009 9:19 AMHi,
the bug got closed already as not a bug. Instead this is filed as a documentation bug now, saying that tree tables don't support wrapped columns. So the bottom line is that three tables can only have a single leading column. If you need to show multiple information in there then I guess you will concatenate this
Frank -
MORE A CRY FOR HELP THEN A QUESTION-THANKS!
I'm having some diffucilites debugging errors produced by my binary search tree class. Spent alot of time trying correct them but just doesn't seem to be working for me :|!. I'm working with two main classes BinaryNode and BinarySearchTree.
class BinaryNode<AnyType> extends BinarySearchTree
// Constructor
BinaryNode(AnyType theElement)
element = theElement;
left = right = null;
// Data; accessible by other package routines
AnyType element; // The data in the node
BinaryNode<AnyType> left; // Left child
BinaryNode<AnyType> right; // Right child
public class BinarySearchTree<AnyType extends Comparable<? super AnyType>>
/** The tree root. */
protected BinaryNode<AnyType> root;
private int[] unsorted = new int[] {3,6,7,2,1};
* Construct the tree.
public BinarySearchTree()
root = null;
* Insert into the tree.
* @param x the item to insert.
* @throws DuplicateItemException if x is already present.
public void insert(AnyType x)
root = insert(x, root);
* Remove from the tree..
* @param x the item to remove.
* @throws ItemNotFoundException if x is not found.
public void remove(AnyType x)
root = remove(x, root);
* Remove minimum item from the tree.
* @throws ItemNotFoundException if tree is empty.
public void removeMin()
root = removeMin(root);
* Find the smallest item in the tree.
* @return smallest item or null if empty.
public BinaryNode<AnyType> findMin()
//uses a helpler method that iterates over the left hand of the binary tree
return(findMin(root));
* Find the largest item in the tree.
* @return the largest item or null if empty.
public BinaryNode<AnyType> findMax()
return (findMax(root));
* Find an item in the tree.
* @param x the item to search for.
* @return the matching item or null if not found.
public AnyType find(AnyType x)
return elementAt(find(x,root));
* Make the tree logically empty.
public void makeEmpty()
root = null;
* Test if the tree is logically empty.
* @return true if empty, false otherwise.
public boolean isEmpty()
return root == null;
* Internal method to get element field.
* @param t the node.
* @return the element field or null if t is null.
public AnyType elementAt(BinaryNode<AnyType> t)
return t == null ? null : t.element;
* Internal method to insert into a subtree.
* @param x the item to insert.
* @param t the node that roots the tree.
* @return the new root.
* @throws DuplicateItemException if x is already present.
protected BinaryNode<AnyType> insert(AnyType x, BinaryNode<AnyType> t)
if(t == null) {
t = new BinaryNode<AnyType>(x);
else if(x.compareTo(t.element) < 0) {
t.left = insert(x, t.left);
else if(x.compareTo(t.element) > 0 ) {
t.right = insert(x, t.right);
else {
throw new DuplicateItemException(x.toString()); // Duplicate
return t;
* Internal method to remove from a subtree.
* @param x the item to remove.
* @param t the node that roots the tree.
* @return the new root.
* @throws ItemNotFoundException if x is not found.
protected BinaryNode<AnyType> remove(AnyType x, BinaryNode<AnyType> t)
if(t == null) {
throw new ItemNotFoundException(x.toString());
if(x.compareTo(t.element) < 0) {
t.left = remove(x,t.left);
else if(x.compareTo(t.element) > 0) {
t.right = remove(x, t.right);
else if(t.left != null && t.right != null) // Two children
t.element = findMin(t.right).element;
t.right = removeMin(t.right);
else {
t = (t.left != null) ? t.left : t.right;
return t;
* Internal method to remove minimum item from a subtree.
* @param t the node that roots the tree.
* @return the new root.
* @throws ItemNotFoundException if t is empty.
protected BinaryNode<AnyType> removeMin(BinaryNode<AnyType> t)
if(t == null) {
throw new ItemNotFoundException();
else if(t.left != null) {
t.left = removeMin(t.left);
return t;
else {
return t.right;
* Given a non-empty binary search tree,
* return the minimum data value found in that tree.
* Note that the entire tree does not need to be searched.
* @param t the node that roots the tree.
* @return node containing the smallest item.
protected BinaryNode<AnyType> findMin(BinaryNode<AnyType> t)
if(t != null) {
while(t.left != null) {
t = t.left;
return t; //the smallest value
* Internal method to find the largest item in a subtree.
* @param t the node that roots the tree.
* @return node containing the largest item.
protected BinaryNode<AnyType> findMax(BinaryNode<AnyType> t)
if(t != null) {
while(t.right != null) {
t = t.right;
return t; //the largest value
* Internal method to find an item in a subtree.
* @param x is item to search for.
* @param t the node that roots the tree.
* @return node containing the matched item.
private BinaryNode<AnyType> find(AnyType x, BinaryNode<AnyType> t)
while(t != null) {
if(x.compareTo(t.element) < 0) {
t = t.left;
else if(x.compareTo(t.element) > 0) {
t = t.right;
else {
return t; // Match
return null; // Not found
public void betweenTraverse() {
betweenTraverse(root);
* Given two integers,
* print all the values in the tree which are between these two numbers
* in ascending order.
* @param t is BinaryTree to search through
* @param a is min integer to start print from
* @param b is max integer to keep integer print between
private void betweenTraverse(BinaryNode<AnyType> t)
//enter samllest vaule
int a = System.in.read();
//enter largetest vaule
int b = System.in.read();
if (t != null) {
inorderTraverse(t.left);
if(t.elementAt(t) >a && t.elementAt(t) < b) { //LINE 274 with error
System.out.println(t.elementAt(t));
inorderTraverse(t.right);
* Given an array of unsorted integers
* adds add the these elements of unsorted as nodes
* to an initially empty binary search tree
* @param x is array which it element to be added to a binary tree
public BinarySearchTree<Integer> numberstoTree(int[] x)
BinarySearchTree<Integer> treeOne = new BinarySearchTree<Integer>();
Arrays.sort(x);
for (int i = 0 ; i < x.length ; i++) {
int j = x;
treeOne.insert(j);
treeOne.inorderTraverse();
return treeOne;
public void inorderTraverse() {
inorderTraverse(root);
private void inorderTraverse(BinaryNode<AnyType> t) {
if (t != null) {
inorderTraverse(t.left);
System.out.println(t.elementAt(t));
inorderTraverse(t.right);
// Test program
public static void main(String[] args)
BinarySearchTree<Integer> t = new BinarySearchTree<Integer>();
final int NUMS = 4000;
final int GAP = 37;
System.out.println("Checking... (no more output means success)");
for( int i = GAP; i != 0; i = ( i + GAP ) % NUMS ) {
t.insert(i);
for(int i = 1; i < NUMS; i += 2) {
t.remove(i);
if(t.findMin().elementAt(t) != 2 || t.findMax().elementAt(t) != NUMS - 2) { //LINE 332 with error
System.out.println("FindMin or FindMax error!");
for(int i = 2; i < NUMS; i += 2) {
if( t.find(i) != i) {
System.out.println("Find error1!");
for(int i = 1; i < NUMS; i += 2) {
if(t.find(i) != null) {
System.out.println("Find error2!");
}I getting these errors:BinarySearchTree.java:274: operator > cannot be applied to java.lang.Comparable,int
if(t.elementAt(t) >a && t.elementAt(t) < b) {
^
BinarySearchTree.java:274: operator < cannot be applied to java.lang.Comparable,int
if(t.elementAt(t) >a && t.elementAt(t) < b) {
^
BinarySearchTree.java:332: elementAt(BinaryNode) in BinarySearchTree cannot be applied to (BinarySearchTree<java.lang.Integer>)
if(t.findMin().elementAt(t) != 2 || t.findMax().elementAt(t) != NUMS - 2) {
^
BinarySearchTree.java:332: cannot find symbol
symbol : method elementAt(BinarySearchTree<java.lang.Integer>)
location: class java.lang.Integer
if(t.findMin().elementAt(t) != 2 || t.findMax().elementAt(t) != NUMS - 2) {
^ I've tried to change the method return types, to integer, AnyType but still producing more or same amount of errors, any help debugging this would be so helpful!.
ThanksSo i've tried to re implement the static statements. i.e
if(t.findMin().compareTo(t.elementAt(t.root)) != 2 || t.findMax().compareTo(t.elementAt(t.root)) != NUMS - 2) {
System.out.println("FindMin or FindMax error!");
}but now receiving this error :
BinarySearchTree.java: operator > cannot be applied to java.lang.Comparable,java.lang.Integer
if(t.elementAt(t) > A && t.elementAt(t) < B) { //LINE 274 WITH ERROR
^
BinarySearchTree.java: operator < cannot be applied to java.lang.Comparable,java.lang.Integer
if(t.elementAt(t) > A && t.elementAt(t) < B) { //LINE 274 WITH ERROR
^
BinarySearchTree.java: cannot find symbol
symbol : method compareTo(java.lang.Integer)
location: class BinaryNode<java.lang.Integer>
if(t.findMin().compareTo(t.elementAt(t.root)) != 2 || t.findMax().compareTo(t.elementAt(t.root)) != NUMS - 2) {
^
BinarySearchTree.java: cannot find symbol
symbol : method compareTo(java.lang.Integer)
location: class BinaryNode<java.lang.Integer>
if(t.findMin().compareTo(t.elementAt(t.root)) != 2 || t.findMax().compareTo(t.elementAt(t.root)) != NUMS - 2) {The method compareTo takes an object as defined in the comparable interface which my BinarySearchTree extends. Binary Node is a child of BinarySearchTree. I've been messing around with where i initiate the compareTo method but not had any success, any idea/push in the right direction would be appreciated.
Thanks -
I'm just wondering : when a Component Tree is contitute for the first time
When I'm looking at the JSF life cycle figure I can see the "Reconstitute Componente Tree" but I don't see something like "Constitute Componente Tree". When is it supposed to happen ?
Thanks for your answer.If there is no existing tree (for example if it's the first time you reach a certain page), you start with an empty tree. It is up to you to create a new tree, either directly from Java, or (which is probably going to be the most typical scenario) through a template language like JSP using the Standard HTML RenderKit Tag Library.
When using JSP, the JSF spec defines a sort of tree merging algorithm, which merges an existing tree with a tree defined in your JSP file. If the initial tree is empty, the resulting tree is going to depend 100% on the tree defined in your JSP. If there is an initial tree, slightly more complex rules may apply. -
How to delete a node from a node network
How do I delete a node from a node network?
<P>
<OL>
<LI>Follow the instructions on page 30 of the Calendar Server (CS) 3.x Admin Guide,
and page 62 of the CS 4.0 Admin Guide "Deleting (excluding) a Node from the
Network".
<LI>Shut down the Directory Server.
<LI>Backup the LDAP directory to an LDIF file.
<LI>Edit this LDIF file and delete references to the
6 calendar reserved users for the node to be deleted.
<LI>Restore the LDAP directory with this changed LDIF file.
<LI>Run unidbfix -export -n all
<LI>Edit the resulting remotenodes.ini
files and delete all
references to the node to be deleted.
<LI>Run unidbfix -import -n all
<LI>Start the Directory Server.
<LI>Start the Calendar Server.
<P>
Note: This next step is for Calendar Server 3.x * ONLY *
<P>
<LI>Run unireqdump -delete
to delete all requests to the node
to be deleted.
</OL>Divya wrote:
Hi,
I'm using forms6i.
I want to delete unselected nodes from a tree
How can it be done??
ThanksIf you mean empty branches as unselected nodes,
set Allow Empty Branches property to 'No' in the Trees property. -
Designer not incorporating OLB item properties
I have an item identified on a canvas as a tree control item. In the item property Template/Object Library I have the value 'USO$MY_TREE'. In the object library used for generation I have 'USO$MY_TREE' identified and the property 'Allow Empty Branches' set to no. When I generate my form from case and look at it in Forms6I that vale is set to Yes. I am using designer version 6.5.91.0.9 configuration 4.0.12 release 4.6.
Forms Builder version 6.0.8.18.3. I need this to say 'No' which is what is in the Object Library. Is there a generator preference or something I am missing here?Hi
In the generated FMB, the tree control subclass information is correctly pointing to your object?
Anyway, if there is no other way, you may, in the when-new-form-instance trigger, dynamically set that property:
set_tree_property('block.tree', ALLOW_EMPTY_BRANCHES, PROPERTY_FALSE);
hth -
BPM Fork Processing without receiving all required messages
Hi
I am developing a BPM which receives 5 different messages.
I am putting a block with Local Correlation with Block Start = New Transaction and Block End = New Transaction.
Inside this block, I am using Fork with Necessary Branches = 5 , using local correlation for each receive step with Use Correlation and Activate Correlation.
When I am adding Receive Steps to Fork, there is an extra branch getting added to the Fork. So now I have 5 Receive steps with Abstract Interfaces and one extra step without having anything. I couldn't figure out how to get rid of this extra step. I know there is way to get rid of this extra step in Fork...but not sure how
Now, when I am testing, after receiving any 4 messages process is coming out of the Fork block and going to the next block.
As in the next block I use all the 5 messages, I am getting error there.
Can you please give your inputs what could cause this problem?
How do we get rid of extra branch in Fork which we do not use..
Thanks for your help in advance.
Regads,
RameshHello Ramesh,
When you Drag-Drop any process step in the Fork, it will create a new branch and will sit inside that branch. If you want to put the step on some specific branch then Drag the process step and take it to the desired branch and only drop when [ ] appears on that branch. To insert new branch in fork you can use Right click on Fork->Insert->New Branch.
Now for ur problem, you have set the necessary branches as 5, when u receive the 4 message(4 branches executed) and fifth branch(empty branch) will make total count to 5. Therefore, ur fork step will be executed and will not wait for the fifth msg.
HTH,
Regards,
Sami.
Maybe you are looking for
-
How do I find and use the Firefox Identity Finder feature?
On a web page that compares various Web browsers, the following narrative describes a Firefox 5.0 feature called Identity Finder: "Once Identity Finder has secured all exposed private data, a laptop thief or spying Trojan won't be able to steal your
-
What is the best way to download (full dump) of Photo Stream to Win 7 PC and ERASE / DELETE the content appearing on Photo Stream on my iPhone 4? There are about 3000 photos on the Photo Stream that I just simply want to download on my PC so i can cl
-
OIM 11g high availability - is LDAP required for Weblogic credential store
Hi all, Trying to understand whether we need an LDAP in an HA architecture with [OIM/SOA] - [OIM/SOA/Admin]? The HA guide: http://docs.oracle.com/cd/E14571_01/core.1111/e10106/imha.htm#CDEFECJF Does not mention this requirement, in fact it specifical
-
Naming, arranging linked photos with Excel document info
Hello! I am attempting to make a newspaper layout consisting for graduates from our local high schools. I have been provided a disc with literally hundreds of pictures. The photos in the layout need to be arranged in alphabetical order, but the file
-
Getting music videos onto your ipod?
I've had my 5th gen ipod for a year now and I just figured out how to convert my windows media-using music videos onto my ipod. Only problem, there's no sound. I have the picture but I'm not getting any sound. Anyone have any suggestions? Also, is th