您的位置:首页 > Web前端 > HTML

The SAP HTML viewer

2008-10-31 16:38 183 查看

The SAP HTML viewer.

Note that the SAP HTML viewer uses internet Explorer 4.0 or higher.

This example uses the SAP HTML viewer to browse the internet. The navigation buttons are placed on a SAP Toolbar control. The Goto URL button and field are normal dynpro elements, and so is the Show URL field.

Steps:

Create a screen and palce a container named go_html_container for the HTML viewer.
Create a dynpro button with ethe text GGoto url and functioncode GOTOURL.
Create a dynpro input/output field named G_SCREEN100_URL_TEXT. This field is used to key in the url.
Create a dynpro input/output field named G_SCREEN100_DISPLAY_URL. This field is used to show the current url

The screen:



The code

SAPMZ_HF_HTML_CONTROL

REPORT sapmz_hf_html_control .

TYPE-POOLS: icon.

CLASS cls_event_handler DEFINITION DEFERRED.

*-------------------------------------------------------------------
* G L O B A L  V A R I A B L E S
*-------------------------------------------------------------------
DATA:
ok_code                 LIKE sy-ucomm,
* Container for html vieaer
go_html_container       TYPE REF TO cl_gui_custom_container,
* HTML viewer
go_htmlviewer           TYPE REF TO cl_gui_html_viewer,
* Container for toolbar
go_toolbar_container    TYPE REF TO cl_gui_custom_container,
* SAP Toolbar
go_toolbar              TYPE REF TO cl_gui_toolbar,
* Event handler for toolbar
go_event_handler        TYPE REF TO cls_event_handler,
* Variable for URL text field on screen 100
g_screen100_url_text(255) TYPE c,
g_screen100_display_url(255) TYPE c.

*-------------------------------------------------------------------
* I N T E R N A L   T A B L E S
*-------------------------------------------------------------------
DATA:
* Table for button group
gi_button_group            TYPE ttb_button,
* 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.

START-OF-SELECTION.
SET SCREEN '100'.

*---------------------------------------------------------------------*
*       CLASS cls_event_handler DEFINITION
*---------------------------------------------------------------------
* Handles events for the toolbar an the HTML viewer
*---------------------------------------------------------------------*
CLASS cls_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* Handles method function_selected  for the toolbar control
on_function_selected
FOR EVENT function_selected OF cl_gui_toolbar
IMPORTING fcode,
* Handles method navigate_complete for the HTML viewer control
on_navigate_complete
FOR EVENT navigate_complete OF cl_gui_html_viewer
IMPORTING url.
ENDCLASS.

CLASS cls_event_handler IMPLEMENTATION.

* Handles method function_selected  for the toolbar control
METHOD on_function_selected.
CASE fcode.
WHEN 'BACK'.
CALL METHOD go_htmlviewer->go_back
EXCEPTIONS cntl_error = 1.
WHEN 'FORWARD'.
CALL METHOD go_htmlviewer->go_forward
EXCEPTIONS cntl_error = 1.
WHEN 'STOP'.
CALL METHOD go_htmlviewer->stop
EXCEPTIONS cntl_error = 1.

WHEN 'REFRESH'.
CALL METHOD go_htmlviewer->do_refresh
EXCEPTIONS cntl_error = 1.

WHEN 'HOME'.
CALL METHOD go_htmlviewer->go_home
EXCEPTIONS cntl_error = 1.

WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.

* Handles method navigate_complete for the HTML viewer control
METHOD on_navigate_complete.
*   Display current URL in a textfield on the screen
g_screen100_display_url = url.
ENDMETHOD.

ENDCLASS.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

IF go_html_container IS INITIAL.
* Create container for HTML viewer
CREATE OBJECT go_html_container
EXPORTING
container_name = 'HTML_CONTAINER'.

* Create HTML viewer
CREATE OBJECT go_htmlviewer
EXPORTING parent = go_html_container.

* Create container for toolbar
CREATE OBJECT go_toolbar_container
EXPORTING
container_name = 'TOOLBAR_CONTAINER'.

* Create toolbar
CREATE OBJECT go_toolbar
EXPORTING
parent = go_toolbar_container.

* Add buttons to the toolbar
PERFORM add_button_group.

* Create event table. The event ID must be found in the
* documentation of the specific control
CLEAR g_event.
REFRESH gi_events.
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.

g_event-eventid    = go_htmlviewer->m_id_navigate_complete.
APPEND g_event TO gi_events.

* Use the events table to register events for the control
CALL METHOD go_toolbar->set_registered_events
EXPORTING
events = gi_events.

CALL METHOD go_htmlviewer->set_registered_events
EXPORTING
events = gi_events.

* Create event handlers
CREATE OBJECT go_event_handler.

SET HANDLER go_event_handler->on_function_selected
FOR go_toolbar.

SET HANDLER go_event_handler->on_navigate_complete
FOR go_htmlviewer.

ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
* Handles the pushbutton for goto url
CASE ok_code.
WHEN 'GOTOURL'.
PERFORM goto_url.
ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  add_button_group
*&---------------------------------------------------------------------*
*  Adds a button group to the toolbar
*-----------------------------------------------------------------------
FORM add_button_group.

* BACK botton
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'BACK'
icon               = icon_arrow_left
butn_type          = cntb_btype_button
text               = ''
quickinfo          = 'Go back'
CHANGING
data_table         = gi_button_group.

* FORWARD botton
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'FORWARD'
icon               = icon_arrow_right
butn_type          = cntb_btype_button
text               = ''
quickinfo          = 'Go forward'
CHANGING
data_table         = gi_button_group.

* STOP button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'STOP'
icon               = icon_breakpoint
butn_type          = cntb_btype_button
text               = ''
quickinfo          = 'Stop'
CHANGING
data_table         = gi_button_group.

* REFRESH button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'REFRESH'
icon               = icon_refresh
butn_type          = cntb_btype_button
text               = ''
quickinfo          = 'Refresh'
CHANGING
data_table         = gi_button_group.

* Home button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'HOME'
icon               = ''
butn_type          = cntb_btype_button
text               = 'Home'
quickinfo          = 'Home'
CHANGING
data_table         = gi_button_group.

* Separator
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'SEP1'
icon               = ' '
butn_type          = cntb_btype_sep
CHANGING
data_table         = gi_button_group.

* EXIT button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode              = 'EXIT'
icon               =  icon_close
butn_type          =  cntb_btype_button
text               = ''
quickinfo          = 'Close porgram'
CHANGING
data_table         = gi_button_group.

* Add button group to toolbar
CALL METHOD go_toolbar->add_button_group
EXPORTING data_table = gi_button_group.

ENDFORM.                    " add_button_group
*&---------------------------------------------------------------------*
*&      Form  goto_url
*&---------------------------------------------------------------------*
*  Calls method SHOW_URL to navigate to an URL
*----------------------------------------------------------------------
FORM goto_url.

CALL METHOD go_htmlviewer->show_url
EXPORTING url = g_screen100_url_text.

ENDFORM.                    " goto_url
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐