Chinaunix首页 | 论坛 | 博客
  • 博客访问: 176925
  • 博文数量: 31
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-17 23:11
文章分类

全部博文(31)

文章存档

2011年(1)

2009年(18)

2008年(12)

我的朋友

分类:

2009-01-11 12:33:21

LIKE THIS PICTURE

As implemented in gui, we shall create another column to control the cell .

For example

1.         Create the cell for controlling each cell ( read/edit and cell design )

2.         Set the control value

3.         Apply the design

The source codes like below

DATA:

* Node Info

  rootnode_info TYPE REF TO if_wd_context_node_info,

* Context Nodes

  dyn_node TYPE REF TO if_wd_context_node,

  tabname_node TYPE REF TO if_wd_context_node,

* String (for table name)

  tablename TYPE string.

* get node info of context root node

  rootnode_info = wd_context->get_node_info( ).

* Get the name of the table to be created

 

  DATA: is_fieldcat TYPE LVC_S_FCAT.

  DATA: gt_fieldcatalog TYPE lvc_t_fcat.

  DATA: new_table TYPE REF TO data."out_data table space

  DATA: new_line  TYPE REF TO data."out_data line space

  DATA: LNAME TYPE STRING.

  DATA: LS TYPE I VALUE 30.

  DO LS TIMES.

    LNAME = SY-INDEX.

    CONCATENATE 'C' LNAME INTO is_fieldcat-fieldname.

*  is_fieldcat-fieldname = 'GUID'.

    is_fieldcat-ref_field = 'DESCRIPTION'..

    is_fieldcat-ref_table = 'CRMD_ORDERADM_H'.

    APPEND is_fieldcat TO gt_fieldcatalog.

  ENDDO.

  DO LS TIMES.

 

     LNAME = SY-INDEX.

     CLEAR is_fieldcat.

     CONCATENATE 'DESIGN' LNAME INTO is_fieldcat-fieldname.

     is_fieldcat-DOMNAME = 'WDUI_TABLE_CELL_DESIGN'..

     APPEND is_fieldcat TO gt_fieldcatalog.

     CLEAR is_fieldcat.

     CONCATENATE 'READONLY' LNAME INTO is_fieldcat-fieldname.

     APPEND is_fieldcat TO gt_fieldcatalog.

  ENDDO.

*

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = gt_fieldcatalog

    IMPORTING

      ep_table        = new_table.

  FIELD-SYMBOLS: TYPE ANY TABLE,

                   TYPE ANY,

                 TYPE ANY.

  ASSIGN new_table->* TO .

data: index_row(3) TYPE N,

      index_col(3) type N.

 

  DO LS TIMES.

    index_row = sy-index.

    CREATE DATA new_line LIKE LINE OF .

    ASSIGN new_line->* TO .

    DO LS TIMES.

      index_col = SY-INDEX.

      ASSIGN COMPONENT SY-INDEX

                  OF STRUCTURE TO .

      IF SY-INDEX = 1.

         concatenate 'BP' INDEX_ROW into .

         = 'BP' .

      ELSE.

      concatenate 'NUMER' '.' INDEX_ROW '-' INDEX_COL into .

*      = SY-INDEX.

      ENDIF.

    ENDDO.

    insert into table .

  ENDDO.

 

  data: descr_ref TYPE ref to CL_ABAP_TYPEDESCR.

  data: STATIC_ELEMENT_RTTI type ref to CL_ABAP_STRUCTDESCR.

  descr_ref = cl_abap_typedescr=>describe_by_data( ).

  STATIC_ELEMENT_RTTI ?= descr_ref.

  ZCL_WD_ALV_TEST=>CREATE_NODEINFO_FROM_STRUCT(

*    EXPORTING

      PARENT_INFO         = rootnode_info

*    STRUCTURE_NAME      = tablename

      IS_MULTIPLE         = abap_true

*    IS_MANDATORY        = ABAP_FALSE

      NODE_NAME           = 'DTABLE'

      STATIC_ELEMENT_RTTI = STATIC_ELEMENT_RTTI ).

*  RECEIVING

*    NEW_NODE            = dyn_node

  .

 

 

* get instance of new node

  dyn_node = wd_context->get_child_node( name = 'DTABLE' ).

* Instantiate ALV component

  DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.

  l_ref_cmp_usage = wd_this->wd_cpuse_alv( ).

  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.

    l_ref_cmp_usage->create_component( ).

  ENDIF.

* Pass context node to ALV

  DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .

  l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).

  l_ref_interfacecontroller->set_data( dyn_node ).

  DATA: LR_CONFIG      TYPE REF TO CL_SALV_WD_CONFIG_TABLE.

  LR_CONFIG = l_ref_interfacecontroller->GET_MODEL( ).

 

  DATA:

      LT_COLUMNS     TYPE SALV_WD_T_COLUMN_REF,

      LS_COLUMN      TYPE SALV_WD_S_COLUMN_REF,

      LR_COLUMN      TYPE REF TO CL_SALV_WD_COLUMN,

      LR_HEADER      TYPE REF TO CL_SALV_WD_COLUMN_HEADER,

      LR_INPUT_FIELD TYPE REF TO CL_SALV_WD_UIE_INPUT_FIELD,

      LR_TEXT_VIEW TYPE REF TO CL_SALV_WD_UIE_TEXT_VIEW,

      LR_CAPTION TYPE REF TO CL_SALV_WD_UIE_CAPTION,

      LR_ACTION TYPE REF TO CL_SALV_WD_UIE_LINK_TO_ACTION,

      LR_BUTTON TYPE REF TO CL_SALV_WD_UIE_BUTTON,

      LR_CHECKBOX TYPE REF TO CL_SALV_WD_UIE_CHECKBOX,

      LR_ICON_FIELD  TYPE REF TO CL_SALV_WD_UIE_IMAGE.

  LT_COLUMNS = LR_CONFIG->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMNS( ).

  LR_CONFIG->IF_SALV_WD_TABLE_SETTINGS~SET_VISIBLE_ROW_COUNT( 30 ).

  LR_CONFIG->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( ABAP_FALSE ).

  LR_CONFIG->IF_SALV_WD_TABLE_SETTINGS~SET_DATA_CHECK( IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CELL_EVENT ).

  LR_CONFIG->IF_SALV_WD_TABLE_SETTINGS~SET_SELECTION_MODE( '08' ).

*LR_CONFIG->IF_SALV_WD_STD_FUNCTIONS~SET_DISPLAY_AS_ALLOWED( ABAP_FALSE ).

  LR_CONFIG->IF_SALV_WD_STD_FUNCTIONS~SET_PDF_ALLOWED( ABAP_FALSE ).

 

 

*LR_CONFIG->IF_SALV_WD_TABLE_SETTINGS~SET_CELL_ACTION_EVENT_ENABLED( ABAP_TRUE ).

  CL_SALV_WD_MODEL_TABLE_UTIL=>IF_SALV_WD_TABLE_UTIL_STDFUNCS~SET_GROUP_EDIT(

      R_MODEL = LR_CONFIG

      ALLOWED = ABAP_FALSE ).

 

  data: hstr type string.

  LOOP AT LT_COLUMNS INTO LS_COLUMN.

    LNAME = SY-TABIX.

    LR_COLUMN = LS_COLUMN-R_COLUMN.

    LR_HEADER = LR_COLUMN->GET_HEADER( ).

    hstr = LR_COLUMN->IF_SALV_WD_COLUMN_REF~GET_TEXT_FIELDNAME( ).

*    LR_COLUMN->IF_SALV_WD_COLUMN_REF~SET_TEXT_FIELDNAME( '物料T' ).

    concatenate '产品' LNAME INTO hstr.

    IF SY-TABIX = 1.

      lr_column->r_header->set_text( 'BP' ).

 

    ELSE.

      lr_column->r_header->set_text( hstr ).

    ENDIF.

    lr_column->r_header->SET_TOOLTIP( '物料tooltips' ).

    LR_HEADER = LR_COLUMN->GET_HEADER( ).

*    hstr = LR_COLUMN->IF_SALV_WD_COLUMN_REF~GET_TEXT_FIELDNAME( ).

    LR_HEADER->SET_DDIC_BINDING_FIELD( ).

*    hstr = LR_COLUMN->IF_SALV_WD_COLUMN_REF~GET_TEXT_FIELDNAME( ).

    CASE LS_COLUMN-ID.

      WHEN LS_COLUMN-ID.

         CREATE OBJECT LR_INPUT_FIELD

                exporting VALUE_FIELDNAME = LS_COLUMN-ID.

         LR_COLUMN->SET_CELL_EDITOR( LR_INPUT_FIELD ).

      WHEN OTHERS.

    ENDCASE.

  ENDLOOP.

DATA: T01(2) TYPE N.

DO 20 TIMES.

T01 = SY-INDEX - 1.

 

CALL METHOD ZCL_ALV_OPERATION=>SET_CELL_DESIGN

  EXPORTING

    ROW                    = SY-INDEX

    COL                    = 2

*    READ_ONLY              = ABAP_TRUE

    CELL_DESIGN_FIELDVALUE = T01

  CHANGING

    DATA                   =

    .

ENDDO.

 

CALL METHOD ZCL_ALV_OPERATION=>APPLY_CELL_DESIGNS

  EXPORTING

    DATA    =

  CHANGING

    COLUMNS = LT_COLUMNS

    .

  dyn_node->bind_table( ).

 

CLASS ZCL_ALV_OPERATION

PARAMETERS:

ROW Importing  Type   INTEGER                                                                         

COL Importing  Type   INTEGER                                                                          

READ_ONLY  Importing  Type   ABAP_BOOL  ABAP_TRUE

CELL_DESIGN_FIELDVALUE   Importing  Type   WDUI_TABLE_CELL_DESIGN                                                                        

DATA   Changing   Type   ANY TABLE                                                                       

 

method SET_CELL_DESIGN.

  DATA: LS_COLUMN      TYPE SALV_WD_S_COLUMN_REF,

        LR_COLUMN      TYPE REF TO CL_SALV_WD_COLUMN,

        LR_INPUT_FIELD TYPE REF TO CL_SALV_WD_UIE_INPUT_FIELD,

        CD_FIELDNAME TYPE STRING,

        RO_FIELDNAME TYPE STRING,

        INDEX_NAME TYPE STRING.

 

  FIELD-SYMBOLS: TYPE ANY TABLE,

                     TYPE ANY,

                   TYPE ANY,

                     TYPE ANY.

  ASSIGN DATA TO .

  data: index_row(3) TYPE N,

        index_col(3) type N.

  data: descr_ref TYPE ref to CL_ABAP_TYPEDESCR,

        AMOUNT_LINES TYPE I,

        STATIC_ELEMENT_RTTI type ref to CL_ABAP_STRUCTDESCR.

  LOOP AT ASSIGNING .

    descr_ref = cl_abap_typedescr=>describe_by_data( ).

    STATIC_ELEMENT_RTTI ?= descr_ref.

    EXIT.

  ENDLOOP.

  AMOUNT_LINES = LINES( STATIC_ELEMENT_RTTI->COMPONENTS ).

  AMOUNT_LINES = AMOUNT_LINES / 3.

  LOOP AT ASSIGNING .

    IF SY-TABIX = ROW.

      IF COL = 0.

        DO AMOUNT_LINES TIMES.

          INDEX_NAME = SY-INDEX.

          CONCATENATE 'DESIGN' INDEX_NAME INTO CD_FIELDNAME.

          ASSIGN COMPONENT CD_FIELDNAME

            OF STRUCTURE TO .

          IF IS ASSIGNED.

            = CELL_DESIGN_FIELDVALUE.

          ENDIF.

          CONCATENATE 'READONLY' INDEX_NAME INTO RO_FIELDNAME.

          ASSIGN COMPONENT RO_FIELDNAME

            OF STRUCTURE TO .

          IF IS ASSIGNED.

            = READ_ONLY.

          ENDIF.

        ENDDO.

      ELSE.

        INDEX_NAME = COL.

        CONCATENATE 'DESIGN' INDEX_NAME INTO CD_FIELDNAME.

        ASSIGN COMPONENT CD_FIELDNAME

          OF STRUCTURE TO .

        IF IS ASSIGNED.

           = CELL_DESIGN_FIELDVALUE.

        ENDIF.

        CONCATENATE 'READONLY' INDEX_NAME INTO RO_FIELDNAME.

        ASSIGN COMPONENT RO_FIELDNAME

          OF STRUCTURE TO .

        IF IS ASSIGNED.

          = READ_ONLY.

        ENDIF.

      ENDIF.

      EXIT.

    ENDIF.

 

  ENDLOOP.

 

endmethod.

 

PARAMETERS:

DATA   Importing  Type   ANY TABLE

COLUMNS    Changing   Type   SALV_WD_T_COLUMN_REF

method APPLY_CELL_DESIGNS.

 

  DATA: LS_COLUMN      TYPE SALV_WD_S_COLUMN_REF,

          LR_COLUMN      TYPE REF TO CL_SALV_WD_COLUMN,

          LR_INPUT_FIELD TYPE REF TO CL_SALV_WD_UIE_INPUT_FIELD,

          CD_FIELDNAME TYPE STRING,

          RO_FIELDNAME TYPE STRING,

          INDEX_NAME TYPE STRING.

 

  FIELD-SYMBOLS: TYPE ANY TABLE,

                     TYPE ANY,

                   TYPE ANY,

                     TYPE ANY.

  ASSIGN DATA TO .

  data: index_row(3) TYPE N,

        index_col(3) type N.

  DATA: AMOUNT_COL TYPE I.

  AMOUNT_COL = LINES( COLUMNS ).

  AMOUNT_COL = AMOUNT_COL / 3.

 

  LOOP AT COLUMNS INTO LS_COLUMN.

    IF SY-TABIX <= AMOUNT_COL.

      LR_COLUMN = LS_COLUMN-R_COLUMN.

      INDEX_NAME = SY-TABIX.

      CONCATENATE 'DESIGN' INDEX_NAME INTO CD_FIELDNAME.

      CONCATENATE 'READONLY' INDEX_NAME INTO RO_FIELDNAME.

      lr_column->SET_CELL_DESIGN_FIELDNAME( VALUE = CD_FIELDNAME ).

      CREATE OBJECT LR_INPUT_FIELD

        EXPORTING

          VALUE_FIELDNAME = LS_COLUMN-ID.

      LR_COLUMN->SET_CELL_EDITOR( LR_INPUT_FIELD ).

      LR_INPUT_FIELD->set_read_only_fieldname( value = RO_FIELDNAME ).

    ELSE.

    EXIT.

    ENDIF.

  ENDLOOP.

endmethod.
阅读(2160) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~