二维码

[教程] UNDERSTANDING VIEW GROUP CONTEXT

Twilight发表于 2015-12-08 00:00Twilight 最后回复于 2015-12-08 00:00 [复制链接] 3380 0

Before doing operations like edit, save and create operations, we need to know one concept called VIEW GROUP CONTEXT.

When we are on overview page, certain times, we need to put all assignment blocks in edit mode and some times, only few or one assignment block should be edited.

Every implementation class of view has one attribute called VIEW_GROUP_CONTEXT which is type of IF_BSP_WD_VIEW_GROUP_CONTEXT.

At runtime view group context instance can be represented using the class CL_BSP_WD_VIEW_GROUP_CONTEXT.

Generally we create an instance of view group for top level controllers. Suppose if OP is an overview page, which is hosting three different assignment blocks A, B and C. Then we will set the property VIEW_GROUP_CONTEXT of OP implementation class. Remaining views A, B and C will automatically inherit its parent view group context. Here their parent is OP.

We use SET_VIEW_GROUP_CONTEXT method to set the VIEW_GROUP_CONTEXT property. When setting this property, we always check whether its parent view group context is initial or not. If it is initial, then only we will create one instance of class CL_BSP_WD_VIEW_GROUP_CONTEXT and assign this instance to the VIEW GROUP CONTEXT property. Code will look like below.
  1. METHOD set_view_group_context.
  2.   IF iv_first_time EQ abap_true AND view_group_context IS INITIAL.
  3.     IF iv_parent_context IS INITIAL.
  4.       CREATE OBJECT view_group_context TYPE cl_bsp_wd_view_group_context.
  5.     ELSE.
  6.       view_group_context ?= iv_parent_context.
  7.     ENDIF.
  8.   ENDIF.
  9. ENDMETHOD.
复制代码
We can see that we are checking first parent view group context. If it is not initial, then we are assigning it to the current view viewgroupcontext property else we are creating new one.

This class offers some methods to control the display mode of views.

In order to set a view in editable mode, we use IF_BSP_WD_VIEW_GROUP_CONTEXT~SET_VIEW_EDITABLE method by sending the instance of view implementation class to it.

In order to check, whether a view is in editable mode or not, we use IF_BSP_WD_VIEW_GROUP_CONTEXT~IS_VIEW_IN_DISPLAY_MODE method by sending the instance of view implementation class to it.

To put all views in editable mode, we use IF_BSP_WD_VIEW_GROUP_CONTEXT~SET_ALL_EDITABLE ( ). This method will be used in top level controllers like OVERVIEW PAGES.

To make any view which is in editable mode in to display mode, we use IF_BSP_WD_VIEW_GROUP_CONTEXT~RESET (). This method not only reset the current view group context but also reset the view group context of its children.

Users who generally work on transactions may know that clicking on CANCEL button on top will put all views in to display mode at one go.

Whenever we use IF_BSP_WD_VIEW_GROUP_CONTEXT~SET_VIEW_EDITABLE method, it simply adds our view to one internal table. See the below code.
VIEW GROUP CONTEXT 2.jpg

Later when you use the method IF_BSP_WD_VIEW_GROUP_CONTEXT~IS_VIEW_IN_DISPLAY_MODE, it by sending instance of view controller, it simply checks whether this controller is there in the internal table or not. If it is there, then it will return false saying that it is not in display mode else it will return true.
VIEW GROUP CONTEXT 3.jpg

This flag will be given to the DISPLAY MODE property of major configuration tags. So finally based on this value returned by the above mentioned method, configuration tags will decide to make a view editable or not. You can find below code on major views .htm pages.
Like below.
VIEW_GROUP_CONTEXT.jpg
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表