* globale Objektreferenz für Tree-Objekt
DATA: o_tree TYPE REF TO cl_column_tree_model.
* Übergabeobjekt für Drag-Drop-Events
CLASS lcl_dd_object DEFINITION.
PUBLIC SECTION.
METHODS: constructor
IMPORTING
i_drag_node_text TYPE tm_nodekey.
METHODS: get_value
RETURNING VALUE(rv_ret) TYPE tm_nodekey.
PRIVATE SECTION.
DATA: gv_drag_node_text TYPE tm_nodekey.
ENDCLASS.
CLASS lcl_dd_object IMPLEMENTATION.
METHOD constructor.
gv_drag_node_text = i_drag_node_text.
ENDMETHOD.
METHOD get_value.
rv_ret = gv_drag_node_text.
ENDMETHOD.
ENDCLASS.
* Demoprogramm: SAPSIMPLE_TREE_DRAG_DROP_DEMO
* http://saphelp.ucc.ovgu.de/NW750/EN/4d/88f020981740abe10000000a15822b/frameset.htm
* Eventhandler-Klasse
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY.
CLASS-METHODS: on_drag FOR EVENT drag OF cl_column_tree_model
IMPORTING
node_key
item_name
drag_drop_object
sender.
CLASS-METHODS: on_drop FOR EVENT drop OF cl_column_tree_model
IMPORTING
node_key
drag_drop_object
sender.
CLASS-METHODS: on_drop_complete FOR EVENT drop_complete OF cl_column_tree_model
IMPORTING
node_key
item_name
drag_drop_object
sender.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
* Quell-Node
METHOD on_drag.
* Übergabe Name der Quell-Node
drag_drop_object->object = NEW lcl_dd_object( node_key ).
ENDMETHOD.
* Ziel-Node
METHOD on_drop.
TRY.
* Holen Name der Quell-Node
DATA(o_dd_obj) = CAST lcl_dd_object( drag_drop_object->object ).
IF o_tree IS BOUND.
* Quell-Node an Ziel-Node umhängen
o_tree->move_node(
node_key = o_dd_obj->get_value( )
relative_node_key = node_key
relationship = cl_tree_model=>relat_last_child
).
ENDIF.
CATCH cx_root.
* Abbruch bei Cast-Fehler
drag_drop_object->abort( ).
ENDTRY.
ENDMETHOD.
METHOD on_drop_complete.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
* Tree-Control erzeugen
* item_selection = abap_true wegen der CheckBoxen
o_tree = NEW cl_column_tree_model( node_selection_mode = cl_column_tree_model=>node_sel_mode_single
hierarchy_column_name = 'FOLDER'
hierarchy_header = VALUE #( t_image = icon_folder
heading = 'Beispiel'
tooltip = 'Tooltip'
width = 30
)
item_selection = abap_true
).
* Spalten hinzufügen
o_tree->add_column( EXPORTING
name = 'COL1'
width = 30
header_text = 'Column1' ).
o_tree->add_column( EXPORTING
name = 'COL2'
width = 30
header_text = 'Column2' ).
* in default_screen einbetten
o_tree->create_tree_control( parent = cl_gui_container=>default_screen ).
* Drag-Drop-Verhalten definieren
DATA(o_behaviour) = NEW cl_dragdrop( ).
o_behaviour->add( EXPORTING
flavor = 'Filestest'
dragsrc = abap_true
droptarget = abap_true
effect = CONV i( cl_dragdrop=>move + cl_dragdrop=>copy )
).
DATA: lv_handle_dd TYPE i.
o_behaviour->get_handle( IMPORTING handle = lv_handle_dd ).
* Beispielhaft Nodes und Subnodes erzeugen
o_tree->add_node( EXPORTING
isfolder = abap_true
node_key = 'NODE1'
relative_node_key = ''
relationship = cl_tree_model=>relat_last_child
expanded_image = CONV tv_image( icon_folder )
image = CONV tv_image( icon_folder )
item_table = VALUE #( ( class = cl_column_tree_model=>item_class_checkbox
item_name = 'FOLDER'
text = 'Obj1'
editable = abap_true
)
)
drag_drop_id = lv_handle_dd
).
o_tree->add_node( EXPORTING
isfolder = abap_true
node_key = 'NODE1_1'
relative_node_key = 'NODE1'
relationship = cl_tree_model=>relat_last_child
expanded_image = CONV tv_image( icon_oo_object )
image = CONV tv_image( icon_oo_object )
item_table = VALUE #( ( class = cl_column_tree_model=>item_class_link
item_name = 'FOLDER'
text = 'Obj4'
)
( class = cl_column_tree_model=>item_class_text
item_name = 'COL1'
text = 'Wert1'
style = cl_column_tree_model=>style_intensified
font = cl_column_tree_model=>item_font_prop
)
( class = cl_column_tree_model=>item_class_text
item_name = 'COL2'
text = 'Wert2'
)
)
drag_drop_id = lv_handle_dd
).
o_tree->add_node( EXPORTING
isfolder = abap_true
node_key = 'NODE2'
relative_node_key = ''
relationship = cl_tree_model=>relat_last_child
expanded_image = CONV tv_image( icon_folder )
image = CONV tv_image( icon_folder )
item_table = VALUE #( ( class = cl_column_tree_model=>item_class_checkbox
item_name = 'FOLDER'
text = 'Obj2'
editable = abap_true
)
)
drag_drop_id = lv_handle_dd
).
o_tree->add_node( EXPORTING
isfolder = abap_true
node_key = 'NODE2_1'
relative_node_key = 'NODE2'
relationship = cl_tree_model=>relat_last_child
expanded_image = CONV tv_image( icon_oo_object )
image = CONV tv_image( icon_oo_object )
item_table = VALUE #( ( class = cl_column_tree_model=>item_class_button
item_name = 'FOLDER'
text = 'Obj3'
)
( class = cl_column_tree_model=>item_class_text
item_name = 'COL1'
text = 'Wert1'
style = cl_column_tree_model=>style_inactive
font = cl_column_tree_model=>item_font_prop
)
( class = cl_column_tree_model=>item_class_text
item_name = 'COL2'
text = 'Wert2'
)
)
drag_drop_id = lv_handle_dd
).
* Nodes expandieren
o_tree->expand_root_nodes( expand_subtree = abap_true
level_count = 10 ).
* Events registrieren
* ITEM_DOUBLE_CLICK Doppelklick auf Item
* BUTTON_CLICK Drucktaste wurde gedrückt
* LINK_CLICK Link geklickt
* CHECKBOX_CHANGE Zustandsänderung einer Checkbox
* ITEM_KEYPRESS Taste wurde gedrückt, Item war selektiert
* HEADER_CLICK Header geklickt
* ITEM_CONTEXT_MENU_REQUEST Anforderung eines Kontext-Menüs für ein Item
* ITEM_CONTEXT_MENU_SELECT Kontext-Menü Eintrag wurde ausgewählt
* HEADER_CONTEXT_MENU_REQUEST Anforderung eines Kontext-Menüs für einen Header
* HEADER_CONTEXT_MENU_SELECT Kontext-Menü Eintrag wurde ausgewählt
* DRAG Ereignis zum Füllen des Drag Drop Daten - Objekts
* DRAG_MULTIPLE Ereignis zum Füllen des Drag Drop Daten - Objekts
* DROP_COMPLETE Ereignis nach erfolgreichem Drop
* DROP_COMPLETE_MULTIPLE Ereignis nach erfolgreichem Drop
SET HANDLER lcl_events=>on_drag FOR o_tree.
SET HANDLER lcl_events=>on_drop FOR o_tree.
SET HANDLER lcl_events=>on_drop_complete FOR o_tree.
* Erzeugung von cl_gui_container=>default_screen erzwingen
WRITE: space.