进阶: 案例八: Drag and Drop(动态)

1、节点

2、UI

3、

4、方法:

METHOD wddomodifyview .
  DATA: lo_container TYPE REF TO cl_wd_uielement_container,
        lo_grid_layout TYPE REF TO cl_wd_grid_layout,
        lo_grid_data TYPE REF TO cl_wd_grid_data,
        lo_drag_source_info TYPE REF TO cl_wd_drag_source_info,
        lo_drop_target_info TYPE REF TO cl_wd_drop_target_info,
        lo_child TYPE REF TO cl_wd_uielement,
        lt_children TYPE cl_wd_uielement=>tt_uielement,
        l_sourceidx TYPE i,
        lw_dragdata TYPE string,
        lw_tagetidx TYPE i.
  IF first_time = abap_true.
* for Group1
    lo_container ?= view->get_element( 'GROUP1' ).
    lo_grid_layout ?= lo_container->get_layout( ).
    lo_grid_layout->set_on_drop( 'DROPIT1' ).
** create drap-source-info
    lo_drag_source_info = cl_wd_drag_source_info=>new_drag_source_info(
    bind_enabled = 'GRID_DRAG_ENABLED'
    view = view
    tags = 'gridcell1' ).
** set drap-source-info
    lo_grid_layout->set_drag_source_info( lo_drag_source_info ).
** create drop-target-info
    lo_drop_target_info = cl_wd_drop_target_info=>new_drop_target_info(
    bind_enabled = 'GRID_DROP_ENABLED' "This is not neccessary)
    view = view
    tags = 'gridcell*').
** set drop-target-info
    lo_grid_layout->set_drop_target_info( lo_drop_target_info ).
* for Group2
    lo_container ?= view->get_element( 'GROUP2' ).
    lo_grid_layout ?= lo_container->get_layout( ).
    lo_grid_layout->set_on_drop( 'DROPIT2' ).
** create drap-source-info
    lo_drag_source_info = cl_wd_drag_source_info=>new_drag_source_info(
    bind_enabled = 'GRID_DRAG_ENABLED'
    view = view
    tags = 'gridcell2' ).
** set drap-source-info
    lo_grid_layout->set_drag_source_info( lo_drag_source_info ).
** create drop-target-info
    lo_drop_target_info = cl_wd_drop_target_info=>new_drop_target_info(
    bind_enabled = 'GRID_DROP_ENABLED'
    view = view
    tags = 'gridcell*'
    ).
** set drop-target-info
    lo_grid_layout->set_drop_target_info( lo_drop_target_info ).
  ENDIF.
  IF wd_this->perform_drop IS NOT INITIAL.
    IF wd_this->tags = 'gridcell2'.
      lo_container ?= view->get_element( 'GROUP2' ).
    ELSE.
      lo_container ?= view->get_element( 'GROUP1' ).
    ENDIF.
**get the source Index
    lt_children = lo_container->get_children( ).
    LOOP AT lt_children INTO lo_child.
      l_sourceidx = sy-tabix.
      lo_grid_data ?= lo_child->get_layout_data( ).
      lw_dragdata = lo_grid_data->get_drag_data( ).
      IF lw_dragdata = wd_this->source_data.
        EXIT.
      ENDIF.
    ENDLOOP.
**Modify
    CASE wd_this->target_id.
      WHEN 'TEST1'.
**Trigger by himself:group1
        IF wd_this->tags = 'gridcell1'.
          IF wd_this->offset = -1.
            lw_tagetidx = wd_this->index.
          ELSE.
            lw_tagetidx = wd_this->index + 1.
          ENDIF.
          IF l_sourceidx <> lw_tagetidx.
            lo_container ?= view->get_element( 'GROUP1' ).
            lo_container->remove_child( index = l_sourceidx ).
            lo_container->add_child( the_child = lo_child index = lw_tagetidx ).
          ENDIF.
        ELSE.
**Trigger by group2
          lo_container ?= view->get_element( 'GROUP2' ).
          lo_container->remove_child( index = l_sourceidx ).
          lo_container ?= view->get_element( 'GROUP1' ).
          lo_container->add_child( the_child = lo_child index = lw_tagetidx ).
        ENDIF.
      WHEN 'TEST2'.
**Trigger by himself:group2
        IF wd_this->tags = 'gridcell2'.
          IF wd_this->offset = -1.
            lw_tagetidx = wd_this->index.
          ELSE.
            lw_tagetidx = wd_this->index + 1.
          ENDIF.
          IF l_sourceidx <> lw_tagetidx.
            lo_container ?= view->get_element( 'GROUP2' ).
            lo_container->remove_child( index = l_sourceidx ).
            lo_container->add_child( the_child = lo_child index = lw_tagetidx ).
          ENDIF.
        ELSE.
**Trigger by group1
          lo_container ?= view->get_element( 'GROUP1' ).
          lo_container->remove_child( index = l_sourceidx ).
          lo_container ?= view->get_element( 'GROUP2' ).
          lo_container->add_child( the_child = lo_child index = lw_tagetidx ).
        ENDIF.
    ENDCASE.
  ENDIF.
  CLEAR:wd_this->perform_drop.
ENDMETHOD.
View Code

5、方法中创建的动态事件DROPIT1

参数:

代码:

method ONACTIONDROPIT1 .
  wd_this->source_data = data.
  wd_this->INDEX = INDEX.
  wd_this->OFFSET = OFFSET.
  wd_this->TAGS = TAGS.
  wd_this->ID = ID.
  wd_this->TARGET_ID = 'TEST1'.
  wd_this->PERFORM_DROP = 'X'.
endmethod.
View Code

6、
方法中创建的动态事件DROPIT2

参数:

代码:

method ONACTIONDROPIT2 .
  wd_this->source_data = data.
  wd_this->INDEX = INDEX.
  wd_this->OFFSET = OFFSET.
  wd_this->TAGS = TAGS.
  wd_this->ID = ID.
  wd_this->TARGET_ID = 'TEST2'.
  wd_this->PERFORM_DROP = 'X'.
endmethod.
View Code

 

posted @ 2015-03-26 11:03  学习笔记NO.1  阅读(498)  评论(0编辑  收藏  举报