‎2007 Oct 23 3:03 PM
Dear SAP friends,
There is a method in class CL_GUI_TOOLBAR to SET button state:
CALL METHOD toolbar_top->set_button_state
EXPORTING
enabled = s_buttons-state
fcode = s_buttons-fcode.
Can't find a method to GET the button state...
In my maintenance program I disable top toolbar buttons when they get into EDIT mode. When EDIT mode is completed I want to enable only those buttons which were enabled before they got into EDIT.
So - I need to remember the button state so I could restore it later.
What is method to GET button state?
Thank you
Tatyana
‎2007 Oct 23 3:17 PM
Hello Tatyana
The public (read-only) instance attribute <b>M_TABLE_BUTTON</b> of <b>CL_GUI_TOOLBAR</b> stored the current state of all buttons. Thus, if you store the contents of this attribute before (PBO) you switch the EDIT mode you have the current status of all buttons.
Regards
Uwe
‎2007 Oct 23 3:17 PM
Hello Tatyana
The public (read-only) instance attribute <b>M_TABLE_BUTTON</b> of <b>CL_GUI_TOOLBAR</b> stored the current state of all buttons. Thus, if you store the contents of this attribute before (PBO) you switch the EDIT mode you have the current status of all buttons.
Regards
Uwe
‎2007 Oct 23 3:19 PM
Hi,
Please try to read table M_TABLE_BUTTON where DISABLED = 'X'.
Regards,
Ferry Lianto
‎2007 Oct 23 3:26 PM
‎2007 Oct 23 3:32 PM
Hello Tatyana
When you have finished creation of your GUI toolbar M_TABLE_BUTTON is filled as described by Ferry:
- DISABLED = 'X' " inactive buttons
- DISABLED = ' ' " active buttonsStore the instance attribute (e.g. in lt_table_buttons_pbo) and reset it afterwards:
LOOP AT lt_table_buttons_pbo INTO ls_button.
go_toolbar->set_button_info( fcode = ls_button-fcode ... ).
ENDLOOP.Regards
Uwe
‎2007 Oct 23 3:41 PM
Uwe,
I defined like below:
DATA: it_toolbar_top_buttons TYPE ttb_button.
it_toolbar_top_buttons = cl_gui_toolbar=>m_table_button.
I am getting compile error:
You can only use "class=>attr with static methods.
What is wrong please?
Tatyana
‎2007 Oct 23 3:42 PM
Thank you guys,
Please disregard my previous post - You have replied while I was writing my question.
‎2007 Oct 23 3:50 PM
Hi ,
here is the Code for all toolbar .. if you use cntr f and put you SET button then
REPORT sapmz_hf_toolbar .
TYPE-POOLS: icon.
CLASS cls_event_handler DEFINITION DEFERRED.
*--- G L O B A L D A T A
DATA:
ok_code LIKE sy-ucomm,
* Global varables for position of context menu
g_posx TYPE i,
g_posy TYPE i,
* Reference for conatiner
go_toolbar_container TYPE REF TO cl_gui_custom_container,
* Reference for SAP Toolbar
go_toolbar TYPE REF TO cl_gui_toolbar,
* Event handler
go_event_handler TYPE REF TO cls_event_handler,
* Context menu
go_context_menu TYPE REF TO cl_ctmenu.
*--- G L O B A L T A B L E S
DATA:
* 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,
* Table for button group
gi_button_group TYPE ttb_button.
*---------------------------------------------------------------------*
* CLASS CLS_EVENT_HANDLER
*---------------------------------------------------------------------*
* This class handles the function_selected and dropdow_clicked events
* from the toolbar
*---------------------------------------------------------------------*
CLASS cls_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
on_function_selected
FOR EVENT function_selected OF cl_gui_toolbar
IMPORTING fcode,
on_dropdown_clicked
FOR EVENT dropdown_clicked OF cl_gui_toolbar
IMPORTING fcode posx posy.
ENDCLASS.
CLASS cls_event_handler IMPLEMENTATION.
METHOD on_function_selected.
*-- Actions for buttons and context menus
CASE fcode.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'ENABLE'.
* Enable the PRINT button
CALL METHOD go_toolbar->set_button_state
EXPORTING
enabled = 'X'
fcode = 'PRINT'.
WHEN 'DISABLE'.
* Disable the PRINT button
CALL METHOD go_toolbar->set_button_state
EXPORTING
enabled = ' '
fcode = 'PRINT'.
* Other menus and context menus
WHEN 'PRINT'.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'Printing'.
WHEN 'CONTEXT1'.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'Menu: Do something funny'.
WHEN 'CONTEXT2'.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'Menu: Do something crazy'.
WHEN 'SUB1'.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'Submenu: Do something boring'.
WHEN 'SUB2'.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'Submenu: Do something good'.
ENDCASE.
ENDMETHOD.
METHOD on_dropdown_clicked.
*-- Fires when a dropdown menu is clicked. After it has been
*-- clicked a context menu is shown beside the button.
* Save x and y position of button for use with context menu
CLEAR: g_posx, g_posy.
g_posx = posx.
g_posy = posy.
* Create context menu for menu button
PERFORM create_context_menu.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SET SCREEN '100'.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
IF go_toolbar_container IS INITIAL.
* Create container
CREATE OBJECT go_toolbar_container
EXPORTING
container_name = 'TOOLBAR_CONTAINER'.
* Create toolbar
CREATE OBJECT go_toolbar
EXPORTING
parent = go_toolbar_container.
* Add a button to the toolbar
PERFORM add_button.
* Add a button group to the toolbar
PERFORM add_button_group.
* Create event table. Note that 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.
CLEAR g_event.
g_event-eventid = go_toolbar->m_id_dropdown_clicked.
g_event-appl_event = 'X'.
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.
* 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_dropdown_clicked
FOR go_toolbar.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form add_button
*&---------------------------------------------------------------------*
* Adds one pushbutton to the toolbar
*----------------------------------------------------------------------*
FORM add_button.
CALL METHOD go_toolbar->add_button
EXPORTING fcode = 'EXIT' "Function Code
icon = icon_system_end "ICON name
is_disabled = ' ' "Disabled = X
butn_type = cntb_btype_button "Type of button
text = 'Exit' "Text on button
quickinfo = 'Exit program' "Quick info
is_checked = ' '. "Button selected
ENDFORM. " add_button
*&---------------------------------------------------------------------*
*& Form add_button_group
*&---------------------------------------------------------------------*
* Adds a button group to the toolbar.
* The buttons are added to table gi_button_group, and the table is used
* as input to the Add_button_group method. Note that method Fill_buttons
* is used to fill the table.
*----------------------------------------------------------------------*
FORM add_button_group.
* Add a seperator
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'SEP1'
icon = ' '
butn_type = cntb_btype_sep
CHANGING
data_table = gi_button_group.
.
* Add an Enable button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'ENABLE'
icon = ' '
butn_type = cntb_btype_group
text = 'Enable'
quickinfo = 'Enable a print button'
checked = 'X'
CHANGING
data_table = gi_button_group.
.
* Add a Disable button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'DISABLE'
icon = ''
butn_type = cntb_btype_group
text = 'Disable'
quickinfo = 'Disable print button'
checked = ' '
CHANGING
data_table = gi_button_group.
* Add a seperator
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'SEP2'
icon = ' '
butn_type = cntb_btype_sep
CHANGING
data_table = gi_button_group.
* Add print button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'PRINT'
icon = icon_print
butn_type = cntb_btype_button
text = 'Print'
quickinfo = 'Print something'
CHANGING
data_table = gi_button_group.
* Add a menu button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'MENU'
icon = ' '
butn_type = cntb_btype_menu
text = 'Menu'
quickinfo = 'A menu buttonz'
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 create_context_menu
*&---------------------------------------------------------------------*
* This form creates a context menu and a submenu for the menu button.
*----------------------------------------------------------------------*
FORM create_context_menu.
DATA: lo_submenu TYPE REF TO cl_ctmenu.
IF go_context_menu IS INITIAL.
*-- Create context menu
CREATE OBJECT go_context_menu.
CALL METHOD go_context_menu->add_function
EXPORTING
fcode = 'CONTEXT1'
text = 'Do something funny'.
CALL METHOD go_context_menu->add_function
EXPORTING
fcode = 'CONTEXT2'
text = 'Do something crazy'.
CALL METHOD go_context_menu->add_separator.
* Create sub menu for the context menu
CREATE OBJECT lo_submenu.
CALL METHOD lo_submenu->add_function
EXPORTING
fcode = 'SUB1'
text = 'Do something boring'.
CALL METHOD lo_submenu->add_function
EXPORTING
fcode = 'SUB2'
text = 'Do something good'.
*-- Add sub menu to the context menu
CALL METHOD go_context_menu->add_submenu
EXPORTING
menu = lo_submenu
text = 'Do something else.....'.
ENDIF.
* Link menu to toolbar button. To position the context menu the
* x and y positions of the menu button is used.
* These values was retrieved in the On_dropdown_clicked
* method of cls_event_handler
CALL METHOD go_toolbar->track_context_menu
EXPORTING
context_menu = go_context_menu
posx = g_posx
posy = g_posy.
ENDFORM. " create_context_menu
Reward points if it is usefull ...
Girish
‎2007 Oct 23 4:11 PM
Uwe and Ferry,
Here is my code thanks to your help:
DATA: BEGIN OF s_buttons,
fcode TYPE ui_func,
icon TYPE iconname,
butn_type TYPE tb_btype,
quickinfo TYPE iconquick,
state TYPE c,
text(40),
END OF s_buttons.
DATA: t_buttons LIKE TABLE OF s_buttons.
DATA: t_buttons_pbo LIKE TABLE OF s_buttons....
* On click EDIT button:
* - Remember top toolbar buttons:
MOVE t_buttons TO t_buttons_pbo....
* On click SAVE or CANCEL buttons:
* - Restore buttons state:
LOOP AT t_buttons_pbo INTO s_buttons.
IF s_buttons-state = 'X'.
CALL METHOD toolbar_top->set_button_state
EXPORTING
enabled = 'X'
fcode = s_buttons-fcode.
ENDIF.The code works.
Thank you very much!
Tatyana