Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Control Framework tree control event not trigerring

Former Member
0 Kudos

The event handle_node_double_click is not trigerring on the tree controls . I want to display the contents of the nodes on the text editor on trigerring of this event

&----


*& Report ZCONTROLS_TREE_TEDIT_SPITTER

*&

&----


*&

*&

&----


REPORT zcontrols_tree_tedit_spitter.

DATA : editor TYPE REF TO cl_gui_textedit,

tree TYPE REF TO cl_gui_simple_tree.

DATA : container TYPE REF TO cl_gui_custom_container,

splitter TYPE REF TO cl_gui_easy_splitter_container,

right TYPE REF TO cl_gui_container,

left TYPE REF TO cl_gui_container.

DATA : node_itab LIKE node_str OCCURS 0.

----


  • CLASS EVENT_HANDLER DEFINITION

----


*

----


CLASS event_handler DEFINITION.

PUBLIC SECTION.

METHODS : handle_node_double_click

FOR EVENT NODE_DOUBLE_CLICK OF cl_gui_simple_tree

IMPORTING node_key.

ENDCLASS. "EVENT_HANDLER DEFINITION

----


  • CLASS EVENT_HANDLER IMPLEMENTATION

----


*

----


CLASS event_handler IMPLEMENTATION.

METHOD handle_node_double_click.

perform node_double_click using node_key.

ENDMETHOD. "HANDLE_NODE_DOUBLE_CLICK

ENDCLASS. "EVENT_HANDLER IMPLEMENTATION

data : handler1 type ref to event_handler.

START-OF-SELECTION.

CALL SCREEN 9001.

&----


*& Module start OUTPUT

&----


  • text

----


MODULE start OUTPUT.

SET PF-STATUS 'ZSTAT1'.

IF container IS INITIAL.

CREATE OBJECT container

EXPORTING

container_name = 'CONTAINER_NAME'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CREATE OBJECT splitter

EXPORTING

parent = container

orientation = 1

name = 'Mohit'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

left = splitter->top_left_container.

right = splitter->bottom_right_container.

CREATE OBJECT editor

EXPORTING

parent = right

name = 'MohitEditor'

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

gui_type_not_supported = 5

OTHERS = 6

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CREATE OBJECT tree

EXPORTING

parent = left

node_selection_mode = tree->node_sel_mode_single

name = 'MohitTree'

EXCEPTIONS

lifetime_error = 1

cntl_system_error = 2

create_error = 3

failed = 4

illegal_node_selection_mode = 5

OTHERS = 6

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

PERFORM fill_tree.

CALL METHOD tree->add_nodes

EXPORTING

table_structure_name = 'NODE_STR'

node_table = node_itab

EXCEPTIONS

error_in_node_table = 1

failed = 2

dp_error = 3

table_structure_name_not_found = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

create object handler1.

set handler handler1->handle_node_double_click for tree.

ENDIF.

ENDMODULE. " start OUTPUT

&----


*& Module USER_COMMAND_9001 INPUT

&----


  • text

----


MODULE user_command_9001 INPUT.

CALL METHOD cl_gui_cfw=>dispatch.

ENDMODULE. " USER_COMMAND_9001 INPUT

&----


*& Form fill_tree

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_tree .

DATA : node LIKE node_str.

CLEAR node.

node-node_key = 'head_mohit'.

node-isfolder = 'X'.

node-text = 'Mohit'.

APPEND node TO node_itab.

CLEAR node.

node-node_key = 'Child1'.

node-relatkey = 'head_mohit'.

node-relatship = cl_gui_simple_tree=>relat_last_child.

node-text = 'Mohit is the best '.

APPEND node TO node_itab.

CLEAR node.

node-node_key = 'Child2'.

node-relatkey = 'head_mohit'.

node-relatship = cl_gui_simple_tree=>relat_last_child.

node-text = 'Mohit is the bestest '.

APPEND node TO node_itab.

CLEAR node.

node-node_key = 'head_JAIN'.

node-isfolder = 'X'.

node-text = 'jAIN'.

APPEND node TO node_itab.

CLEAR node.

node-node_key = 'Child3'.

node-relatkey = 'head_JAIN'.

node-relatship = cl_gui_simple_tree=>relat_next_sibling.

node-text = 'cnh INDIA '.

APPEND node TO node_itab.

CLEAR node.

node-node_key = 'Child4'.

node-relatkey = 'head_JAIN'.

node-relatship = cl_gui_simple_tree=>relat_last_child.

node-text = 'SAP '.

APPEND node TO node_itab.

ENDFORM. " fill_tree

&----


*& Form node_double_click

&----


  • text

----


  • -->P_NODE_KEY text

----


form node_double_click using p_node_key type TV_NODEKEY.

DATA : node LIKE node_str.

DATA textline(256).

DATA text_table LIKE STANDARD TABLE OF textline.

READ TABLE node_itab WITH KEY node_key = p_node_key

INTO node.

endform. " node_double_click

&----


*& Module exit INPUT

&----


  • text

----


module exit input.

CASE sy-ucomm.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

endmodule. " exit INPUT

2 REPLIES 2

Former Member
0 Kudos

Hi,

You have to register the event using SET HANDLER,

check out BCALV_TREE_02 for how to set events using SET HANDLER.

Regards,

Raghavendra

uwe_schieferstein
Active Contributor
0 Kudos

Hello Mohit

Here is a sample routine (taken from BCALV_TREE_02) which you have to add and adapt for your report. It does two things:

1. Register events that should be handled (required but not sufficient for event handling)

2. Set event handler for registered events

The first step is different from ALV grid controls because here all events are already registered with the control (not the control framework).

Set the event handler (statement SET HANDLER) registers the event handling with the control framework.

FORM register_events.
*§4. Event registration: tell ALV Tree which events shall be passed
*    from frontend to backend.
  DATA: lt_events TYPE cntl_simple_events,
        l_event TYPE cntl_simple_event,
        l_event_receiver TYPE REF TO lcl_tree_event_receiver.

*§4a. Frontend registration(i):  get already registered tree events.
*................................................................
* The following four tree events registers ALV Tree in the constructor
* method itself.
*    - cl_gui_column_tree=>eventid_expand_no_children
* (needed to load data to frontend when a user expands a node)
*    - cl_gui_column_tree=>eventid_header_context_men_req
* (needed for header context menu)
*    - cl_gui_column_tree=>eventid_header_click
* (allows selection of columns (only when item selection activated))
*   - cl_gui_column_tree=>eventid_item_keypress
* (needed for F1-Help (only when item selection activated))
*
* Nevertheless you have to provide their IDs again if you register
* additional events with SET_REGISTERED_EVENTS (see below).
* To do so, call first method  GET_REGISTERED_EVENTS (this way,
* all already registered events remain registered, even your own):
call method g_alv_tree->get_registered_events
      importing events = lt_events.
* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.

*§4b. Frontend registration(ii): add additional event ids
  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
  APPEND l_event TO lt_events.

*§4c. Frontend registration(iii):provide new event table to alv tree
  CALL METHOD g_alv_tree->set_registered_events
    EXPORTING
      events = lt_events
    EXCEPTIONS
      cntl_error                = 1
      cntl_system_error         = 2
      illegal_event_combination = 3.
  IF sy-subrc <> 0.
    MESSAGE x208(00) WITH 'ERROR'.     "#EC NOTEXT
  ENDIF.
*--------------------
*§4d. Register events on backend (ABAP Objects event handling)
  CREATE OBJECT l_event_receiver.
  SET HANDLER l_event_receiver->handle_node_double_click FOR g_alv_tree.

ENDFORM.                               " register_events

Regards

Uwe