Code: Alles auswählen.
report z_test.
" ___ DEFINITION ____________________________________________________
class lcl_salv_handler definition.
public section.
types:
begin of lty_parameter,
dialog_with_splitter type boolean_flg,
dialog_with_text_editor type boolean_flg,
salv_in_fullscreen type boolean_flg,
end of lty_parameter.
methods:
constructor importing is_parameter type lty_parameter.
private section.
types:
begin of lty_dialog,
container type ref to cl_gui_dialogbox_container,
begin of dimensions,
height type i,
left type i,
top type i,
width type i,
end of dimensions,
splitter_bottom type ref to cl_gui_container,
splitter_container type ref to cl_gui_splitter_container,
splitter_top type ref to cl_gui_container,
text_editor type ref to cl_gui_textedit,
toolbar type ref to cl_gui_toolbar,
end of lty_dialog.
data:
mo_salv type ref to cl_salv_table,
mt_data type standard table of sbuspart with default key,
ms_dialog type lty_dialog,
ms_parameter type lty_parameter,
mv_selected_row type i.
methods:
adopt_change,
close_dialog,
create_salv,
show_dialog,
" --- event methods -------------------------------------------
on_dialog_close for event close of cl_gui_dialogbox_container importing sender,
on_dialog_toolbar_function for event function_selected of cl_gui_toolbar importing fcode,
on_double_click for event double_click of cl_salv_events_table importing row column.
endclass.
" ___ IMPLEMENTATION ________________________________________________
class lcl_salv_handler implementation.
" === adopt change ================================================
method adopt_change.
check ms_dialog-text_editor is not initial.
ms_dialog-text_editor->get_textstream(
importing
is_modified = data(lv_is_modified)
text = data(lv_text)
).
cl_gui_cfw=>flush( ).
check lv_is_modified is not initial.
mt_data[ mv_selected_row ]-contact = lv_text.
mo_salv->refresh(
refresh_mode = if_salv_c_refresh=>full
s_stable = value #(
col = abap_true
row = abap_true
)
).
if ms_parameter-salv_in_fullscreen is not initial.
cl_gui_cfw=>set_new_ok_code( |OK| ). " change is only shown after pai trigger
endif.
endmethod.
" === close dialog ================================================
method close_dialog.
check ms_dialog-container is not initial.
ms_dialog-container->get_height( importing height = ms_dialog-dimensions-height ).
ms_dialog-container->get_left( importing left = ms_dialog-dimensions-left ).
ms_dialog-container->get_top( importing top = ms_dialog-dimensions-top ).
ms_dialog-container->get_width( importing width = ms_dialog-dimensions-width ).
" --- free text editor ------------------------------------------
if ms_dialog-text_editor is not initial.
" =============================================================
" normally, adopt_change() should only be called when the user
" clicks on 'OK'. but as the text editor and toolbar cannot be
" shown together, the call of adopt_change( ) is included here.
" this line can be removed when the issue has been resolved.
" =============================================================
adopt_change( ).
ms_dialog-text_editor->free( ).
free ms_dialog-text_editor.
endif.
" --- free toolbar ----------------------------------------------
if ms_dialog-toolbar is not initial.
ms_dialog-toolbar->free( ).
free ms_dialog-toolbar.
endif.
" --- free splitter ---------------------------------------------
if ms_dialog-splitter_container is not initial.
if ms_dialog-splitter_top is not initial.
ms_dialog-splitter_container->remove_control(
column = 1
row = 1
).
ms_dialog-splitter_top->free( ).
free ms_dialog-splitter_top.
endif.
if ms_dialog-splitter_bottom is not initial.
ms_dialog-splitter_container->remove_control(
column = 1
row = 2
).
ms_dialog-splitter_bottom->free( ).
free ms_dialog-splitter_bottom.
endif.
ms_dialog-splitter_container->free( ).
free ms_dialog-splitter_container.
endif.
" --- free dialog -----------------------------------------------
ms_dialog-container->free( ).
free ms_dialog-container.
clear mv_selected_row.
endmethod.
" === constructor =================================================
method constructor.
ms_parameter = is_parameter.
ms_dialog-dimensions = value #(
height = 200
left = 200
top = 60
width = 400
).
select *
into corresponding fields of table mt_data
from sbuspart up to 20 rows.
create_salv( ).
endmethod.
" === create salv =================================================
method create_salv.
try.
if ms_parameter-salv_in_fullscreen is initial.
cl_salv_table=>factory(
exporting
r_container = cl_gui_container=>default_screen
importing
r_salv_table = mo_salv
changing
t_table = mt_data
).
else.
cl_salv_table=>factory(
importing
r_salv_table = mo_salv
changing
t_table = mt_data
).
mo_salv->get_functions( )->set_default( abap_true ).
endif.
mo_salv->get_columns( )->set_optimize( abap_true ).
mo_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>cell ).
set handler on_double_click for mo_salv->get_event( ).
catch cx_root.
" ...
endtry.
mo_salv->display( ).
if ms_parameter-salv_in_fullscreen is initial.
write space.
endif.
endmethod.
" === on dialog close =============================================
method on_dialog_close.
check sender is not initial.
close_dialog( ).
endmethod.
" === on dialog toolbar function ==================================
method on_dialog_toolbar_function.
case fcode.
when 'CANCEL'. close_dialog( ).
when 'OK'. adopt_change( ). close_dialog( ).
endcase.
endmethod.
" === on double click =============================================
method on_double_click.
check row > 0
and ms_dialog-container is initial.
mv_selected_row = row.
show_dialog( ).
endmethod.
" === show dialog =================================================
method show_dialog.
check ms_dialog-container is initial.
" --- create dialog ---------------------------------------------
ms_dialog-container = new #(
height = ms_dialog-dimensions-height
left = ms_dialog-dimensions-left
parent = cl_gui_container=>default_screen
top = ms_dialog-dimensions-top
width = ms_dialog-dimensions-width
).
set handler on_dialog_close for ms_dialog-container.
" --- splitter --------------------------------------------------
if ms_parameter-dialog_with_splitter is not initial.
ms_dialog-splitter_container = new #(
columns = 1
parent = ms_dialog-container
rows = 2
).
ms_dialog-splitter_top = new cl_gui_custom_container(
container_name = 'DIALOG_TOP'
).
ms_dialog-splitter_container->add_control(
column = 1
control = ms_dialog-splitter_top
row = 1
).
ms_dialog-splitter_bottom = new cl_gui_custom_container(
container_name = 'DIALOG_BOTTOM'
).
ms_dialog-splitter_container->add_control(
column = 1
control = ms_dialog-splitter_bottom
row = 2
).
endif.
" --- text editor -----------------------------------------------
if ms_parameter-dialog_with_text_editor is not initial.
ms_dialog-text_editor = new #(
parent = switch #( ms_parameter-dialog_with_splitter
when space then ms_dialog-container
else ms_dialog-splitter_top
)
).
ms_dialog-text_editor->set_textstream(
conv #( mt_data[ mv_selected_row ]-contact )
).
endif.
" --- toolbar ---------------------------------------------------
ms_dialog-toolbar = new #(
parent = switch #( ms_parameter-dialog_with_splitter
when space then ms_dialog-container
else ms_dialog-splitter_bottom
)
).
ms_dialog-toolbar->add_button(
butn_type = cntb_btype_button
fcode = 'OK'
icon = icon_okay
text = 'OK'
).
ms_dialog-toolbar->add_button(
butn_type = cntb_btype_button
fcode = 'CANCEL'
icon = icon_cancel
text = 'Cancel'
).
ms_dialog-toolbar->set_registered_events(
value #(
(
appl_event = 'X'
eventid = ms_dialog-toolbar->m_id_function_selected
)
)
).
set handler on_dialog_toolbar_function for ms_dialog-toolbar.
endmethod.
endclass.
* ___ INITIALIZATION ________________________________________________
initialization.
parameters:
p_salvfs as checkbox, " salv in fullscreen
p_diaspl as checkbox, " dialog with splitter
p_diated as checkbox. " dialog with text editor
data lt_seltexts type standard table of rsseltexts with default key.
lt_seltexts = value #(
( kind = |P| name = |P_DIASPL| text = |Dialog with Splitter| )
( kind = |P| name = |P_DIATED| text = |Dialog with Text Editor| )
( kind = |P| name = |P_SALVFS| text = |SALV in Fullscreen| )
).
call function 'SELECTION_TEXTS_MODIFY'
exporting
program = sy-cprog
tables
seltexts = lt_seltexts.
* ___ START-OF-SELECTION ____________________________________________
start-of-selection.
data(lo_salv_handler) = new lcl_salv_handler(
value #(
dialog_with_splitter = p_diaspl
dialog_with_text_editor = p_diated
salv_in_fullscreen = p_salvfs
)
).
Code: Alles auswählen.
" --- splitter --------------------------------------------------
if ms_parameter-dialog_with_splitter is not initial.
ms_dialog-splitter_container = new #(
columns = 1
parent = ms_dialog-container
rows = 2
).
ms_dialog-splitter_top = ms_dialog-splitter_container->get_container( column = 1 row = 1 ).
ms_dialog-splitter_bottom = ms_dialog-splitter_container->get_container( column = 1 row = 2 ).
endif.