cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the action OnExpandAll on UI element Tree

Former Member
0 Kudos

Hi, experts .

I am in WDA developing project and developing the screen which has Tree .

I want to expand all nodes when users click the button on the head of Tree .

I copied the application `WDT_TREE` and created Tree of my application successfully .

And I created the action OnExpandAll on my Tree and tried to create the function to expand all nodes .

But I do not know how to use the action OnExpandAll .

I can see the button to start action OnExpandAll on the head of Tree .

I am trying to write logic in the action . But it does not work successfully .

(In my tree , when I click the button for OnExpandAll , all nodes are outputted on root node .

Because my logic is wrong ... )

Please give me any hints .

Masao

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank you for your kindfull replies .

But expanded properties are already set by my tree program .

I do not understand about data set logic .

- In the application of `WDT_TREE` , the method CREATE_NODE in the controller VIEW1 set data from wd_this->mt_file_struc to the recursion node 'FOLDER_CONTENT' which is gotten from parameter CUR_ELEMENT .

CUR_ELEMENT is called from CONTEXT_ELEMENT which is made when users click a node on tree . ( CONTEXT_ELEMEN is input parameter of event handler which is set on UI element TreeNodeType . That has the lead selection of clicked entry of Tree . So , in event handler ONACTIONLOAD_CHILDREN can call the recursion node 'FOLDER_CONTENT' of which instance is created .)

- In case of OnAllExpand action , CONTEXT_ELEMENT is not specified . So , the action OnExpandAll have to make element .

- I tried to write sentences to create the recursion node 'FOLDER_CONTENT' . I can create an element instance , but I can not create node instance under the element instance. How can I do that ? Or my process like above is all wrong ?

method OnExpandAll .

  • create the child nodes

" I cannot write like below ,because context_element is initial

  • create_node(

  • exporting

  • cur_element = context_element

  • parent_key = parent_key ).

" so I tried to create element . But I think my logic is wrong

DATA:

lr_fol_node TYPE REF TO if_wd_context_node,

lr_element TYPE REF TO if_wd_context_element,

lr_cur_node TYPE REF TO if_wd_context_node.

lr_fol_node = wd_context->get_child_node( `FOLDER` )

lr_element = lr_fol_node->create_element( ) .

  • the below is not right , because the node is not created

  • lr_cur_node = lr_element->get_child_node( 'FILE' ).

  • .... Where is the method `CREATE_NODE` in IF_WD_CONTEXT_ELEMENT ???

Do I need to change the setting of a Cardinality ?

Masao

gill367
Active Contributor
0 Kudos

Hi

As your case it is a recursive node.

then you have to create method and call it recursively for the expanall functionality.

do it like this.

create an attribute the node FOLDER

name = 'ISEXPANDED'

type = WDY_BOOLEAN.

Now bind the property expanded of treenode FOLDER UI to this attribute.

now go to the methods tab and create one method say name ZEXPANDALL.

in thsi method make one importing parameter of type ( type ref to ) if_wd_context_node. and name NODE.

then write the following code in this method.

method ZEXPANDALL .
DATA ELT TYPE WDR_CONTEXT_ELEMENT_SET.
DATA EL TYPE REF TO IF_WD_CONTEXT_ELEMENT.
data nd type ref to if_wd_context_node.
data nds type WDR_CONTEXT_CHILD_MAP.
data chld type wdr_context_child.
data nf type ref to if_wd_context_node_info.
data name type string.
ELT = node->GET_ELEMENTS( ).

LOOP AT ELT INTO EL.
  EL->SET_ATTRIBUTE(
  NAME = 'ISEXPANDED'
  VALUE = ABAP_TRUE



  ).
  data parent_key type string.
EL->get_attribute( exporting name = 'TEXT' importing value
= parent_key ).

* create the child nodes
    create_node(
      exporting
        cur_element = EL
        parent_key  = parent_key ).

nds = el->get_child_nodes( ).
loop at nds into chld.
  nd ?= chld-node.
  nf = nd->get_node_info( ).
name  = nf->get_name( ).

if name eq 'FOLDER'.
  zexpandall(                             "recursive call
  nd
  ).
endif.

  endloop.



  ENDLOOP.
endmethod.

NOw go to your eventhandler created for action expandall.

there write the following code.

method ONACTIONEXPANDALL .
DATA lo_nd TYPE REF TO if_wd_context_node.



  lo_nd = wd_context->get_child_node( 'FOLDER' ).


  ZEXPANDALL( lo_nd ).

endmethod.

thats it.

Thanks

sarbjeet singh

Answers (4)

Answers (4)

Former Member
0 Kudos

Dear sarbjeet singh .

Thank you for your reply .

Your advise solved my problem .

Best Regards

Masao

Former Member
0 Kudos

Hi Masao,

Try the below code.

DATA: lo_nd TYPE REF TO if_wd_context_node,

lit_table TYPE wd_this->elements_ctx_result,

wa_table TYPE wd_this->element_ctx_result.

*-- Navigate from <CONTEXT> to <CTX_RESULT> via lead selection

lo_nd = wd_context->get_child_node( name = wd_this->wdctx_ctx_result ).

*-- Binding Values Back to Context

lo_nd->get_static_attributes_table( IMPORTING table = lit_table).

*-- Setting Expanded Context Element

LOOP AT lit_table INTO wa_table WHERE leaf = space OR leaf IS INITIAL.

wa_result-expanded = 'X'.

MODIFY lit_table FROM wa_table INDEX sy-tabix.

ENDLOOP.

*-- Binding the Changed data Context Node

lo_nd->bind_table( new_items = lit_table set_initial_elements = abap_true ).

Regards,

Simi A M

gill367
Active Contributor
0 Kudos

hi

You need to create an attribute of type wdy_boolean at all levels of the node and then set it true for all the elements

and bind this attribute to the expanded property of tree-node UI element.

for example i have this node

YEAR ahving month as the child node

then to expand all the instances of year node and child month node

i will create two attributes one under year and one under month.

so context structure will be like

YEAR
   ------  year_attribute (string)
   ------ Is_expanded ( wdy_boolean)
   ----------Month ( node )
   -------------- month_attribute( String)
   -------------- is_expanded ( wdy_boolean)

now for both nodes year and month uncheck the lead selected.

then bind the attribute is_expanded to the corresponding tree-node UI elements.

then create one action for onexpandall event and write the following code there.


  DATA lo_nd_year TYPE REF TO if_wd_context_node.
  DATA lo_el_year TYPE REF TO if_wd_context_element.
  DATA ls_year TYPE wd_this->element_year.
* navigate from <CONTEXT> to <YEAR> via lead selection
  lo_nd_year = wd_context->get_child_node( name = wd_this->wdctx_year ).

DATA ELT TYPE WDR_CONTEXT_ELEMENT_SET.
DATA EL TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA ND TYPE REF TO IF_wD_CONTEXT_NODE.
DATA ELT1 TYPE WDR_CONTEXT_ELEMENT_SET.
DATA EL1 TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA ND1 TYPE REF TO IF_wD_CONTEXT_NODE.


ELT = lo_nd_year->GET_ELEMENTS( ).
LOOP AT ELT INTO EL.
  EL->SET_ATTRIBUTE(
  NAME = 'IS_EXPANDED'
  VALUE = ABAP_TRUE
  ).
ND1 = EL->GET_CHILD_NODE( 'MONTH'  ).


ELT1 = ND1->GET_ELEMENTS( ).
LOOP AT ELT1 INTO EL1.
  EL1->SET_ATTRIBUTE(
  NAME = 'IS_EXPANDED'
  VALUE = ABAP_TRUE

  ).

  ENDLOOP.

  ENDLOOP.

this will expand the tree.

thanks

sarb

Former Member
0 Kudos

Hi Masao,

Please check this... It might helps you.

Cheers,

Kris.