Add tree node problem
Hi guys, I'm trying to add nodes programatically but I have the same wrong behavior:
1. I displayed a tree which will be updated from a data block and Selected say NODE1.
2. After I displayed it I EXECUTE QUERY on the DATA BLOCK next to it, so I can choose a candidate record to belong to the tree structure.
3. I add the record via a button which has the addMyNode code.
4. It adds the node correctly. (say NODE11).
5. I add another node just behind the new node (NODE11) say NODE 111.
6. With my mouse I selected the father(NODE1) of NODE11 and add a brother of NODE 11, say NODE12, but this node is added next to NODE111.
7. If I navigate a little while through the tree after step number 5, and then return to NODE1 with my mouse, I can add it perfectly.
What's wrong with my code:??
AddMyNode (in a PushButton):
PROCEDURE AddMyNode IS
htree ITEM;
top_node FTREE.NODE;
new_node FTREE.NODE;
item_value VARCHAR2(120);
num_selected NUMBER;
current_node FTREE.NODE;
ncl_centro NUMBER;
BEGIN
htree := Find_Item('DB_ARBOL.HT_ARBOL');
num_selected := Ftree.Get_Tree_Property(htree, Ftree.SELECTION_COUNT);
FOR j IN 1..num_selected LOOP
current_node := Ftree.Get_Tree_Selection(htree, j); Long postings are being truncated to ~1 kB at this time.
Hi guys, I'm trying to add nodes programatically but I have the same wrong behavior:
1. I displayed a tree which will be updated from a data block and Selected say NODE1.
2. After I displayed it I EXECUTE QUERY on the DATA BLOCK next to it, so I can choose a candidate record to belong to the tree structure.
3. I add the record via a button which has the addMyNode code.
4. It adds the node correctly. (say NODE11).
5. I add another node just behind the new node (NODE11) say NODE 111.
6. With my mouse I selected the father(NODE1) of NODE11 and add a brother of NODE 11, say NODE12, but this node is added next to NODE111.
7. If I navigate a little while through the tree after step number 5, and then return to NODE1 with my mouse, I can add it perfectly.
What's wrong with my code:??
AddMyNode (in a PushButton):
PROCEDURE AddMyNode IS
htree ITEM;
top_node FTREE.NODE;
new_node FTREE.NODE;
item_value VARCHAR2(120);
num_selected NUMBER;
current_node FTREE.NODE;
ncl_centro NUMBER;
BEGIN
htree := Find_Item('DB_ARBOL.HT_ARBOL');
num_selected := Ftree.Get_Tree_Property(htree, Ftree.SELECTION_COUNT);
FOR j IN 1..num_selected LOOP
current_node := Ftree.Get_Tree_Selection(htree, j); Long postings are being truncated to ~1 kB at this time.
Similar Messages
-
How can i can add tree node ?
h want like to add tree node in the run time mode and commit it into database
use ftree.ADD_TREE_NODE for adding new nodes.
But what do you want to save in the db ? -
Dynamic add tree node and thread
Hi,
I implemented a thread by using SwingWorker class to execute the time-consuming file loading and processing task instead of the event-dispatching thread. However, I need to dynamically add node to a tree by using data returned by the file loader in my project's main frame like following:
if (source == loadAffyItem) {
//load affy file data to the application
loader = new AffyFileLoader();
//dynamically add node to the tree after data loading
rawDataNode = treePanel.addObject(null, "Raw Data");
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new UserData("Pixel", loader.getPixelMatrix()));
pixelNode = treePanel.addObject(rawDataNode, node);
node = new DefaultMutableTreeNode(new UserData("Signal", loader.getSignalMatrix()));
signalNode = treePanel.addObject(rawDataNode, node);
}However, I always get a NullPointer error by doing this way since the code to dynamically add node to the tree using data returned from loader, but the loader is executed
in another thread and not finished yet. How could I make that code executed after the loader class is finished? Hope you could enlight me about this issue?
thanks in advance!
JennyYou'll have to redesign a bit. You could either have the separate thread add the node when it's finished (using SwingUtilities invokeLater to ensure you're updating the GUI in the Event Dispatch thread), or you could have the separate thread call-back or send an event when it's finished (and your main thread would listen).
-
Hierarchical tree node problem
Hi all --
Today's problem is (drum roll)............
My application uses a heirarichal tree where each tree node contains the name of a form within this system. The user can navigate from form to form by clicking the appropriatetly name tree node. This seems to work - sometimes. Some users click on a node for one form, but get transferred to another named form(usually the one above or below the one actually activated). I've also found out that this happens ONLY when the user has their screen resolution set to 800 x 600. This application was developed at screen resolution 1024 x 768 and it woks fine. Anybody know why??Here is the code for both the tree node selected and tree node activated triggers
Tree Node Seleceted code:
:CONTROL.Node_Activated := null ;
:CONTROL.Node_Selected := Ftree.Get_Tree_Node_Property('CONTROL_TREE.MENU', :SYSTEM.TRIGGER_NODE, Ftree.NODE_VALUE) ;
===========================================================
Tree Node Activated code:
Declare
LN$I Pls_integer ;
Begin
:CONTROL.Node_Selected := null;
:CONTROL.Node_Activated := Ftree.Get_Tree_Node_Property('CONTROL_TREE.MENU', :SYSTEM.TRIGGER_NODE, Ftree.NODE_VALUE) ;
If :CONTROL.Node_Activated IS NOT NULL Then
if :GLOBAL.curr_proc_id <> :control.node_activated or :control.node_activated
is null then
CALL_FORM(:CONTROL.Node_Activated);
else
Set_Alert_Property( 'AL_FORM_OPENED', ALERT_MESSAGE_TEXT,
:CONTROL.Node_Activated || ' is already opened. Please check your current or previously opened library.' );
LN$I := Show_Alert( 'AL_FORM_OPENED' ) ;
end if;
end if ;
end ; -
Tree and Tree Node Components - Threadinar7
Hi All,
This is the seventh in the "Threadinar" series , please see Threadinar6 at
http://forum.sun.com/jive/thread.jspa?threadID=100601 for details
In this Threadinar we will focus on the
"Tree" and "Tree Node" Components
Let us begin our discussion with the Tree Component.
Tree Component
You can drag the Tree component from the Palette's Basic category to the Visual Designer to create a hierarchical tree structure with nodes that can be expanded and collapsed, like the nodes in the Outline window. When the user clicks a node, the row will be highlighted. A tree is often used as a navigation mechanism.
A tree contains Tree Node components, which act like hyperlinks. You can use a Tree Node to navigate to another page by setting its url property. You can also use a Tree Node to submit the current page. If the the Tree Node's action property is bound to an action event handler, selecting the node automatically submits the page. If the Tree Node's actionListener property is bound to an action listener, opening or closing the node automatically submits the page. You set Tree Node properties in the Tree Node Component Properties window.
* If you use this component to navigate between pages of a portlet, do not use the url property to link to a page. Instead, use the Navigation editor to set up your links to pages.
* Events related to tree node selection do not work correctly in portlets because the component uses cookies to pass the selected node id back and forth, and cookies are not correctly handled by the portlet container. You cannot handle tree node selection events in portlet projects.
Initially when you drop a tree on a page, it has one root node labeled Tree and one subnode labeled Tree Node 1. You can add more nodes by dragging them to the tree and dropping them either on the root node to create top level nodes or on existing nodes to create subnodes of those nodes. You can also right-click the Tree or any Tree Node and choose Add Tree Node to add a subnode to the node.
Additionally, you can work with the component in the Outline window, where the component and its child components are available as nodes. You can move a node from level to level easily in the Outline window, so you might want to work there if you are rearranging nodes. You can also add and delete tree nodes in the Outline window, just as in the Visual Designer.
The Tree component has properties that, among other things, enable you change the root node's displayed text, change the appearance of the text, specify if expanding or collapsing a node requires a trip to the server, and specify whether node selection should automatically open or close the tree. To set the Tree's properties, select the Tree component in your page and use the Tree Component Properties window.
The following Tutorial ("Using Tree Component") is very useful to learn using Tree components
http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/sitemaptree.html
See Also the Technical Article - "Working with the Tree Component and Tree Node Actions"
http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/tree_component.html
Tree Node Component
You can drag the Tree Node component from the Palette's Basic category to a Tree component or another tree node in the Visual Designer to create a node in a hierarchical tree structure, similar to the tree you see in the Outline window.
The tree node is created as a subnode of the node on which you drop it. If you drop the node on the tree component itself, a new node is created as a child of the root node. You can see the hierarchical structure clearly in the Outline window, where you can also easily move nodes around and reparent them.
You can also add a tree node either to a Tree component or to a Tree Node component by right-clicking the component and choosing Add Tree Node.
A Tree Node component by default is a container for an image and can be used to navigate to another page, submit the current page, or simply open or close the node if the node has child nodes.
* If you select the Tree Node component's node Tree Node icon in the Outline window, you can edit its properties in the Tree Node Properties window. You can set things like whether or not the Tree Node is expanded by default, the tooltip for the Tree Node, the label for the tree node, and the Tree Node's identifier in your web application.
* You can use a Tree Node to navigate to another page by setting its url property. You can also use a Tree Node to submit the current page. If the the Tree Node's action property is bound to an action event handler, selecting the node automatically submits the page. If the Tree Node's actionListener property is bound to an action listener, opening or closing the node automatically submits the page.
- Note: If you use this component to navigate between pages of a portlet, do not use the url property to link to a page. Instead, use the Navigation editor to set up your links to pages. In addition, events related to tree node selection do not work correctly in portlets because the component uses cookies to pass the selected node id back and forth, and cookies are not correctly handled by the portlet container. You cannot handle tree node selection events in portlet projects.
* If you select the image in the Tree Node, you can see that its icon property is set to TREE_DOCUMENT. If you right-click the image on the page and choose Set Image, you can either change the icon to another one or choose your own image in the Image Customizer dialog box. For more information on working with an image in a tree node, see Image component.
- Note: The image used in a tree node works best if it is 16x16 or smaller. Larger images can work, but might appear overlapped in the Visual Designer. You can right-click the component and choose Preview in Browser feature to check the appearance of the images.
Please share your comments, experiences, additional information, questions, feedback, etc. on these components.
------------------------------------------------------------------------------- --------------------One challenge I had experience was to make the tree
always expanded on all pages (I placed my tree menu
in a page fragment so I can just import it in my
pages).Did you solve this problem. It would be interesting to know what you did.
To expand a node you call setExpanded on the node. Here is some code from a tutorial that a coworker of mine is working on.
In the prerender method:
Integer expandedPersonId = getRequestBean1().getPersonId();
// If expandedPersonId is null, then we are not coming back
// from the Trip page. In that case we do not want any trip
// nodes to be pre-selected (highlighted) due to browser cookies.
if (expandedPersonId==null) {
try {
HttpServletRequest req =(HttpServletRequest)
getExternalContext().getRequest();
Cookie[] cookies = req.getCookies();
//Check if cookies are set
if (cookies != null) {
for (int loop =0; loop < cookies.length; loop++) {
if (cookies[loop].getName().equals
("form1:displayTree-hi")) {
cookies[loop].setMaxAge(0);
HttpServletResponse response =(HttpServletResponse)
getExternalContext().getResponse();
response.addCookie(cookies[loop]);
} catch (Exception e) {
error("Failure trying to clear highlighting of selected node:" +
e.getMessage());
} ... (in a loop for tree nodes)...
personNode.setExpanded(newPersonId.equals
(expandedPersonId));In the action method for the nodes:
// Get the client id of the currently selected tree node
String clientId = displayTree.getCookieSelectedTreeNode();
// Extract component id from the client id
String nodeId = clientId.substring(clientId.lastIndexOf(":")+1);
// Find the tree node component with the given id
TreeNode selectedNode =
(TreeNode) this.getForm1().findComponentById(nodeId);
try {
// Node's id property is composed of "trip" plus the trip id
// Extract the trip id and save it for the next page
Integer tripId = Integer.valueOf(selectedNode.getId().substring(4));
getRequestBean1().setTripId(tripId);
} catch (Exception e) {
error("Can't convert node id to Integer: " +
selectedNode.getId().substring(4));
return null;
It would also be great if I can set the tree
readonly where the user cannot toggle the expand
property of the tree (hope this can be added to the
tree functionality). -
Help:create tree node dynamically from java code...
hi there...can anyone give me solution how to create or add tree node dynamically from java code???
currently i am using tree node to handle my menu...i try to create tree and add treenode dynamically from .java page, but it failed...can anyone give solution how to create tree ui from java code, so i can create a dynamic menu...thanz before...Hi:
Just put the statements you would normally put on a sqlplus command line in jdbc statements and execute them?
http://www-db.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html#0.1_executeUpdate
MJG -
Hi,
I am using the class cl_gui_alv_tree_simple, I need to add a node after tree displayed in the screen?
I tried to use method TREE_ADD_NODE , but this found protected.
Thanks
aRsHi,
You can use this method
DATA obj_tree1 TYPE REF TO cl_gui_alv_tree.
CALL METHOD obj_tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = rs_main
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
Hope this will solve your problem.
Award points if it helps.
-Gaurang -
Problems in creating a preorder tree node arraylist
Hi, i want to create an arraylist containing a preorder tree node's name, the program compiled well but every time it gives error when i press the "Output Preorder" button to create the arraylist, the following is the code, can someone help? Thanks a lot!!
JButton outputPreorderButton = new JButton("Output Preorder");
outputPreorderButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
for (Enumeration evev = tableTreeRootNode.preorderEnumeration() ; evev.hasMoreElements() ;) {
System.out.println(evev.nextElement());
String s = (String)evev.nextElement();
tableTreeNodesArray.add(s);Yeah, well, it will "give error" (as you so precisely and informatively say) if there's an odd number of nodes in your tree. Consider your code:System.out.println(evev.nextElement());
// Get element number 1 and print it.
String s = (String)evev.nextElement();
tableTreeNodesArray.add(s);
// Get element number 2 and add it to the list.So, the odd-numbered elements you print. The even-numbered elements you add to the list. If it happens there are 31 nodes, then an error will occur when you try to get node 32. -
I add some node to a tree but it is not shown in web page.
Hi
thank you for reading my post.
I read some tutorial in the web and i add some tree node to a tree dynamically.
but none of them is shown :(.
I should say that i write the code that create a tree in session scope bean because my tree is placed in a fragment and fragment has no preRender method.
here is code that initiate a tree, and i think it is correct.
public void initiateTree() {
getTree1().setClientSide(true);
System.out.println("Setter called");
Context ctx=null;
DataSource ds=null ;
Connection con=null ;
Statement st = null ;
List rootMenuItems = new ArrayList();
ResultSet rs = null;
try {
ctx = new InitialContext();
ds= (DataSource) ctx.lookup("java:comp/env/jdbc/dataSource");
con= ds.getConnection();
st= con.createStatement();
} catch (Exception ex) {
ex.printStackTrace();
try {
java.sql.PreparedStatement childsPSt = con.prepareStatement("select * from categories where parentcategory = ?");
rs= st.executeQuery("select * from categories where parentcategory= 0 and language = " +"'"+getLang()+"'");
//roots
while(rs.next()){
int parentID = rs.getInt("categoryID");
System.out.println("A root has been added "+parentID );
TreeNode aRootNode = new TreeNode();
aRootNode.setText(rs.getString("categoryname"));
//childs
childsPSt.setInt(1,parentID);
ResultSet cRs = childsPSt.executeQuery();
while(cRs.next()){
System.out.println("Achild has been added "+ cRs.getString("categoryname")+ " " + parentID);
TreeNode childNode = new TreeNode();
childNode.setText(cRs.getString("categoryname"));
aRootNode.getChildren().add(childNode);
getTree1().getChildren().add(aRootNode);
} catch (SQLException ex) {
ex.printStackTrace();
I call this method in session bean constructor.
here is code that bind the tree in page fragment to session bean tree1
<ui:tree binding="#{SessionBean1.tree1}" id="tree1" style="height: 167px"/>here is console output that prove the initiate method do some works.
Setter called
A root has been added 1
Achild has been added cat name 2 1
Achild has been added cat name 3 1
A root has been added 5i think u need to add hyperlink component to the node thus cause node must carry hyperlink or anything u like to add like staticText or checkBox ....
add this code after creation the aRootNode and childNode
it may works :)
Hyperlink h = new Hyperlink();
h.setText(cRs.getString("categoryname"));
childNode .getFacets().put( childNode .CONTENT_FACET_KEY, h ); -
How to add child node in Tree table programmetically
Jdev Version 11.1.1.4.0.
I have created tree table programmetically in bean.
I have to add child node to tree table component on button click event on page.
Please let me know how to do this in bean.
Regards,
KiranHow are you creating the tree pro-grammatically?
If you are adding a new node to underlying data structure and refresh the tree - the tree will get updated with the new data.
Thanks,
Navaneeth -
Add/Edit/Delete Tree Nodes using CL_GUI_ALV_TREE
Hi All,
I am looking for an example of program with CL_GUI_ALV_TREE that have a functionality of add a tree node, edit a tree node, and delete a tree node.
I have already looked the BCALV_TREE* demo program but could not able to find a program to add/edit/delete node tree elements.
Any info on this.
Thanks
aRsHello aRs
Here is a sample report showing how to delete nodes in an ALV tree. The report was copied from BCALV_TREE_01. Search for added code:
*$ADDED: begin
*$ADDED: end[/code]
When you display the tree expand the first folder completely. When entering 'DELETE' into the command field directly the first flight date node will be deleted.
REPORT ZUS_SDN_BCALV_TREE_01_DELNODE.
based on: REPORT bcalv_tree_01.
Purpose:
~~~~~~~~
This report shows the essential steps to build up a hierarchy
using an ALV Tree Control (class CL_GUI_ALV_TREE).
Note that it is not possible to build up this hierarchy
using a simple ALV Tree Control (class CL_GUI_ALV_TREE_SIMPLE).
To check program behavior
~~~~~~~~~~~~~~~~~~~~~~~~~
Start this report. The hierarchy tree consists of nodes for each
month on top level (this level can not be build by a simple ALV Tree
because there is no field for months in our output table SFLIGHT.
Thus, you can not define this hierarchy by sorting).
Nor initial calculations neither a special layout has been applied
(the lines on the right do not show anything).
Note also that this example does not build up and change the
fieldcatalog of the output table. For this reason, all fields
of the output table are shown in the columns although the fields
CARRID and FLDATE are already placed in the tree on the left.
(Of course, this is not a good style. See BCALV_TREE_02 on how to
hide columns).
Essential steps (Search for '§')
~~~~~~~~~~~~~~~
1.Usual steps when using control technology.
1a. Define reference variables.
1b. Create ALV Tree Control and corresponding container.
2.Create Hierarchy-header
3.Create empty Tree Control
4.Create hierarchy (nodes and leaves)
4a. Select data
4b. Sort output table according to your conceived hierarchy
4c. Add data to tree
5.Send data to frontend.
6.Call dispatch to process toolbar functions
*$ADDED: begin
DATA:
gd_del_nkey TYPE lvc_nkey.
*$ADDED: end
§1a. Define reference variables
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
g_custom_container TYPE REF TO cl_gui_custom_container.
DATA: gt_sflight TYPE sflight OCCURS 0, "Output-Table
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm, "OK-Code
g_max TYPE i VALUE 255.
END-OF-SELECTION.
CALL SCREEN 100.
*& Module PBO OUTPUT
process before output
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAINTITLE'.
IF g_alv_tree IS INITIAL.
PERFORM init_tree.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Automation Queue failure'(801)
txt1 = 'Internal error:'(802)
txt2 = 'A method in the automation queue'(803)
txt3 = 'caused a failure.'(804).
ENDIF.
ENDIF.
ENDMODULE. " PBO OUTPUT
*& Module PAI INPUT
process after input
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
*$ADDED: begin
WHEN 'DELETE'.
CALL METHOD g_alv_tree->delete_subtree
EXPORTING
i_node_key = gd_del_nkey
I_UPDATE_PARENTS_EXPANDER = SPACE
i_update_parents_folder = 'X'
EXCEPTIONS
node_key_not_in_model = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD g_alv_tree->frontend_update.
*$ADDED: end
WHEN OTHERS.
§6. Call dispatch to process toolbar functions
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " PAI INPUT
*& Form init_tree
text
--> p1 text
<-- p2 text
FORM init_tree.
§1b. Create ALV Tree Control and corresponding Container.
create container for alv-tree
DATA: l_tree_container_name(30) TYPE c.
l_tree_container_name = 'CCONTAINER1'.
CREATE OBJECT g_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'(100).
ENDIF.
create tree control
CREATE OBJECT g_alv_tree
EXPORTING
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
§2. Create Hierarchy-header
The simple ALV Tree uses the text of the fields which were used
for sorting to define this header. When you use
the 'normal' ALV Tree the hierarchy is build up freely
by the programmer this is not possible, so he has to define it
himself.
DATA l_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
§3. Create empty Tree Control
IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
(even after this method call). You can change data of your table
by calling methods of CL_GUI_ALV_TREE.
Furthermore, the output table 'gt_outtab' must be global and can
only be used for one ALV Tree Control.
CALL METHOD g_alv_tree->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_hierarchy_header = l_hierarchy_header
CHANGING
it_outtab = gt_sflight. "table must be empty !
§4. Create hierarchy (nodes and leaves)
PERFORM create_hierarchy.
§5. Send data to frontend.
CALL METHOD g_alv_tree->frontend_update.
wait for automatic flush at end of pbo
ENDFORM. " init_tree
*& Form build_hierarchy_header
build hierarchy-header-information
-->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Month/Carrier/Date'(300).
p_hierarchy_header-tooltip = 'Flights in a month'(400).
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ' '.
ENDFORM. " build_hierarchy_header
*& Form exit_program
free object and leave program
FORM exit_program.
CALL METHOD g_custom_container->free.
LEAVE PROGRAM.
ENDFORM. " exit_program
*& Form create_hierarchy
text
--> p1 text
<-- p2 text
FORM create_hierarchy.
DATA: ls_sflight TYPE sflight,
lt_sflight TYPE sflight OCCURS 0,
l_yyyymm(6) TYPE c, "year and month of sflight-fldate
l_yyyymm_last(6) TYPE c,
l_carrid LIKE sflight-carrid,
l_carrid_last LIKE sflight-carrid.
DATA: l_month_key TYPE lvc_nkey,
l_carrid_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey.
§4a. Select data
SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS.
§4b. Sort output table according to your conceived hierarchy
We sort in this order:
year and month (top level nodes, yyyymm of DATS)
carrier id (next level)
day of month (leaves, dd of DATS)
SORT lt_sflight BY fldate0(6) carrid fldate6(2).
Note: The top level nodes do not correspond to a field of the
output table. Instead we use data of the table to invent another
hierarchy level above the levels that can be build by sorting.
§4c. Add data to tree
LOOP AT lt_sflight INTO ls_sflight.
Prerequesite: The table is sorted.
You add a node everytime the values of a sorted field changes.
Finally, the complete line is added as a leaf below the last
node.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
Top level nodes:
IF l_yyyymm <> l_yyyymm_last. "on change of l_yyyymm
l_yyyymm_last = l_yyyymm.
*Providing no key means that the node is added on top level:
PERFORM add_month USING l_yyyymm
CHANGING l_month_key.
The month changed, thus, there is no predecessor carrier
CLEAR l_carrid_last.
ENDIF.
Carrier nodes:
(always inserted as child of the last month
which is identified by 'l_month_key')
IF l_carrid <> l_carrid_last. "on change of l_carrid
l_carrid_last = l_carrid.
PERFORM add_carrid_line USING ls_sflight
l_month_key
CHANGING l_carrid_key.
ENDIF.
Leaf:
(always inserted as child of the last carrier
which is identified by 'l_carrid_key')
PERFORM add_complete_line USING ls_sflight
l_carrid_key
CHANGING l_last_key.
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form add_month
FORM add_month USING p_yyyymm TYPE c
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight,
l_month(15) TYPE c. "output string for month
get month name for node text
PERFORM get_month USING p_yyyymm
CHANGING l_month.
l_node_text = l_month.
add node:
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_carrid_line'
the leaf gets a child and thus ALV converts it to a folder
automatically.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_month
FORM add_carrid_line USING ps_sflight TYPE sflight
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight.
add node
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_carrid_line'
the leaf gets a child and thus ALV converts it to a folder
automatically.
l_node_text = ps_sflight-carrid.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_carrid_line
*& Form add_complete_line
FORM add_complete_line USING ps_sflight TYPE sflight
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value.
WRITE ps_sflight-fldate TO l_node_text MM/DD/YYYY.
add leaf:
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set.
Since these nodes will never get children they stay leaves
(as intended).
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = ps_sflight
i_node_text = l_node_text
IMPORTING
e_new_node_key = p_node_key.
*$ADDED: begin
IF ( ps_sflight-fldate = '20040522' ). " first flight date
IF ( gd_del_nkey IS INITIAL ). " collect only first date
gd_del_nkey = p_node_key.
ENDIF.
ENDIF.
*$ADDED: end
ENDFORM. " add_complete_line
*& Form GET_MONTH
text
-->P_P_YYYYMM text
<--P_L_MONTH text
FORM get_month USING p_yyyymm
CHANGING p_month.
Returns the name of month according to the digits in p_yyyymm
DATA: l_monthdigits(2) TYPE c.
l_monthdigits = p_yyyymm+4(2).
CASE l_monthdigits.
WHEN '01'.
p_month = 'January'(701).
WHEN '02'.
p_month = 'February'(702).
WHEN '03'.
p_month = 'March'(703).
WHEN '04'.
p_month = 'April'(704).
WHEN '05'.
p_month = 'May'(705).
WHEN '06'.
p_month = 'June'(706).
WHEN '07'.
p_month = 'July'(707).
WHEN '08'.
p_month = 'August'(708).
WHEN '09'.
p_month = 'September'(709).
WHEN '10'.
p_month = 'October'(710).
WHEN '11'.
p_month = 'November'(711).
WHEN '12'.
p_month = 'December'(712).
ENDCASE.
CONCATENATE p_yyyymm+0(4) '->' p_month INTO p_month.
ENDFORM. " GET_MONTH
/code
Regards
Uwe -
How to add custom ADF Tree Node icon
Hi All,
i am using below code in style sheet to set the tree node icon,
af|tree::node-icon:nodetype-collapsed
but i don't have any idea how to add getnodetype() method in the node class, (I am using Jdeveloper 11.1.1.2.0). please suggest me the steps to achive it.
Thanks,
Maheshi did as you suggested, but i am not getting any image, below is my source
<nodeDefinition DefName="com.mahesh.SSCExplorer.model.ROview.OrdrHdrVO"
Name="OrdrHdr20"
TargetIterator="${bindings.OrdrHdr2Iterator}"
ClosedIcon="/Nuvola_filesystems_folder.png"
OpenIcon="/Nuvola_filesystems_folder.png"
Icon="/Nuvola_filesystems_folder.png">
please suggest is there any other settings i need to do.
Thanks,
Mahesh -
Letting a user add a node to a tree
Hi,
Currently I have a tree that is built dynamically with a
remote object call. Also, if the user clicks on a node, a menu pops
up allowing the user to create a child for the node. How do I let
the user add a node to the tree ? I saw tangential examples showing
how to add xml nodes, but I am unable to translate that to trees
that are populated NOT in static xml, but from a remote object
call.
I have the following function signature :
// parentIndex - the index of the parent node, where the user
wants to add a child node
// childLabel - the label for the child node.
private addChild(parentIndex:int, childLabel:String) {
Thanks for your help.Hi Tracy, this the code I am using from PeterEnt's blog. His
example was about drag-and-drop. I am trying to use it (maybe I
shouldn't:) for my child node insertion.
myTree.selectedIndex = parentIndex;
var node:XML = myTree.selectedItem as XML; // interestingly,
myTree.selectedItem is not null, but node is null. Why ?
var p:*;
if(myTree.dataDescriptor.hasChildren(node)) {
p = node;
parentIndex = 0;
else { // I am getting a null pointer exception here
p = node.parent();
var insert:XML = <node />;
insert.@label = "New Toy";
insert.@type = "Toy";
myTree.dataDescriptor.addChildAt(p, insert, parentIndex+1);
I am getting the parent value (label etc) correctly for
myTree.selectedItem. But when I do node:XML = myTree.selectedItem
as XML, I am getting null value for null. That's why I asked in my
first message if there is a difference in populating the data
statically as XML v.s. loading the data using remote object (which
is the case here).
Appreciate your help. -
JTreeTable problem editing tree node
Hi,
Iam using the swing JTreeTable component and facing a problem. Iam displaying hierarchical data in the JTreeTable. Now I would like to provide the facility to edit a tree node. I have a TreeSelectionListener registered on the tree and a TreeModelListener registered on the DefaultTreeModel. Wheneve, I start editing a node by double clicking it the valueChanged method is called but I do not see the new value the user types in this method. I have another method setValueAt which is where I can see the new value the user has entered.
I can set this new value to the treenode using
node.setUserObject(newValue);However, if I do this, the next time I try to edit the same node, the editor component is painted over the tree node thus displaying an empty textfield that occupies the entire cell.
How can I make the editor appear above the tree node with the contents loaded in it always.
Any help is appreciated.
cheers,
vidyutYou bind a mouselistener to the tree, so it has to be handled there.
When clicking once (method should be "mouseReleased" or something, treenodes name (toString) should be .setText("");
regards
marco -
How to resize a custom tree node like you would a JFrame window?
Hello,
I am trying to resize a custom tree node like you would a JFrame window.
As with a JFrame, when your mouse crosses the Border, the cursor should change and you are able to drag the edge to resize the node.
However, I am faced with a problem. Border cannot detect this and I dont want to use a mouse motion listener (with a large number of nodes, I fear it will be inefficient, calculating every node's position constantly).
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.util.EventObject;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;
public class ResizeNode extends JPanel {
AnilTreeCellRenderer2 atcr;
AnilTreeCellEditor2 atce;
DefaultTreeModel treeModel;
JTree tree;
DefaultMutableTreeNode markedNode = null;
public ResizeNode() {
super(new BorderLayout());
treeModel = new DefaultTreeModel(null);
tree = new JTree(treeModel);
tree.setEditable(true);
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setShowsRootHandles(true);
tree.setCellRenderer(atcr = new AnilTreeCellRenderer2());
tree.setCellEditor(atce = new AnilTreeCellEditor2(tree, atcr));
JScrollPane scrollPane = new JScrollPane(tree);
add(scrollPane,BorderLayout.CENTER);
public void setRootNode(DefaultMutableTreeNode node) {
treeModel.setRoot(node);
treeModel.reload();
public static void main(String[] args){
ResizeNode tb = new ResizeNode();
tb.setPreferredSize(new Dimension(400,200));
JFrame frame = new JFrame("ResizeNode");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(tb);
frame.setSize(400, 200);
frame.pack();
frame.setVisible(true);
tb.populate();
private void populate() {
TextAreaNode2 r = new TextAreaNode2(this);
setRootNode(r);
TextAreaNode2 a = new TextAreaNode2(this);
treeModel.insertNodeInto(a, r, r.getChildCount());
class AnilTreeCellRenderer2 extends DefaultTreeCellRenderer{
TreeBasic panel;
DefaultMutableTreeNode currentNode;
public AnilTreeCellRenderer2() {
super();
public Component getTreeCellRendererComponent
(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus){
TextAreaNode2 currentNode = (TextAreaNode2)value;
NodeGUI2 gNode = (NodeGUI2) currentNode.gNode;
return gNode.box;
class AnilTreeCellEditor2 extends DefaultTreeCellEditor{
DefaultTreeCellRenderer rend;
public AnilTreeCellEditor2(JTree tree, DefaultTreeCellRenderer r){
super(tree, r);
rend = r;
public Component getTreeCellEditorComponent(JTree tree, Object value,
boolean isSelected, boolean expanded, boolean leaf, int row){
return rend.getTreeCellRendererComponent(tree, value, isSelected, expanded,
leaf, row, true);
public boolean isCellEditable(EventObject event){
return true;
class NodeGUI2 {
final ResizeNode view;
Box box = Box.createVerticalBox();
final JTextArea aa = new JTextArea( 1, 5 );
final JTextArea aaa = new JTextArea( 1, 8 );
NodeGUI2( ResizeNode view_ ) {
this.view = view_;
box.add( aa );
aa.setBorder( BorderFactory.createMatteBorder( 0, 0, 1, 0, Color.GREEN ) );
box.add( aaa );
box.setBorder( BorderFactory.createMatteBorder( 5, 5, 5, 5, Color.CYAN ) );
private Dimension getEditorPreferredSize() {
Insets insets = box.getInsets();
Dimension boxSize = box.getPreferredSize();
Dimension aaSize = aa.getPreferredSize();
Dimension aaaSize = aaa.getPreferredSize();
int height = aaSize.height + aaaSize.height + insets.top + insets.bottom;
int width = Math.max( aaSize.width, aaaSize.width );
if ( width < boxSize.width )
width += insets.right + insets.left + 3; // 3 for cursor
return new Dimension( width, height );
class TextAreaNode2 extends DefaultMutableTreeNode {
NodeGUI2 gNode;
TextAreaNode2(ResizeNode view_) {
gNode = new NodeGUI2(view_);
}the node on the tree is only painted on using the
renderer to do the painting work. A mouse listener
has to be added to the tree, and when moved over an
area, you have to determine if you are over the
border and which direction to update the cursor and
to know which way to resize when dragged. One of the
BasicRootPaneUI has some code that can help determine
that.Thanks for replying. What is your opinion on this alternative idea that I just had?
I am wondering if it might be easier to have a toggle button in the node that you click when you want to resize the node. Then a mouse-down and dragging the mouse will resize the node. Mouse-up will reset the toggle button, and so will mouse down in an invalid area.
Anil
Maybe you are looking for
-
Date funkcion in AS oracle forms
Hi all I'm DBA and I had question from our developers about AS and forms. We wont to have applications server in one server (SRV1)and db in another server(DB2) , can You help me witch date function in forms depend on system time of SRV1 and which of
-
Combining supported files by number
Hello. I'm new to this community and to the adobe software. I've tried searching for similar posts, but couldn't find any. Kindly help me out I have more than 50 numbered images and I'm trying to combine them to make a pdf file, but they don't get li
-
HT1694 hotmail account Sync problems with my iMAc . H
Hi really strange problem, i receive hotmail account emails wit "Mail" but whatever action i do on it , like read , delete etc.. doesnt reflect on Hotmail Server ( hotmail web page) That problems is not reflected on my iphone or ipad. Thnks Rubén.
-
Hold Button in Purchase Requisition
Hello All, I want to creat an PR and want to put on "HOLD". but the Hold Button is missing in PR (As we get in PO). Please suggest. Cheers, Mansih Jindal
-
Struggling to embed a .swf object in DW CS5
So I just got CS5, after upgrading from CS3 and have basically spent a whole week figuring out my old workflows. The following problem has stumped me for the past 2 hours, and I can't seem to fix it. I have a basic html file with a table. In the tabl