TREE STructures
hi all,
i was working with the tree structures . . . i used CL_GUI_SIMPLE_TREE. when i was done with it i found that it can only make one level nodes nesting .
Please help what should i use, i want to have a tree with any number of levels of tree nodes.
Thanx in Advance
Zahid
Hello Shehryar,
Firstly, it's nice to know that you like some of the posts that I make here. I like some of your posts very much, too.
Secondly, Sorry for this late response.
Now I shall try to correct you :-)...
Please consider the last post that Zahid had made. He says :
<i>Thank You Raj! for ur help..
plz look at the problem what i am actually facing , i mentioned in the above post . . . plz tell me some solution
Zahid</i>
What I understand when he says <u>"....the problem i am actually facing, i mentioned in the above post..."</u> is that he wants to have a solution to the problem of building a tree of his specifications.
In fact, I see that you had also sent him a mail giving him some information. I have no idea about what that was.
Since he says he is a beginner, I just wanted to give him a little <i>food for thought</i>, if I can call it that, to some basic problem-solving skills in computation. The tree control had just happened to be an example here.
Trust this sorts things out a bit. Please revert, if you have something else to be clarified.
Regards,
Anand Mandalika.
P.S. 1. I personally prefer going to the Class and clicking the button for "Method Documentation" (place your cursor on the method name and hit F9), rather than going to SE63 (to which the developer might sometimes be unauthorized)
2. Attempting / wanting to find out the documentation of all the objects (be it programs / FMs / classes / anything ) is something that I don't think makes too much sense. You would have to know the object for which you want the documentation. In other words, you would have to know ( or find out if you do not know ) the tool that you need to use. Then you can read more about it and see if the particular tool does what you want. It is hardly the case that you see what a tool offers and then decide whether you have a requirement for that.
Similar Messages
-
How to create a tree structure using forms.
Hi,
How do i create a tree structure using oracle forms,i have a table named Functions and a specific column 'Function Name' should be displayed in the tree nodes.Can anyone help me out on how to create a tree structure and populating the nodes??
thanks in advance
Regards
KarthikThe FTree package provides functions to populate the tree - look for the topic "Manipulating a hierarchical tree at runtime
" in the online help this point to all the functions and triggers -
How to show alv report in tree structure
hi all,
how to show data or create a alv report in tree structure.
thanks in advance.
HarshaHi Harsha,
Its done using FM 'RS_TREE_CONSTRUCT'
and FM for displaying the tree: 'RS_TREE_LIST_DISPLAY'
Thanks
Shrila -
How to get Text for nodes in Tree Structure
Hi Friends,
How to get Text for nodes in Tree Structure
REPORT YFIIN_REP_TREE_STRUCTURE no standard page heading.
I N I T I A L I Z A T I O N
INITIALIZATION.
AUTHORITY-CHECK OBJECT 'ZPRCHK_NEW' :
ID 'YFIINICD' FIELD SY-TCODE.
IF SY-SUBRC NE 0.
MESSAGE I000(yFI02) with SY-TCODE .
LEAVE PROGRAM.
ENDIF.
class screen_init definition create private.
Public section
public section.
class-methods init_screen.
methods constructor.
Private section
private section.
data: container1 type ref to cl_gui_custom_container,
container2 type ref to cl_gui_custom_container,
tree type ref to cl_gui_simple_tree.
methods: fill_tree.
endclass.
Class for Handling Events
class screen_handler definition.
Public section
public section.
methods: constructor importing container
type ref to cl_gui_custom_container,
handle_node_double_click
for event node_double_click
of cl_gui_simple_tree
importing node_key .
Private section
private section.
endclass.
*& Classes implementation
class screen_init implementation.
*& Method INIT_SCREEN
method init_screen.
data screen type ref to screen_init.
create object screen.
endmethod.
*& Method CONSTRUCTOR
method constructor.
data: events type cntl_simple_events,
event like line of events,
event_handler type ref to screen_handler.
create object: container1 exporting container_name = 'CUSTOM_1',
tree exporting parent = container1
node_selection_mode =
cl_gui_simple_tree=>node_sel_mode_multiple.
create object: container2 exporting container_name = 'CUSTOM_2',
event_handler exporting container = container2.
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = ' '. "system event, does not trigger PAI
append event to events.
call method tree->set_registered_events
exporting events = events.
set handler event_handler->handle_node_double_click for tree.
call method: me->fill_tree.
endmethod.
*& Method FILL_TREE
method fill_tree.
data: node_table type table of abdemonode,
node type abdemonode.
types: begin of tree_node,
folder(50) type c,
tcode(60) type c,
tcode1(60) type c,
tcode2(60) type c,
text(60) type c,
text1(60) type c,
text2(60) type c,
end of tree_node.
data: wa_tree_node type tree_node,
t_tree_node type table of tree_node.
wa_tree_node-folder = text-001.
wa_tree_node-tcode = text-002.
wa_tree_node-text = 'Creditors ageing'.
wa_tree_node-tcode1 = text-003.
wa_tree_node-text1 = 'GR/IR aging'.
wa_tree_node-tcode2 = text-004.
wa_tree_node-text2 = 'Bank Balance'.
append wa_tree_node to t_tree_node.
clear wa_tree_node .
wa_tree_node-folder = text-005.
wa_tree_node-tcode = text-006.
wa_tree_node-text = 'Creditors ageing'.
wa_tree_node-tcode1 = text-007.
wa_tree_node-text1 = 'Creditors ageing'.
wa_tree_node-tcode2 = text-008.
wa_tree_node-text2 = 'Creditors ageing'.
append wa_tree_node to t_tree_node.
clear wa_tree_node .
wa_tree_node-folder = text-009.
wa_tree_node-tcode = text-010.
wa_tree_node-text = 'Creditors ageing'.
wa_tree_node-tcode1 = text-011.
wa_tree_node-text1 = 'Creditors ageing'.
wa_tree_node-tcode2 = text-012.
wa_tree_node-text2 = 'Creditors ageing'.
append wa_tree_node to t_tree_node.
clear wa_tree_node .
node-hidden = ' '. " All nodes are visible,
node-disabled = ' '. " selectable,
node-isfolder = 'X'. " a folder,
node-expander = ' '. " have no '+' sign forexpansion.
loop at t_tree_node into wa_tree_node.
at new folder.
node-isfolder = 'X'. " a folder,
node-node_key = wa_tree_node-folder.
clear node-relatkey.
clear node-relatship.
node-text = wa_tree_node-folder.
node-n_image = ' '.
node-exp_image = ' '.
append node to node_table.
endat.
at new tcode .
node-isfolder = ' '. " a folder,
node-n_image = '@CS@'. "AV is the internal code
node-exp_image = '@CS@'. "for an airplane icon
node-node_key = wa_tree_node-tcode.
node-text = wa_tree_node-text .
node-relatkey = wa_tree_node-folder.
node-relatship = cl_gui_simple_tree=>relat_last_child.
endat.
append node to node_table.
at new tcode1 .
node-isfolder = ' '. " a folder,
node-n_image = '@CS@'. "AV is the internal code
node-exp_image = '@CS@'. "for an airplane icon
node-node_key = wa_tree_node-tcode1.
node-relatkey = wa_tree_node-folder.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = wa_tree_node-text1.
endat.
append node to node_table.
at new tcode2 .
node-isfolder = ' '. " a folder,
node-n_image = '@CS@'. "AV is the internal code
node-exp_image = '@CS@'. "for an airplane icon
node-node_key = wa_tree_node-tcode2.
node-relatkey = wa_tree_node-folder.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = wa_tree_node-text2.
endat.
append node to node_table.
endloop.
call method tree->add_nodes
exporting table_structure_name = 'ABDEMONODE'
node_table = node_table.
endmethod.
endclass.
*& Class implementation
class screen_handler implementation.
*& Method CONSTRUCTOR
method constructor.
create object: HTML_VIEWER exporting PARENT = CONTAINER,
LIST_VIEWER exporting I_PARENT = CONTAINER.
endmethod.
*& Method HANDLE_NODE_DOUBLE_CLICK
method handle_node_double_click.
case node_key(12).
when 'Creditors'.
submit YFIIN_REP_CREADITORS_AGING via selection-screen and return.
when 'Vendor'.
submit YFIIN_REP_VENDOR_OUTSTANDING via selection-screen and return.
when 'Customer'.
submit YFIIN_REP_CUSTOMER_OUTSTANDING via selection-screen and
return.
when 'GR/IR'.
submit YFIIN_REP_GRIR_AGING via selection-screen and return.
when 'Acc_Doc_List'.
submit YFIIN_REP_ACCOUNTINGDOCLIST via selection-screen and return.
when 'Bank Bal'.
submit YFIIN_REP_BANKBALANCE via selection-screen and return.
when 'Ven_Cus_Dtl'.
submit YFIIN_REP_VENDORCUST_DETAIL via selection-screen and return.
when 'G/L_Open_Bal'.
submit YFIIN_REP_OPENINGBALANCE via selection-screen and return.
when 'Usr_Authn'.
submit YFIIN_REP_USERAUTHRIZATION via selection-screen and return.
endcase.
endmethod.
endclass.
Program execution ************************************************
load-of-program.
call screen 9001.
at selection-screen.
Dialog Modules PBO
*& Module STATUS_9001 OUTPUT
text
module status_9001 output.
set pf-status 'SCREEN_9001'.
set titlebar 'TIT_9001'.
call method screen_init=>init_screen.
endmodule. " STATUS_9001 OUTPUT
Dialog Modules PAI
*& Module USER_COMMAND_9001 INPUT
text
module user_command_9001 input.
endmodule. " USER_COMMAND_9001 INPUT
*& Module exit_9001 INPUT
text
module exit_9001 input.
case sy-ucomm.
when 'EXIT'.
set screen 0.
endcase.
endmodule.
exit_9001 INPUTyou can read the table node_table with nody key value which imports when docubble click the the tree node (Double clifk event).
Regards,
Gopi .
Reward points if helpfull. -
How to use ONE query to find out tree structure?
ID------------upperID----------Name------------------------isFolder
1------------ 0---------- Folder
1------------------------------------1
2------------ 1------------ Folder 1- Sub
Folder--------------------1
3------------ 2------------
Folder1-Item1-A--------------------------0
4------------ 1------------ Folder 1- Sub
Item-----------------------0
Hi all, if I have a table like above to demonstrate the
folders and item relationship. This structure allows the user to
create unlimited folders and items.
Now I would like to use one query to find out the tree
structure of this table, how could I do the query.
Any help on this will be highly appreciated!
Thanks,
ezAlso, see this thread:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=7&threadid=12 55788&enterthread=y -
How to create a form on a tree structured table
Hi,
I have a table that is designed to do a tree structure like:
Table Name: test
Fields:
ID
ParentID
Description
I created a browser (IR) (page 1) that calls a form (page 2)
The form has the editing fields and at the bottom layer I have a reports region where I display the children records using a query like:
select * from test where ParentID = :P2_ID
I need at the region level to add a button to call a form to edit the child record (which is the same table) and when done, to return to the form again but to the parent record.
How can I do that successfully? Is there any example:?
Thank youMaybe this can help:
http://apex.oracle.com/pls/otn/f?p=31517:157
using instead of trigger on a view.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
How to create Tree structure in Visual Composer
Hi All,
I need to develop tree structure in my VC application. Can any one of you please suggest me the steps to do it.Its very urgent please can any one help me out in this.
Regards,
LakshmiHi Nutan,
if you want to solve it with webdynpro it depends on your skills in java and abap. There are books available to start with webdynpro and there are examples for building tree structures with Webdynpro.
[Java Webdynpro|http://www.sappress.com/product.cfm?account=&product=H983]
[ABAP Webdynpro|http://www.sappress.com/product.cfm?account=&product=H1916]
If you want to do it in VC you have to write e.g. an ABAP rfc function module, which returns you the tree with the information about childnode, parentnode and so on, so that you can display it in the table. But if the users click on sort then the tree is "destroyed". You can also display only a few levels of your tree and when you select a certain node a drill down is done by calling a rfc which returns the child nodes of the corresponding node.
But I think the solution with VC is not the best. Use webdynpro for this requirements.
Best Regards,
Marcel -
How to get Tree structure in JSP page?
Hi,
I would like get data from the database and display the data in tree structure with the check boxes at each nodes on a jsp page with out using any third party tools. how can i do that? Do i require any new tags to fulfill this requirement?
can any one help me out by sending any example code?
thanks in advance.
Regards,
ReddyOnce you have the data in a list or something, can't you just use <c:forEach> and then output standard nested <ul> and <li> tags to give the tree structure.
<html>
<style>
li
list-style-type:none;
</style>
<body>
<form>
<ul>
<li>
<input type="checkbox">Check 1</input>
<ul>
<li>
<input type="checkbox">Check 1A</input>
</li>
<li>
<input type="checkbox">Check 1B</input>
</li>
</ul>
</li>
<li>
<input type="checkbox">Check 2</input>
<ul>
<li>
<input type="checkbox">Check 2A</input>
</li>
</ul>
</li>
<li>
<input type="checkbox">Check 3</input>
</li>
</ul>
</form>
</body>
</html> -
How can I create a Tree Structure in java ??
Hi,
I want to create a tree structure(objects hierarchy) using java language. Is there any API method for this ?
Can any one please give me a hint or suggestion how I can do this ??
Thanks for the help in advance.Do you mean graphically?
You can use a TreeSet or TreeMap if you just want to use tree structures.
Kaj -
How to get tree structure navigation in module pool program
please send me a sample code for getting tree structure navigation in a screen in module pool program.
ex.
masters
itemsdo a chain and endchain on the fields.Then insert the fields in to the required database.
-
How to get the folder name of selected subitem in tree structure?
Hi All,
I created a tree structure like below.
->Folder1-- 1
2
3
->Folder2-----1
2
3
i.e i have two folders & each folder having the values like above.Now i want to perform some action by clicking on the any of the values.Suppose if i click value 2,i want to do some action.the actions need to perform is varies from floder to to folder.
So How can i get the folder name of clicked Value?
Regards,
RaviHi Kumar ,
the below code should help you.
Register the below action for the leaf node for which u need the subfolder's name above it.
Worked fine in my system ...hope it does in ur scenario too
method ONACTIONGET_PATH .
data : lr_element TYPE REF TO if_wd_context_element,
lr_node TYPE REF TO if_wd_context_node,
ls_path type string,
ls_path_node TYPE string,
lt_string type TABLE OF string,
l_lines type i,
l_lines_1 TYPE i.
lr_element = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
**-> getting the path of the node/leaf
*which u had clicked and from that getting the node above it
ls_path = lr_element->get_path( ).
SPLIT ls_path at '.' into table lt_string.
-> remove the first 2 entries as they will contain the view name
DELETE lt_string FROM 1 to 2.
l_lines = LINES( lt_String ).
l_lines_1 = l_lines - 1.
-> remove the last 2 entries as they will contain the element in the path
DELETE lt_string from l_lines_1 to l_lines.
LOOP AT lt_string into ls_path.
CONCATENATE LINES OF LT_STRING into ls_path_node SEPARATED BY '.'.
ENDLOOP.
**-> getting access to the node above the leaf element
LR_NODE = WD_CONTEXT->PATH_GET_NODE( path = ls_path_node ).
lr_element = lr_node->get_element( ).
**-> Getting the name of the folder...
*here path is the attribute in my context which stores the name of the folder
lr_element->get_attribute( EXPORTING name = 'PATH' IMPORTING value = ls_path ).
endmethod. -
How to create a PortalSite map in a tree structure
Hi,
We are trying to reuse SAP Portal EP 7.3 standard functionalities related to create a Portal Site Map.
I've seen the procedure to create a Workset map iview (http://help.sap.com/saphelp_nw73/helpdata/en/49/32a7a9e8c45aaae10000000a42189d/frameset.htm), but we are interested in generate this map contained in a tree structure, because currently the SAP EP 7.1 brings the menu and option format.
I would like to know if this is possible using the standard functionalities or it is required to develop any application?
Please if you could help me it would be really useful.
Thanks in advance,Thanks for your help Srinivas,
I was trying to know if it was possible to assign a style or layout to the site map iview created using the standard map iview delivered by SAP EP 7.3. I was looking for documentation but it is not enough at all and in my project we are still working with SAP EP 7.0
Please, if anyone could know about the map site iview standard and the available styles or maybe it is not changeable.
In that case, the only way it would be a development to get the tree structure.
Thanks!!!! -
I'm having trouble '''Finding''' the forum where I can look for the information I need. I keep ending up in '''endless menus of non-helpful information. '''
I got a popup message, I needed to upgrade to 3.6.17. After allowing it and rebooting, I couldn't start FF anymore, just got a crash report. I tried going to the restore point I had set with no luck and I tried creating a new profile. I lost all my bookmarks (only the Cache remained). And I sat in live chat for an hour waiting for help. German live chat had one helper and English live chat was closed.
So I gave up on help, uninstalled FF 3.6.17 and downloaded FF 3.6.15 and installed it. It loads but all bookmarks are gone. More importantly, now when I load the bookmarks, I can't '''retrieve''' them except by storing a new one. '''Only''' when I create a new bookmark can I see the folders I've created. I can't get to the organizer so I can't use the bookmarks to retrieve websites.
I'm disturbed that I can't get to the tree-structure forum where I can get the help I need. This "lead me around" labyrinth from one question to another, without being able to look through the forum for the information I need, is not helpful.
Thank you.
FoxhuntI believe you just are able to delete them from iTunes.
Hope it will be helpful -
How to populate Tree structure from BAPI while tree grows or shrinks
Hi All
Currently I am populating the tree structure from BAPI based on the HLevel (Hierarchy Level) parameter, but when ever insertion and deletion happens in the tree at any level in the UI and at the same time i am updating these tree node values with HLevel value(example : 1 is first level , 2 is second level, 3 is third level etc) updating successfully& correctly into the BAPI, no issues.
Once it is updated into the BAPI, next time when i refreshed the UI then i am not populating the tree structure correctly from BAPI with updated new nodes based on the HLevel. when tree struture grows or shrinks in the BAPI after updating into BAPI from UI then i am not populating the tree sturcture correctly based on the HLevel value from the BAPI.
Please let me know any sample code how to populate tree structure correctly when tree structure grows or shrinks based on the HLevel value ( Hierarchy Level , for example : 1 is level , 2 is 2nd level , 3 is third level nodes etc)
anybody helps in this regard with sample code on the populating tree tructure then it would be great help to me.
Thanks in advance
Regards
Kalki Reddy
Edited by: KalkiReddy on Nov 29, 2009 3:48 PMBapi output node:
Value | Text | HLevel
01 | A | 1
0101 | AA | 2
010101 | AAA | 3
01010B | AAB | 3
0102 | AB | 2
02 | B | 1
0201 | BA | 2
This code is used to build the tree in wdDoInit method
IE_T_CatalogueNode catalogueNode = wdContext.nodeE_T_Catalogue();
int size = catalogueNode.size();
ICatalogoElement level1elem = null;
for (int i = 0; i < size; i ++)
IE_T_CatalogueElement catalogueElem = catalogueNode.getE_T_CatalogueElementAt(i);
if (catalogueElem.getLevel().equals("1"))
// 1 Livello
level1elem = wdContext.createCatalogoElement();
level1elem.setKATALOGART_CODE(catalogueElem.getKatalogart());
level1elem.setCODEGRUPPE_CODE(catalogueElem.getCodegruppe());
level1elem.setCODE(catalogueElem.getCode());
level1elem.setCODE_DESCR(catalogueElem.getKatalogart_Descr());
level1elem.setDESCR(catalogueElem.getKatalogart_Descr());
wdContext.nodeCatalogo().addElement(level1elem);
for (int j = i + 1; j < size; j ++)
IE_T_CatalogueElement catalogueElem2level =
catalogueNode.getE_T_CatalogueElementAt( j );
String level2 = catalogueElem2level.getLevel();
if (level2.equals("2"))
ICatalogoElement level2elem = level1elem.nodeChild().createCatalogoElement();
level2elem.setKATALOGART_CODE(catalogueElem2level.getKatalogart());
level2elem.setCODEGRUPPE_CODE(catalogueElem2level.getCodegruppe());
level2elem.setCODE(catalogueElem2level.getCode());
level2elem.setCODE_DESCR(catalogueElem2level.getCodegruppe_Descr());
level2elem.setDESCR(catalogueElem2level.getCodegruppe_Descr());
level1elem.nodeChild().addElement(level2elem);
for (int k = j + 1; k < size; k ++)
IE_T_CatalogueElement catalogueElem3level =
catalogueNode.getE_T_CatalogueElementAt( k );
String level3 = catalogueElem3level.getLevel();
if (level3.equals("3"))
ICatalogoElement level3elem = level2elem.nodeChild().createCatalogoElement();
level3elem.setKATALOGART_CODE(catalogueElem3level.getKatalogart());
level3elem.setCODEGRUPPE_CODE(catalogueElem3level.getCodegruppe());
level3elem.setCODE(catalogueElem3level.getCode());
level3elem.setCODE_DESCR(catalogueElem3level.getCode_Descr());
level3elem.setDESCR(catalogueElem3level.getCode_Descr());
level2elem.nodeChild().addElement(level3elem);
Damiano -
ATP Tree Structure is not getting created automatically after Sales Order is saved
In one one of our scenario, when we add material to Sales Order and save with Requirement Type(under Procurrement Tab of Sales Order) , in APO there is no planned order or only planned order which is dynamically pegged created because the ATP Tree in APO is not being converted. There is no pegging relevant item create(e.g. Planned Order). When we are checking the persistent ATP Trees in APO (/SAPAPO/ATREE_DSP - ATP-Trees) we can see that they are not converted automatically. They are still there. If we do it manually via transaction (/SAPAPO/RRP_ATP2PPDS - Conversion ATP Tree Structures -> Production Planning) it works. Afterwards the Planned Order is available and fixed pegged.
Why is APO not converting the ATP tree automatically ?
I also checked the scheduling horizon for conversion of the ATP Tree and it is correct: Is there any relation with Check Mode setting under ATP tab in Material Master?Hi Prasad ,
This enables you to debug the ATP tree . If you have created an entry here with your user name then it will not let ATP tree get converted into PP/DS orders automatically .
It's very surprising because all seems fine . Just cross check all the settings once with below .
The conversion time depends on the following horizons and dates:
· PP/DS Horizon
· Scheduling horizon for the conversion of ATP tree structures
· Requirements dates in the ATP tree structure
PP/DS immediately converts the ATP tree structure when the sales order is saved
· If the earliest requirements date for components is within the scheduling horizon or
· If the latest requirements date for finished products is within the PP/DS horizon
If none of these conditions are fulfilled when saving the sales order, the system saves the ATP tree structure in SAP APO. In this case you can only convert the ATP tree structure online or in the background when one of the conditions given above is fulfilled. Here, there is an offset for the horizons with which you can achieve an earlier conversion.
You maintain the scheduling horizon for the conversion of ATP tree structures in Customizing for Production Planning and Detailed Scheduling under Maintain Global Parameters and Defaults. You maintain a location product specific PP/DS horizon in the location product master. If no location product specific PP/DS horizon exists, the system uses the PP/DS horizon from the planning version. You maintain these in Model and Planning Version Management.
Love Singh -
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>
Maybe you are looking for
-
I have two Airport Express units. Can I use one to extend the range of the other?
The similar questions that I have found on this site refer to extending an Airport Extreme with an Airport Express. But can you also extend an Airport Express with another Airport Express?
-
Create lock object with fun command
Hallo, Is it possible to create a lock object with the fun command? I tried to use: FUN ( ENQUEUE _<lockobject> , <interface> ). When I fill the importing parameters, execute the script and afterwards refresh the interace than the import parameters a
-
ActionScript 2 need to show graphic when doors open
I had this working at one time but having a problem with adding a graphic display when the door starts to open. A button initiates the door to open, here is the script. the second part is where it fails, anyone help please. Can send fla if needed on
-
Sorry for cross posting, but I accidentally put this in the Mac forum when it should have clearly been here. I'm hoping that someone has an answer to my little problem. Here's the post: "I have a certain reoccurring problem with a few CDs when I try
-
Backing up your backups: the right way.
Hello everyone. I've been searching a lot online but haven't found anything that could help me doing what I need to. Have anyone ever tried to make a Backup of only one particular time machine backup ? Let me explain: I have a hard drive full of time