Code: Alles auswählen.
*__________________________________________
*
* Klasse Event-Receiver
*__________________________________________
CLASS CL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
DATA: UCOMM TYPE SY-UCOMM.
DATA: SELFIELD TYPE SLIS_SELFIELD.
METHODS:
HANDLE_ONDROP
FOR EVENT ONDROP OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ,
HANDLE_DROPCOMPL
FOR EVENT ONDROPCOMPLETE OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ,
HANDLE_FLAV
FOR EVENT ONDROPGETFLAVOR OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ
E_FLAVORS.
PRIVATE SECTION.
ENDCLASS.
* Implementation
CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
* Drag & Drop
METHOD HANDLE_ONDROP.
*
ENDMETHOD.
METHOD HANDLE_DROPCOMPL.
*
ENDMETHOD.
METHOD HANDLE_FLAV.
*
ENDMETHOD.
ENDCLASS.
....
GS_LAYOUT_ALV-S_DRAGDROP-ROW_DDID = G_HANDLE_ALV.
* handler for ALV grid
SET HANDLER EVENT_RECEIVER->HANDLE_ONDROP FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_DROPCOMPL FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_FLAV FOR GRID.
* first call with dummy entry
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT_ALV
CHANGING "IT_SORT = GT_SORT_GRID[]
IT_OUTTAB = GT_SFLIGHT[]
it_fieldcatalog = fieldcat[].
Code: Alles auswählen.
INCLUDE <ICON>.
*----------------------------------------------------------------------*
* INCLUDE BCALV_DND_TOP2 *
*----------------------------------------------------------------------*
* definition of tables, types, data and constants
* tables
TABLES: SCARR, SFLIGHT, SPFLI, SAPLANE.
TYPE-POOLS: SLIS.
* internal tables
DATA: GT_SCARR TYPE TABLE OF SCARR WITH HEADER LINE,
begin of wa_tab,
cat1(20),
cat2(20),
cont(40),
end of wa_tab,
GT_SPFLI like TABLE OF wa_tab WITH HEADER LINE,
begin of wa_grid,
name1(20),
name2(20),
name3(20),
end of wa_grid,
GT_SFLIGHT like TABLE OF wa_grid WITH HEADER LINE,
GT_SAPLANE TYPE TABLE OF SAPLANE WITH HEADER LINE,
GT_HEADER TYPE TABLE OF SLIS_LISTHEADER WITH HEADER LINE,
GT_FIELDCAT_LVC TYPE LVC_T_FCAT WITH HEADER LINE,
GT_SORT TYPE LVC_T_SORT, "Sortiertabelle
GT_SORT_GRID TYPE LVC_T_SORT WITH HEADER LINE,
GT_ROW_TABLE TYPE LVC_T_ROW WITH HEADER LINE. " selected rows
* global fields
DATA: CONTROLS_CREATED,
FLG_NEW,
GS_LAYOUT_ALV TYPE LVC_S_LAYO,
GS_LAYOUT_TREE TYPE LVC_S_LAYO,
GS_TOOLBAR TYPE STB_BUTTON,
G_DROPEFFECT TYPE I,
G_REPID LIKE SY-REPID,
OK_CODE LIKE SY-UCOMM,
SAVE_OK_CODE LIKE SY-UCOMM,
SELECTED VALUE 'X',
TREE1 TYPE REF TO CL_GUI_SIMPLE_TREE.
* constants
CONSTANTS: FCODE_BACK LIKE SY-UCOMM VALUE 'BACK',
FCODE_DISP LIKE SY-UCOMM VALUE 'DISP',
FCODE_END LIKE SY-UCOMM VALUE 'END',
FCODE_ENTR LIKE SY-UCOMM VALUE 'ENTR',
FCODE_ESC LIKE SY-UCOMM VALUE 'ESC',
FCODE_PLANE LIKE SY-UCOMM VALUE 'FLIGHT'.
TYPES: NODE_TABLE_TYPE LIKE STANDARD TABLE OF MTREESNODE
WITH DEFAULT KEY.
DATA: NODE_TABLE TYPE NODE_TABLE_TYPE,
NODE LIKE MTREESNODE.
DATA: " Drag&Drop Objekte
DRAGDROP_TREE TYPE REF TO CL_DRAGDROP,
DRAGDROP_ALV TYPE REF TO CL_DRAGDROP,
" Handles
G_HANDLE_TREE TYPE I,
G_HANDLE_ALV TYPE I,
" Custom Container für ALV-Grid
G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
" Das ALV-GRID
GRID TYPE REF TO CL_GUI_ALV_GRID,
" Docking-Container (links)
G_CONTAINER_OBJECT TYPE REF TO CL_GUI_DOCKING_CONTAINER.
*__________________________________________
*
* Klasse Event-Receiver
*__________________________________________
CLASS CL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
DATA: UCOMM TYPE SY-UCOMM.
DATA: SELFIELD TYPE SLIS_SELFIELD.
METHODS:
HANDLE_ONDROP
FOR EVENT ONDROP OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ,
HANDLE_DROPCOMPL
FOR EVENT ONDROPCOMPLETE OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ,
HANDLE_FLAV
FOR EVENT ONDROPGETFLAVOR OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
E_DRAGDROPOBJ
E_FLAVORS.
PRIVATE SECTION.
ENDCLASS.
* Implementation
CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
* Drag & Drop
METHOD HANDLE_ONDROP.
*
ENDMETHOD.
METHOD HANDLE_DROPCOMPL.
*
ENDMETHOD.
METHOD HANDLE_FLAV.
*
ENDMETHOD.
ENDCLASS.
DATA: EVENT_RECEIVER TYPE REF TO CL_EVENT_RECEIVER.
*_________________________________________
*
* Klasse Event-Receiver für Trees
*_________________________________________
CLASS CL_TREE_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
* Drag
METHODS: HANDLE_ON_DRAG
FOR EVENT ON_DRAG OF cl_gui_simple_tree
IMPORTING DRAG_DROP_OBJECT
node_key.
PRIVATE SECTION.
ENDCLASS.
* Implementation
CLASS CL_TREE_EVENT_RECEIVER IMPLEMENTATION.
* Drag & Drop
METHOD HANDLE_ON_DRAG.
PERFORM DISPLAY_FLIGHTS USING node_key.
"CALL METHOD CL_GUI_CFW=>SET_NEW_OK_CODE EXPORTING NEW_CODE =
"FCODE_ENTR.
ENDMETHOD.
ENDCLASS.
DATA: TREE_EVENT_RECEIVER TYPE REF TO CL_TREE_EVENT_RECEIVER.
DATA: fieldcat_3020 type lvc_t_fcat, " Fieldcatalog
wa_3020 like line of fieldcat_3020.
MODULE STATUS_1000 OUTPUT.
IF CONTROLS_CREATED IS INITIAL.
" Iniitialisieren der Drag&Drop Objekte
PERFORM INIT_DRAGDROP.
" Anlegen des Dockingcontrols
PERFORM CREATEDOCKINGCONTROL.
PERFORM CREATETREECONTROL.
CONTROLS_CREATED = SELECTED.
ENDIF.
" ALV-Grid anlegen
IF G_CUSTOM_CONTAINER IS INITIAL.
" Custom Container anlegen für das ALV-GRID
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = 'CUSTOM_CONTROL'.
ENDIF.
IF GRID IS INITIAL.
" Status-Icon hinzufügen
wa_3020-fieldname = 'NAME1'.
wa_3020-coltext = 'Tag 1'.
wa_3020-col_pos = 0.
wa_3020-outputlen = 15.
wa_3020-checkbox = SPACE.
wa_3020-ICON = 'X'.
APPEND wa_3020 to fieldcat_3020.
wa_3020-fieldname = 'NAME2'.
wa_3020-coltext = 'Tag 2'.
APPEND wa_3020 to fieldcat_3020.
wa_3020-fieldname = 'NAME3'.
wa_3020-coltext = 'Tag 3'.
APPEND wa_3020 to fieldcat_3020.
* create Event Receiver
CREATE OBJECT EVENT_RECEIVER.
* create ALV grid
CREATE OBJECT GRID
EXPORTING
I_APPL_EVENTS = SELECTED "application event
I_PARENT = G_CUSTOM_CONTAINER.
* Dummy entry for D'n'D
CLEAR GT_SFLIGHT.
APPEND GT_SFLIGHT.
* handle for D'n'D
GS_LAYOUT_ALV-S_DRAGDROP-ROW_DDID = G_HANDLE_ALV.
* handler for ALV grid
SET HANDLER EVENT_RECEIVER->HANDLE_ONDROP FOR GRID.
" SET HANDLER EVENT_RECEIVER->HANDLE_DROPCOMPL FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_FLAV FOR GRID.
* first call with dummy entry
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT_ALV
CHANGING "IT_SORT = GT_SORT_GRID[]
IT_OUTTAB = GT_SFLIGHT[]
it_fieldcatalog = fieldcat_3020[].
* flush
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
IF FLG_NEW = SELECTED.
CLEAR FLG_NEW.
* first call with data
GS_LAYOUT_ALV-GRID_TITLE = SCARR-CARRNAME.
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT_ALV
CHANGING " IT_SORT = GT_SORT_GRID[]
IT_OUTTAB = GT_SFLIGHT[]
it_fieldcatalog = fieldcat_3020[].
* reset fields on screen 100
CLEAR SAPLANE.
* flush
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
ENDMODULE.
*----------------------------------------------------------------------*
* INCLUDE GRID_DND_TREE_SIMPLE_F01 *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CREATEDOCKINGCONTROL
*&---------------------------------------------------------------------*
FORM CREATEDOCKINGCONTROL.
" Docking-Container anlegen
CREATE OBJECT G_CONTAINER_OBJECT
EXPORTING SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_LEFT
EXTENSION = 320
REPID = G_REPID
DYNNR = '1000'.
ENDFORM. " CREATEDOCKINGCONTROL
*&---------------------------------------------------------------------*
*& Form CREATETREECONTROL
*&---------------------------------------------------------------------*
FORM CREATETREECONTROL.
" Event-Receiver anlegen
CREATE OBJECT TREE_EVENT_RECEIVER.
" Tree anlegen in G_CONTAINER_OBJECT
CREATE OBJECT TREE1
EXPORTING
PARENT = G_CONTAINER_OBJECT
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single.
" Nodes anlegen
" Node with key 'ROOT1'
NODE-NODE_KEY = 'ROOT1'. "#EC NOTEXT
" Key of the node (max.12 Zeichen)
CLEAR NODE-RELATKEY. " Special case: A root node has no parent
CLEAR NODE-RELATSHIP. " node.
NODE-HIDDEN = ' '. " The node is visible,
NODE-DISABLED = ' '. " selectable,
NODE-ISFOLDER = 'X'. " a folder.
CLEAR NODE-N_IMAGE. " Folder-/ Leaf-Symbol in state "closed":
" use default.
CLEAR NODE-EXP_IMAGE. " Folder-/ Leaf-Symbol in state "open":
" use default
CLEAR NODE-EXPANDER. " see below.
NODE-TEXT = 'Root1'.
APPEND NODE TO NODE_TABLE.
" Node with key 'ROOT2'
NODE-NODE_KEY = 'ROOT2'. "#EC NOTEXT
" Key of the node (max.12 Zeichen)
CLEAR NODE-RELATKEY. " Special case: A root node has no parent
CLEAR NODE-RELATSHIP. " node.
NODE-HIDDEN = ' '. " The node is visible,
NODE-DISABLED = ' '. " selectable,
NODE-ISFOLDER = 'X'. " a folder.
CLEAR NODE-N_IMAGE. " Folder-/ Leaf-Symbol in state "closed":
" use default.
CLEAR NODE-EXP_IMAGE. " Folder-/ Leaf-Symbol in state "open":
" use default
CLEAR NODE-EXPANDER. " see below.
NODE-TEXT = 'Root2'.
APPEND NODE TO NODE_TABLE.
" Nodes anlegen
" Node with key 'CHILD1'
NODE-NODE_KEY = 'CHILD1'. "#EC NOTEXT
" Key of the node (max.12 Zeichen)
" Node is inserted as child of the node with key 'Resources'.
NODE-RELATKEY = 'ROOT1'.
NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
NODE-HIDDEN = ' '. " The node is visible,
NODE-DISABLED = ' '. " selectable,
NODE-ISFOLDER = 'X'. " a folder.
CLEAR NODE-N_IMAGE. " Folder-/ Leaf-Symbol in state "closed":
" use default.
CLEAR NODE-EXP_IMAGE. " Folder-/ Leaf-Symbol in state "open":
" use default
CLEAR NODE-EXPANDER. " see below.
NODE-TEXT = 'Child1'.
APPEND NODE TO NODE_TABLE.
NODE-NODE_KEY = 'CHILD2'. "#EC NOTEXT
" Key of the node
" Node is inserted as child of the node with key 'Root'.
NODE-RELATKEY = 'CHILD1'.
NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
NODE-HIDDEN = ' '.
NODE-DISABLED = ' '.
NODE-ISFOLDER = 'X'.
NODE-N_IMAGE = ICON_TRANSPORT.
NODE-EXP_IMAGE = ICON_TRANSPORT.
NODE-DRAGDROPID = g_handle_tree.
NODE-EXPANDER = ' '. " The node is marked with a '+', although
" it has no children. When the user clicks on the
" + to open the node, the event
" expand_no_children is fired. The programmer can
" add the children of the
" node within the event handler of the
" expand_no_children event
" (see method handle_expand_no_children
" of class lcl_application)
NODE-TEXT = 'Child2'.
APPEND NODE TO NODE_TABLE.
NODE-NODE_KEY = 'CHILD3'. "#EC NOTEXT
" Key of the node
" Node is inserted as child of the node with key 'Root'.
NODE-RELATKEY = 'CHILD1'.
NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
NODE-HIDDEN = ' '.
NODE-DISABLED = ' '.
NODE-ISFOLDER = 'X'.
NODE-N_IMAGE = ICON_TRANSPORT.
NODE-DRAGDROPID = g_handle_tree.
NODE-EXP_IMAGE = ICON_TRANSPORT.
NODE-EXPANDER = ' '. " The node is marked with a '+', although
" it has no children. When the user clicks on the
" + to open the node, the event
" expand_no_children is fired. The programmer can
" add the children of the
" node within the event handler of the
" expand_no_children event
" (see method handle_expand_no_children
" of class lcl_application)
NODE-TEXT = 'Child3'.
APPEND NODE TO NODE_TABLE.
CALL METHOD tree1->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = node_table.
* handle for D'n'D
GS_LAYOUT_TREE-S_DRAGDROP-ROW_DDID = G_HANDLE_TREE.
* set handler for tree1
SET HANDLER TREE_EVENT_RECEIVER->HANDLE_ON_DRAG FOR TREE1.
ENDFORM. " CREATETREECONTROL
*&---------------------------------------------------------------------*
*& Form DISPLAY_FLIGHTS
*&---------------------------------------------------------------------*
FORM DISPLAY_FLIGHTS USING P_NODE_KEY LIKE NODE-NODE_KEY .
" Drag-Objekt auslesen ...
READ TABLE NODE_TABLE INTO node WITH KEY node_key = p_node_key.
LOOP AT GT_SFLIGHT.
GT_SFLIGHT-NAME1 = node-text.
modify GT_SFLIGHT.
ENDLOOP.
call method grid->Refresh_table_display.
ENDFORM. " DISPLAY_FLIGHTS
*&---------------------------------------------------------------------*
*& Form init_dragdrop
*&---------------------------------------------------------------------*
FORM INIT_DRAGDROP.
G_DROPEFFECT = CL_DRAGDROP=>COPY.
" Drag&Drop Objekt für Tree anlegen
CREATE OBJECT DRAGDROP_TREE.
CALL METHOD DRAGDROP_TREE->ADD EXPORTING
FLAVOR = 'LINE'
DRAGSRC = SELECTED
DROPTARGET = ''
EFFECT = G_DROPEFFECT.
" Handle merken
CALL METHOD DRAGDROP_TREE->GET_HANDLE IMPORTING
HANDLE = G_HANDLE_TREE.
" Drag&Drop Objekt für ALV anlegen
CREATE OBJECT DRAGDROP_ALV.
CALL METHOD DRAGDROP_ALV->ADD EXPORTING
FLAVOR = 'LINE'
DRAGSRC = ''
DROPTARGET = SELECTED
EFFECT = G_DROPEFFECT.
" Handle merken
CALL METHOD DRAGDROP_ALV->GET_HANDLE IMPORTING
HANDLE = G_HANDLE_ALV.
ENDFORM. " init_dragdrop
Code: Alles auswählen.
...
* unser DnD-Datenobjekt
CLASS lcl_dragdrop_data DEFINITION.
PUBLIC SECTION.
DATA:
daten(50).
ENDCLASS.
...
...
* Sendemethode des Trees
METHOD handle_on_drag.
DATA: lx_dragdrop_data TYPE REF TO lcl_dragdrop_data.
* Daten des TreeKnotens lesen...
READ TABLE node_table INTO node WITH KEY node_key = node_key.
* und DragNDrop-Objekt mit Infos füllen
CREATE OBJECT lx_dragdrop_data.
lx_dragdrop_data->daten = node-text.
* handle speichern
drag_drop_object->object = lx_dragdrop_data.
ENDMETHOD.
...
...
* Empfangsmethode des Grids
METHOD handle_ondrop.
DATA:
lx_dragdrop_data TYPE REF TO lcl_dragdrop_data.
FIELD-SYMBOLS:
<ls_sflight> LIKE LINE OF gt_sflight.
* Objekt in Referenzvariable umfüllen (widening cast)
CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
lx_dragdrop_data ?= e_dragdropobj->object.
ENDCATCH.
* sauberer Abbruch, wenn Objekte nicht kompatibel sind
IF sy-subrc <> 0.
CALL METHOD e_dragdropobj->abort.
ELSE.
* komplette 1. Spalte mit Daten füllen?
LOOP AT gt_sflight ASSIGNING <ls_sflight>.
<ls_sflight>-name1 = lx_dragdrop_data->daten.
ENDLOOP.
CALL METHOD grid->refresh_table_display.
ENDIF.
ENDMETHOD.
...