cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the folder name of selected subitem in tree structure?

Former Member
0 Kudos

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,

Ravi

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi 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.

Former Member
0 Kudos

Hi Bhargav,

In a tree structure you can retrieve the selected(clicked ) value you should use these two methods.

data:

lo_elem_tree1 type ref to if_wd_context_element.

call method wdevent->get_context_element

exporting

name = 'CONTEXT_ELEMENT'

receiving

value = lo_elem_tree1.

call method lo_elem_tree1->get_static_attributes

importing

static_attributes = wd_this->gs_child_elem.

here wd_this->gs_child_elem contains the selected column(folder) value.

wd_this->gs_child_elem is of type your table(tree table).

Regards

Madhu.

Edited by: Madhavi Latha Puchakayala on Jan 27, 2009 9:20 AM

arjun_thakur
Active Contributor
0 Kudos

Hi Bhargava,

You can also refer to the standard component WDR_TEST_EVENTS. Look for TREE_RECUR_DYNLOAD and TREE_RECURSIVE views. It will give you some idea.

Regards

Arjun

pranav_nagpal2
Contributor
0 Kudos

Hi Bhargava,

Refer this link

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/8d/088b41b4b3b25fe10000000a1550b0/frameset.htm

When you trigger any event, event handler will have the reference to the context element and the tree path

for context element refrence this is the code... now you have to bind your onaction event of folder with any event say click and there write the below code.......

data: lv_element type ref to if_wd_context_element,
         index type i.
 
  lv_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT'  ).
  index = lr_element->get_index( ).

now if you click on first folder 1 will be the value in index..... if you click on second folder 2 will be the value in index....... so this way you can identify which node is clicked......

for tree path and id check this link......

refer this link for more detail..............

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/af/4bae42e5adcd6ae10000000a155106/frameset.htm

regards

Pranav

Edited by: Pranav Nagpal on Jan 21, 2009 9:30 AM

Former Member
0 Kudos

Hi Arjun,

as per reply,what i understood is,we will get the index of respective folder when cilck on that folder.

But my reqirement is i need to get the folder name when i click on the values in the folder.

For suppose ,As i said above ,i have the value 2 in both the folders.At run time i may click any 2 (i.e it may folder1 or folder2 ).

How can i know the folder name on which 2 ( value in the folder ) i clicked.

Plz let me correct if i may wrong..........

Regards,

Ravi

pranav_nagpal2
Contributor
0 Kudos

Hi Bhargava,

please see the code below

method ONACTIONCLICK .

data: lv_element type ref to if_wd_context_element,
      lv TYPE string,
         index type i.

  lv_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
  index = lv_element->get_index( ).

    DATA lo_nd_folder TYPE REF TO if_wd_context_node.

    DATA lo_el_folder TYPE REF TO if_wd_context_element.
    DATA ls_folder TYPE wd_this->element_folder.
    DATA lv_name TYPE wd_this->element_folder-name.

*   navigate from <CONTEXT> to <FOLDER> via lead selection
    lo_nd_folder = wd_context->path_get_node( path =
`TREE_ROOT.FOLDER` ).

*   @TODO handle non existant child
*   IF lo_nd_folder IS INITIAL.
*   ENDIF.

*   get element via lead selection
    lo_el_folder = lo_nd_folder->get_element( ).
*   alternative access  via index
   lo_el_folder = lo_nd_folder->get_element( index = index )." you have index and you can pass it here 
  "to get the value of the attribute

    IF lo_el_folder IS INITIAL.
    ENDIF.

*   get single attribute
    lo_el_folder->get_attribute(
      EXPORTING
        name =  `NAME`
      IMPORTING
        value = lv_name ).



endmethod.

this will return you name of the folder in lv_name

regards

Pranav

arjun_thakur
Active Contributor
0 Kudos

Hi,



   data:  name type string.
  name = wdevent->GET_string( 'ID' ).

Use this code in ONACTION method of your treenodetype UI element (the method which is invoked when you click on any folder name). This will give your the ID of the UI element.

Regards

Arjun

Edited by: Arjun on Jan 21, 2009 5:05 PM

Former Member
0 Kudos

Hi Pranav,

I tried as you said.But i didnt get the folder name.

My tree structure is like this.

>A-

>B-1

2

3

>C-4

5

6..

The root folder is A.Under folder A i have multiple folders like B,C,D....

And the sub folders(B,C, D....) under the Root folder(A).have the values like above.I need to perform a action whenever i click any value of the subfolder.

What i need is ,Under which sub folder, the user clicked...

Please help me to resolve this........

Regards,

Ravi