Before reading this tutorial, create one context node at overview page level with base entity BTAdminh and bind it to the context node(which has base entity BTAdminh) of custom controller. (Refer custom controller and data binding and CREATING CONTEXT NODE )
Go to the overview page implementation class and redefine the method SET_VIEW_GROUP_CONTEXT. Write following code and activate it.
METHOD set_view_group_context.
IF iv_first_time EQ abap_true AND me->view_group_context IS NOT BOUND.
IF iv_parent_context IS INITIAL.
CREATE OBJECT me->view_group_context TYPE cl_bsp_wd_view_group_context.
ELSE.
me->view_group_context = iv_parent_context.
ENDIF.
ENDIF.
ENDMETHOD.
复制代码
Let us add three buttons to the overview page to provide EDIT, SAVE and CANCEL operations. In order to add buttons to overview page, we need to add the code to the method IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS of over view page implementation class.
Go the overview page in UI component and redefine the method by choosing the option redefine after right clicking on it. After redefining it, double click on it to open the method.
Add the following code activate it.
IF lr_header IS BOUND AND view_group_context->is_any_view_editable( ) = abap_false
AND lr_header->is_change_allowed( ) = abap_true.
ls_button-enabled = abap_true.
ELSE.
ls_button-enabled = abap_false.
ENDIF.
APPEND ls_button TO rt_buttons.
CLEAR ls_button.
ls_button-page_id = me->component_id.
ls_button-type = cl_thtmlb_util=>gc_icon_cancel.
ls_button-on_click = 'cancel'. "#EC NOTEXT
IF lr_header IS BOUND AND view_group_context->is_any_view_editable( ) = abap_false
AND lr_header->is_change_allowed( ) = abap_true.
ls_button-enabled = abap_true.
ELSE.
ls_button-enabled = abap_false.
ENDIF.
APPEND ls_button TO rt_buttons.
CLEAR ls_button.
ls_button-page_id = me->component_id.
ls_button-type = cl_thtmlb_util=>gc_icon_save.
ls_button-on_click = 'save'. "#EC NOTEXT
IF lr_header IS BOUND AND view_group_context->is_any_view_editable( ) = abap_false
AND lr_header->is_change_allowed( ) = abap_true.
ls_button-enabled = abap_true.
ELSE.
ls_button-enabled = abap_false.
ENDIF.
APPEND ls_button TO rt_buttons.
ENDMETHOD.
复制代码
When you are adding a new button to standard SAP overview page, do not forget to call the super class method.
ON_CLICK: we will assign event handler name to this property. So when this button is clicked, event handler will be triggered. (event handler name is case sensitive ).
TYPE : we can specify an icon over here. CL_THTMLB_UTIL has number of icons.
PAGE_ID : it is page id in framework language. It could be look like this. C1_W1_V1 where C1 is your component controller and W1 is window and V1 is your current view.
Enabled : if this property is true, then button is enabled else disabled.
It is a standard scenario that once you click on EDIT button, page will be in editable mode. In this mode only we will enable save ,cancel buttons and Edit button will be disabled.
When user clicks either SAVE or CANCEL, then again EDIT button will be enabled. SAVE and CANCEL buttons will be disabled.
We are manipulating the ENABLED property of each button exactly in above mentioned way.
We will discuss the scenario for EDIT button.
Its clear that , to edit or save or cancel, there should be data. So we are reading the data from current context node into lr_header.
First conditions is LR_HEADER is BOUND, which means if there is data, second is LR_header->IS_CHANGE_ALLOWED which means, if data can be changed (why we are testing this condition because the same data may be locked by different user at this point of time) and last condition is VIEW_GROUP_CONTEXT->IS_ANY_VIEW_EDITABLE = ABAP_FALSE which means, no view is already in EDIT mode, then enable the EDIT button else disable it.
You can try to understand the logic for remaining buttons.
Activate and test the application.
We can notice all buttons are coming under group MORE. This is happened because we forgot to redefine one more method IF_BSP_WD_TOOLBAR_CALLBACK~GET_NUMBER_OF_VISIBLE_BUTTONS. This method controls the no of visible buttons on tool bar. Redefine it and give any integer value greater than 3. If you give 4, then four buttons will be visible on tool bar and remaining buttons if exists any will be displayed as above.
Go to the overview page implementation class and redefine the method SET_VIEW_GROUP_CONTEXT. Write following code and activate it.
Let us add three buttons to the overview page to provide EDIT, SAVE and CANCEL operations. In order to add buttons to overview page, we need to add the code to the method IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS of over view page implementation class.
Go the overview page in UI component and redefine the method by choosing the option redefine after right clicking on it. After redefining it, double click on it to open the method.
Add the following code activate it.
When you are adding a new button to standard SAP overview page, do not forget to call the super class method.
ON_CLICK: we will assign event handler name to this property. So when this button is clicked, event handler will be triggered. (event handler name is case sensitive ).
TYPE : we can specify an icon over here. CL_THTMLB_UTIL has number of icons.
PAGE_ID : it is page id in framework language. It could be look like this. C1_W1_V1 where C1 is your component controller and W1 is window and V1 is your current view.
Enabled : if this property is true, then button is enabled else disabled.
It is a standard scenario that once you click on EDIT button, page will be in editable mode. In this mode only we will enable save ,cancel buttons and Edit button will be disabled.
When user clicks either SAVE or CANCEL, then again EDIT button will be enabled. SAVE and CANCEL buttons will be disabled.
We are manipulating the ENABLED property of each button exactly in above mentioned way.
We will discuss the scenario for EDIT button.
Its clear that , to edit or save or cancel, there should be data. So we are reading the data from current context node into lr_header.
First conditions is LR_HEADER is BOUND, which means if there is data, second is LR_header->IS_CHANGE_ALLOWED which means, if data can be changed (why we are testing this condition because the same data may be locked by different user at this point of time) and last condition is VIEW_GROUP_CONTEXT->IS_ANY_VIEW_EDITABLE = ABAP_FALSE which means, no view is already in EDIT mode, then enable the EDIT button else disable it.
You can try to understand the logic for remaining buttons.
Activate and test the application.
We can notice all buttons are coming under group MORE. This is happened because we forgot to redefine one more method IF_BSP_WD_TOOLBAR_CALLBACK~GET_NUMBER_OF_VISIBLE_BUTTONS. This method controls the no of visible buttons on tool bar. Redefine it and give any integer value greater than 3. If you give 4, then four buttons will be visible on tool bar and remaining buttons if exists any will be displayed as above.
Test the application. All your buttons should be visible.