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.