SAP control framework-instance

Source: Internet
Author: User

Reference: skysky

274 views

1.1 example

Let's take a small example to use these three classes. We will introduce the specific usage of the dragdrop class later.

Background:

We get an image and display it in picture control. Add a toolbar and use the buttons in the toolbar to control the image size and display mode. You can use context menu to implement some control measures, such as deleting images and opening new images.

8.4.1 define data

* Class Pre-define which used to reference

Class lcl_pic_container definition deferred.

Class event_receiver definition deferred.

Class lcl_toolbar definition deferred.

Class cl_gui_cfw definition load.

* Screen field for program

Data: OK _code like sy-ucomm.

Data: s_object_id type string,

S_object_value type string.

Data: ename (50) type C.

* Picture container and custom container

Data: container_pic type ref to cl_gui_custom_container,

Container_h type ref to cl_gui_custom_container,

Container_v type ref to cl_gui_custom_container.

Data: ref_pic type ref to lcl_pic_container,

Ref_tool type ref to lcl_toolbar.

* If the control created indicator

Data: init type C.

* Data for load pre-defined context menu *******

Data: prog type sy-repid.

8.4.2 create a screen

Define context menu form

Define context menu

Process pre-defined context

* Using the form routine which defined in you dynpro

Form on_ctmenu_input using l_menu type ref to cl_ctmenu.

Prog = sy-repid.

Call method: l_menu-> load_gui_status

Exporting program = prog

Status = 'pf1 '"Your context menu name

Menu = l_menu.

Call method l_menu-> add_function

Exporting fcode = 'getn'

TEXT = 'select new picture '.

Endform.

Define the PIC class

Class lcl_pic_container definition.

Public section.

Data: object_id type string,

Object_value type string.

Constants:

Id_bmap (5) value 'bmap ',

Value_enjoy (20) value 'enable ',

Value_sapsmartforms (20) value 'sapsmartforms ',

Value_mysapcom (20) value 'mysapcom '.

Methods:

* Initialize Screen

Init_screen,

* Add picture to picture container

Add_pic,

* Free objects

Free,

* Setter, set picture ID and type

Set_object

Importing I _object_id type string

I _object_value type string,

Get_object

Exporting value (e_id) type string

Value (e_name) type string.

Private section.

Data:

PIC type ref to cl_gui_picture,

URLs (255 ).

* For picture control events

Data:

Event Type cntl_simple_event,

Events type cntl_simple_events.

Data:

Event_ref type ref to event_receiver.

Methods:

* Get picture URL

Get_pic_url

Importing I _object_id type string

I _object_value type string

Returning Value (s_url) type string,

* Set pf-status

Set_pf_status,

* Set handler for picture control

Set_handler.

Endclass.

8.4.4 define a toolbar class

Class lcl_toolbar definition.

Public section.

Methods:

* Create class

Constructor

Importing pic_ref type ref to cl_gui_picture,

Free.

Private section.

* Define two Toolbar

Data:

H_ref type ref to cl_gui_toolbar,

V_ref type ref to cl_gui_toolbar.

* Toolbar events

Data:

Event Type cntl_simple_event,

Events type cntl_simple_events.

Data:

Event_ref type ref to event_receiver.

* Define button group table

Data:

Bgroup type ttb_button.

Data: PICT type ref to cl_gui_picture.

* Private Method for add toolbar button group

Methods:

Add_button_group importing

Fcode type ui_func

Icon type iconname

Type type tb_btype

Text Type text40

Tip type iconquick.

Endclass.

8.4.5 define event processing class

* For toolbar and picture control and context menu event handle

Class event_receiver definition.

Public section.

Methods:

* For create class, get the object which created it

Constructor

Importing pic_ref type ref to object,

* Events for picture control ****************

Event_dblclick for event picture_dblclick

Of cl_gui_picture

Importing sender,

Event_click for event picture_click

Of cl_gui_picture

Importing sender,

Event_con_menu for event context_menu

Of cl_gui_picture

Importing sender,

Event_con_menu_sel for event context_menu_selected

Of cl_gui_picture

Importing fcode sender,

* Events for picture control ****************

* Events for Toolbar Control ****************

Event_t_f_sel for event function_selected

Of cl_gui_toolbar

Importing fcode sender,

Event_t_d_clk for event dropdown_clicked

Of cl_gui_toolbar

Importing fcode posx posy sender.

* Events for Toolbar Control ****************

Private section.

* Indicator for object swich

Data: Flag type C.

Data: flag_h_type C.

* Catch cast exception

Data: cast type C.

Data: PICT type ref to cl_gui_picture.

Endclass.

8.4.6 implementation classes

For the PIC class, the method init_screen initializes the screen

Method init_screen.

Call method set_pf_status.

* Create custom container for picture container

Create object container_pic

Exporting

Container_name = 'iner iner _ PIC '.

* Create picture control

Create object PIC

Exporting

Parent = container_pic.

* Create toolbar in screen

Create object ref_tool

Exporting pic_ref = pic.

* Add events for picture control

Event-eventid = cl_gui_picture => eventid_picture_click.

Event-appl_event = 'x '.

Append event to events.

Event-eventid = cl_gui_picture => eventid_picture_dblclick.

Event-appl_event = 'x '.

Append event to events.

Event-eventid = cl_gui_picture => eventid_context_menu.

Event-appl_event = 'x '.

Append event to events.

Event-eventid = cl_gui_picture => eventid_context_menu_selected.

Event-appl_event = 'x '.

Append event to events.

* Register events for picture control

Call method pic-> set_registered_events

Exporting events = events.

* Set handler for picture control

Call method set_handler.

* Set picture control border type

Call method pic-> set_3d_border

Exporting border = 1.

* Set picture ID and name

Call method ref_pic-> set_object

Exporting I _object_id = s_object_id

I _object_value = s_object_value.

* Add picture to picture control

Call method add_pic.

* Set object created indicator

Init = 'x '.

Endmethod.

PbO Processing

Module status_0100 output.

If init is initial.

Create object ref_pic.

S_object_id = lcl_pic_container => id_bmap.

S_object_value = lcl_pic_container => value_sapsmartforms.

Call method ref_pic-> init_screen.

Endif.

Endmodule. "status_0100 output

All code

1.2 test results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.