Controls Framework

Controls Framework
  1. General

  2. Synchronization/Flush

  3. Set up event handling for controls

  4. Declare a reference variable before the class has been defined

  5. Set focus to a control

General

Control Framework and enheritance hierarchy

The control framework consists of 2 parts:

  • CL_GUI_CFW contains methods that provide services for communication with the frontend, and can be used both by control wrapper calsses and by control progtrammers
  • The CL_GUI_OBJECT encapsulates ActiveX or JavaBeans methods, while CL_GUI_CONTROL is responsible for displaying the control on the screen.

CL_GUI_OBJECT -> CL_GUI_CONTROL -> CL_GUI_* (Wrapper class)

These classes contains methods that are enherited by subsequent classes in the enheritance tree.

Synchronization/Flush

RFC calls is used to synchronize the front and backend. This synchronization takes palce at some predifined points in the program flow. However you should not rely entirely on automatic synchronization, but force synchronization with the Flush method when necessary.

Bear in mind that the synchronization/RFC calls represenmts a bottleneck, so you should keep the not use the Flush method to a minimum.

Syntax:

CALL METHOD cl_gui_cfw=>FLUSH

Set up event handling for controls

There are two types of events:

Application events. T

The flow logic of the screen is processed after the event (The PAI module is processed).

In the events table the event must be registred as an application event by setting then field appl_event to 'X':

wa_events-eventid = cl_gui_textedit=>event_double_click.
wa_events-appl_event = 'X'.
append wa_events to i_events.

Important: The dispatch method of cl_gui_cfw must be called in the PAI module:

CALL METHOD cl_gui_cfw=>dispatch.

System events.

For system events the flow-logic of the screen is not executed. That means that the PAI and PBO modules are not processed.

In the events table the the field appl_event must be set to SAPCE:

wa_events-eventid = cl_gui_textedit=>event_double_click.
wa_events-appl_event = space.
append wa_events to i_events.

The dispatch method of cl_gui_cfw must NOT be called.

Example

It is presumed that a SAP toolbar control named go_toolbar of class cl_gui_toolbar has been defined. To see a complete example of how to handle events, refer to The SAP toolbar control.

Data:

* 1.  Define and instance of the eventhandler class.

*      If the event handler class is defined after the data decalaration

*      the class must be declared as DEFERRED in the top of the program:  
*      CLASS cls_event_handler DEFINITION DEFERRED.

  go_event_handler TYPE REF TO cls_event_handler,
* 2. Define table for registration of events. 

*     Note that a TYPE REF   to cls_event_handler must be created before you can

*     reference types cntl_simple_events and cntl_simple_event

  gi_events TYPE cntl_simple_events,

* Workspace for table gi_events

  g_event TYPE cntl_simple_event.
* 3. Define and implement eventhandler class

CLASS cls_event_handler DEFINITION.

  PUBLIC SECTION.

    METHODS:

*     Syntax:

*      FOR EVENT 

*         OF 

      on_function_selected

        FOR EVENT function_selected OF cl_gui_toolbar

          IMPORTING fcode,

ENDCLASS.
CLASS cls_event_handler IMPLEMENTATION.

   METHOD on_function_selected.

*     Do something when the event is raised

  ENDMETHOD.

ENDCLASS.
* 4. Append events to the events table

*     The Event Id  can be found in the control documentation. Note that 
*      The event below is registred as an application event

 g_event-eventid         = go_toolbar->m_id_function_selected.

 g_event-appl_event   = 'X'.    "This is an application event

APPEND g_event TO gi_events.

.... append more events i necessary...
* 5. Use the events table to register events for the control

    CALL METHOD go_toolbar->set_registered_events

        EXPORTING

           events = gi_events.
* 6. Create event handler

CREATE OBJECT   go_event_handler.
* Syntax:

* SET HANDLER  -> 

*   FOR 

SET HANDLER go_event_handler->on_function_selected

      FOR go_toolbar.

Declare a reference variable before the class has been defined

Scenario:

DATA: o_my_class TYPE REF TO lcl_myclass.

CLASS lcl_myclass.....
ENDCLASS.

This will cause an error because the definition of class lcl_myclass is after the declaration.

Solution:

Define the class in the beginning of the program with DEFINITION DEFERRED:

CLASS lcl_myclass DEFINITION DEFERRED.

DATA: o_my_class TYPE REF TO lcl_myclass.

CLASS lcl_myclass.....
ENDCLASS.

Set focus to a control

Set the focus to a control named go_grid:

CALL METHOD cl_gui_control=>set_focus 

  EXPORTING control = go_grid.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/190059/viewspace-476534/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/190059/viewspace-476534/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值