ALV FUNCTION:
TOOLBAR上可以对两类TOOLBAR进行显示和设置,分别为系统标准及用户自定义的。
1。系统标准(Standard Functions), 默认ALV显示,可以看到“视图”,“显示为”,“打印”……等
可以通过接口为 if_salv_wd_std_functions 设置其是否显示,显示位置,布局等。
2。用户自定义(Application Functions),用户可以自定义添加各种UI及事件。
可以通过接口为 if_salv_wd_function_settings来实现,UI的类型,位置等。通过继承ALV的ON_FUNCTION加入处理事件。
用户可生成的控件种类: Button,ToggleButton,DropDownByKey,DropDownByIndex,InputField,LinkToURL,linkToAction,ButtonChoice
用户自定义的TOOLBAR,简单实现如下:
在CONTEXT中新建节点FUNCTION_ELEMENTS,与WDALV中的FUNCTION_ELEMENTS映射绑定。FUNCTION_ELEMENT下新建CHECKED,CHOICE,INFUTFIELD,DROPYDOWNBYKEY等属性,供生成UI时使用,以及触发操作后从此读值。
DATA : R_TABLE TYPE REF TO CL_SALV_WD_CONFIG_TABLE。
METHOD configure_alv . “ALV上TOOLBAR设置
*... check ALV component usage
DATA:
lr_salv_wd_table_usage TYPE REF TO if_wd_component_usage.
lr_salv_wd_table_usage = wd_this->wd_cpuse_salv_wd_table( ).
IF lr_salv_wd_table_usage->has_active_component( ) IS INITIAL.
lr_salv_wd_table_usage->create_component( ).
ENDIF.
*... get ALV component
DATA:
lr_salv_wd_table TYPE REF TO iwci_salv_wd_table.
lr_salv_wd_table = wd_this->wd_cpifc_salv_wd_table( ).
*... (1) get ConfigurationModel from ALV Component
wd_this->r_table = lr_salv_wd_table->get_model( ).
* ...(2) init ConfigurationModel
*... init Toolbar
DATA:
lr_functions TYPE REF TO if_salv_wd_function_settings.
lr_functions ?= wd_this->r_table.
DATA:
lr_function TYPE REF TO cl_salv_wd_function.
DATA:
lr_button TYPE REF TO cl_salv_wd_fe_button,
lr_toggle_button TYPE REF TO cl_salv_wd_fe_toggle_button,
lr_dropdown_by_key TYPE REF TO cl_salv_wd_fe_dropdown_by_key,
lr_dropdown_by_idx TYPE REF TO cl_salv_wd_fe_dropdown_by_idx,
lr_input_field TYPE REF TO cl_salv_wd_fe_input_field,
lr_link_to_action TYPE REF TO cl_salv_wd_fe_link_to_action,
lr_link_to_url TYPE REF TO cl_salv_wd_fe_link_to_url,
lr_button_choice TYPE REF TO cl_salv_wd_fe_button_choice.
lr_function = lr_functions->create_function( 'MYLEFTBUTTON' ).
CREATE OBJECT lr_button.
lr_button->set_text( 'MYLEFTBUTTON' ).
lr_function->set_editor( lr_button ).
lr_function = lr_functions->create_function( 'MYTOGGLEBUTTON' ).
CREATE OBJECT lr_toggle_button
EXPORTING
checked_elementname = 'CHECKED'.
lr_toggle_button->set_text( 'MYTOGGLEBUTTON' ).
lr_toggle_button->set_image_source( 'ICON_FLIGHT' ).
lr_toggle_button->set_checked_image_source( 'ICON_FLIGHT' ).
lr_function->set_editor( lr_toggle_button ).
lr_function = lr_functions->create_function( 'MYDROPDOWNBYKEY' ).
CREATE OBJECT lr_dropdown_by_key
EXPORTING
selected_key_elementname = 'DROPDOWNBYKEY'.
lr_dropdown_by_key->set_label_text( 'MYDROPDOWNBYKEY' ).
lr_function->set_editor( lr_dropdown_by_key ).
lr_function = lr_functions->create_function( 'MYDROPDOWNBYINDEX' ).
CREATE OBJECT lr_dropdown_by_idx
EXPORTING
texts_elementname = 'DROPDOWNBYINDEX.VALUE'.
lr_dropdown_by_idx->set_label_text( 'MYDROPDOWNBYINDEX' ).
lr_function->set_editor( lr_dropdown_by_idx ).
lr_function = lr_functions->create_function( 'MYINPUTFIELD' ).
CREATE OBJECT lr_input_field
EXPORTING
value_elementname = 'INPUTFIELD'.
lr_input_field->set_label_text( 'MYINPUTFIELD' ).
lr_function->set_editor( lr_input_field ).
lr_function = lr_functions->create_function( 'MYLINKTOACTION' ).
CREATE OBJECT lr_link_to_action.
lr_link_to_action->set_text( 'MYLINKTOACTION' ).
lr_function->set_editor( lr_link_to_action ).
lr_function = lr_functions->create_function( 'MYLINKTOURL' ).
CREATE OBJECT lr_link_to_url.
lr_link_to_url->set_text( 'MYLINKTOURL' ).
lr_link_to_url->set_reference( 'http://www.amazon.de' ).
lr_function->set_editor( lr_link_to_url ).
lr_function = lr_functions->create_function( 'MYBUTTONCHOICE' ).
CREATE OBJECT lr_button_choice.
lr_button_choice->set_text( 'MYBUTTONCHOICE' ).
lr_function->set_editor( lr_button_choice ).
lr_button_choice->set_repeat_selected_action( abap_true ).
* lr_button_choice->set_selected_action_item( 'CHOICE_3' ).
lr_button_choice->set_sel_action_itm_elementname( 'CHOICE' ).
DATA:
lr_choice TYPE REF TO cl_salv_wd_menu_action_item.
CREATE OBJECT lr_choice
EXPORTING
id = 'CHOICE_1'.
lr_choice->set_text( 'Choice1' ). "#EC NOTEXT
lr_button_choice->add_choice( lr_choice ).
CREATE OBJECT lr_choice
EXPORTING
id = 'CHOICE_2'.
lr_choice->set_text( 'Choice2' ). "#EC NOTEXT
lr_button_choice->add_choice( lr_choice ).
CREATE OBJECT lr_choice
EXPORTING
id = 'CHOICE_3'.
lr_choice->set_text( 'Choice3' ). "#EC NOTEXT
lr_button_choice->add_choice( lr_choice ).
lr_function = lr_functions->create_function_right( 'MYRIGHTBUTTON' ).
CREATE OBJECT lr_button.
lr_button->set_text( 'MYRIGHTBUTTON' ).
lr_function->set_editor( lr_button ).
ENDMETHOD.
METHOD:ON_ALV_FUNCTION 继承ALV中的ON_FUNCTION事件:
METHOD on_alv_function .
CASE r_param->id.
WHEN 'FROM_SUB'.
wd_this->on_from_sub( ).
WHEN 'CREAT_SUB'.
wd_this->on_creat_sub( ).
......
ENDCASE.
ENDMETHOD.