0

I want to catch events on link click on node. I know how to set link click on column item, it's like:

DATA: ls_layout TYPE lvc_s_layi,
      lt_layout TYPE lvc_t_layi.

ls_layout-fieldname = 'Fieldname from table passing to alv tree'.
ls_layout-class = cl_gui_column_tree=>item_class_link.
APPEND ls_layout to lt_layout.

 o_cl_gui_tree->add_node(
    EXPORTING
      "other parameters...
      it_item_layout       = lt_layout
      "other parameters...
  ).

But I don't know how to set link click on node. Could you help me? Thanks.

miskohut
  • 957
  • 1
  • 14
  • 34
  • Is there a chance to switch to the SALV tree? Its event handling mechanism is a bit easier (and it is officially supported, which I always consider an added bonus). – vwegert Jul 09 '15 at 08:36
  • I originally used cl_salv_tree but i wasn't able to add context menu so i switched to cl_gui_alv_tree. I have found this: https://scn.sap.com/thread/160991 saying that node text should by type link., but link is a structure. – miskohut Jul 09 '15 at 08:53

1 Answers1

0

I cannot understand, what should be difficult/different in this event-handling case compared to all other event-handling practices. But perhaps it is my own fault. So, let's do it, stepwise, together. Watch and learn. :-)

The definition for the event receiver can look like:

CLASS lcl_tree_event_receiver DEFINITION.
PUBLIC SECTION.
.
.
.
 METHODS handle_link_click
  FOR EVENT link_click OF cl_gui_alv_tree
  IMPORTING node_key
            fieldname.

ENDCLASS.

Let us implement the class.

CLASS lcl_tree_event_receiver IMPLEMENTATION.
.
.
.
 METHOD handle_link_click.
    " Do whatever You want in here. 
ENDMETHOD.                    "handle_link_click
ENDCLASS.

The activation of the tree events should pass the proper ID

  DATA: lt_events TYPE cntl_simple_events,
  l_event   TYPE cntl_simple_event.
  .
  .
  l_event-eventid = cl_gui_column_tree=>EVENTID_LINK_CLICK.
  " yes, that works, in fact this constant is inside 
  " CL_ITEM_TREE_CONTROL

  APPEND l_event TO lt_events.
   CALL METHOD go_main_tree->set_registered_events
EXPORTING
  events                    = lt_events
EXCEPTIONS
  cntl_error                = 1
  cntl_system_error         = 2
  illegal_event_combination = 3.

And finally we instantiate the handler class and register the handlers, which can look like:

  DATA: l_tree_event_receiver TYPE REF TO lcl_tree_event_receiver.
  CREATE OBJECT   l_tree_event_receiver.


   SET HANDLER l_tree_event_receiver->handle_link_click.
   FOR go_main_tree.

If you want to check, what worked for setting events, call

   CALL METHOD go_main_tree->get_registered_events
   IMPORTING
     events = lt_events.
icbytes
  • 1,831
  • 1
  • 17
  • 27
  • yes but you also have to specify on what you want the link click. If I do it like you suggest it will do nothing. You specify it in parameter it_item_layout in add_node method of cl_gui_alv_tree class. But I was only able to enable link click on node structure not node itself. – miskohut Jul 14 '15 at 05:15
  • Why do you even want to set a link click on a node? Is there a specific reason for not to handle it via on node click? – icbytes Jul 14 '15 at 10:43
  • There's no other event in cl_gui_alv_tree for this. There's double click, link click, and selection changed. And selection changed doesn't suit me. – miskohut Jul 14 '15 at 11:11
  • Then I am afraid, there is no other solution. A klick on a node for itself expands the node. You are now only left with try and error, like try left klick design and left click run . Perhaps You can also trace and debug, what a klick on a node internally does, inherit from cl_gui_alv_tree and redefine the proper handler. – icbytes Jul 14 '15 at 11:56
  • I also played with an idea of checking on selection changed but the event was triggered also when opening context menu with right click ... an it was mess ... If I were able to catch context menu closing it would do the thing. ... – miskohut Jul 14 '15 at 12:45
  • If you do not need context Menu then do not subscribe to it. – icbytes Jul 14 '15 at 14:14