cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically add View Container Element to a Tab

Former Member
0 Kudos

How do you dynamically add a view container element (or any UI element like a button) to a Tab (cl_wd_tab)?

Thanks.

Giscard

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I think it might be late to answer you query....but this might help other people...so i am trying to explain this here:

In my test case i have three views: Main, view2, and view3...and they contain following...

Main view: has one transparent container with id: T_CONT and a tabstrip with id: TAB_STRIP

VIEW2: has one text ui element with static text: 'This is view2'

VIEW3: has one text ui element with static text: 'This is view3'

my goal in ths test example was to create the tabs dynamically under this TAB_STRIP and then add a view ui container to it and show these view2 and view3 under there corresponding tab....so tab1 will have view2 and tab2 will have view3 in it....

also i am just creating two text ui element dynamically, one text ui element has a tooltip....this is just a testing exercise...

1) after creating the main view and adding the mentioned ui elements...transparent container and tabstrip in it...go to WDDOMODIFYVIEW method of this main view....

*******************************************************************************************************************************************

2) add this following code:

IF first_time = abap_true.

DATA: ld_container TYPE REF TO cl_wd_uielement_container,

ld_vc TYPE REF TO cl_wd_view_container_uielement,

ld_textview TYPE REF TO cl_wd_text_view,

ld_textview2 TYPE REF TO cl_wd_text_view,

ld_tab1 TYPE REF TO cl_wd_tab,

ld_tabstrip TYPE REF TO cl_wd_tabstrip.

DATA ld_tcap TYPE REF TO cl_wd_caption.

DATA id_textviewui TYPE string.

DATA loop_num(2) TYPE n.

DATA l_txt TYPE string.

DATA l_txt2 TYPE string.

DATA txt_tooltip TYPE string.

DATA tab_id TYPE string.

DATA cap_id TYPE string.

*now get the ref. to all the component

ld_container ?= view->get_element( 'T_CONT' ).

ld_tabstrip ?= view->get_element( 'TAB_STRIP' ).

*this is where i am creating a viewui container called "VIEW_C"

ld_vc = cl_wd_view_container_uielement=>new_view_container_uielement(

id = 'VIEW_C'

).

*this loops creates two tabs for me---this loop can be replaced with any looping on a table which has specific data to show under *each tab

DO 2 TIMES.

loop_num = sy-index.

*this is where i am just creating some text to show on the screen using the dynamically created text ui element

concatenate 'This is Text #:' loop_num into l_txt separated by space.

*creating the id for the dynamically created textview ui element

CONCATENATE 'TEXT' loop_num INTO id_textviewui.

*I just want the tooptip to appear on the first text view ui element

IF sy-index = 1.

CONCATENATE 'This is tooltip dynamically generated' ' ' INTO txt_tooltip.

ENDIF.

*here calling the method to create the textview ui element

ld_textview = cl_wd_text_view=>new_text_view(

id = id_textviewui

view = view ).

*here I am setting up the layout data property fof this dynamically created text view ui cl_wd_matrix_head_data=>new_matrix_head_data( element = ld_textview ).

*here i am adding the text view ui element to my transparent container

ld_container->add_child( ld_textview ).

*setting up the text for the text view ui element

ld_textview->set_text(

value = l_txt ).

*here again i just want tooltip to show up for the first text ui element...

IF sy-index = 1.

ld_textview->set_tooltip(

value = txt_tooltip ).

endif.

*now here i started to program for the tabstrip

*creating the id for the tab

CONCATENATE 'TAB_' loop_num INTO tab_id.

*creating the tab now

ld_tab1 = cl_wd_tab=>new_tab(

id = tab_id

view = view ).

*creating the caption for the tab...this is important to set or will get the runtime dump

CONCATENATE 'CAP_' loop_num INTO cap_id.

ld_tcap = cl_wd_caption=>new_caption(

id = cap_id

view = view

text = tab_id ).

*setting the header for it

ld_tab->set_header( ld_tcap ).

*now adding the tab to the tabstrip

ld_tabstrip->add_tab(

EXPORTING

index = sy-index

the_tab = ld_tab ).

*now inserting the view container ui into the tab

ld_tab->set_content( ld_vc ).

ENDDO.

ENDIF.

*******************************************************************************************************************************************

3)*now to embed the view inside these view containers what i did is created an action method for the tabstrip

so go to your main view layout....select the tabstrip we have there and look for the "events" properties...

I pick "onSelect" event and created a method name: EMBED_VIEW

one thing i want to mention that when you create this action method...make sure to check mark the option "Transfer UI Event Parameters" or the following coding will fail...

*************************************************************************************************************************************************************4) i put the following coding to insert the view dynamically...

data lo_tab type string.

data lo_old_tab type string.

data lo_id type string.

*you noticed all these parameters are coming from this action method signature

lo_tab = tab.

lo_old_tab = old_tab.

lo_id = id.

data: L_VIEW_CONTROLLER_API type ref to IF_WD_VIEW_CONTROLLER,

COMPONENT_NAME type STRING.

*this is my WDA component name

component_name = 'ZTEST_TAB'.

L_VIEW_CONTROLLER_API = WD_THIS->WD_GET_API( ).

data lo_msg type ref to cx_wdr_rt_exception.

data msg_s type string.

*these tab names we are generating in WDDOMODIFYVIEW using the "DO" looping

if lo_tab = 'TAB_01'.

try.

L_VIEW_CONTROLLER_API->do_dynamic_navigation(

source_window_name = 'ZTEST_TABLE' "{this is my window name }

source_vusage_name = 'MAIN_USAGE_0' "{this one is MAINmy main view-need to type your main view name plus this "_USAGE_0"}

source_plug_name = 'OUT_PLUG1' "{this plug name can be generated dynamically if we do not know how many tabs we have....since for each tab the name has to be unique}

target_view_name = 'VIEW2' "{the view i want to embed}

target_plug_name = 'DEFAULT' "{leave it as default}

target_embedding_position = 'MAIN/VIEW_C' ). "{this one shows the embeding position my main view, which is called "MAIN and the view container ui"}

catch cx_wd_runtime_repository .

msg_s = lo_msg->IF_MESSAGE~GET_TEXT( ) .

endtry.

elseif lo_tab = 'TAB_02'.

try.

L_VIEW_CONTROLLER_API->do_dynamic_navigation(

source_window_name = 'ZTEST_TABLE'

source_vusage_name = 'MAIN_USAGE_0'

source_plug_name = 'OUT_PLUG2' "{unique for each view}

target_view_name = 'VIEW3'

target_plug_name = 'DEFAULT'

target_embedding_position = 'MAIN/VIEW_C').

catch cx_wd_runtime_repository .

msg_s = lo_msg->IF_MESSAGE~GET_TEXT( ) .

endtry.

endif.

*************************************************************************************************************************************************************

this all is a test program....there might be ways to improve it...it is just to give people a starting point.....

hope this will help....

Thanks...

AS...

Former Member
0 Kudos

hi ,

pls see my WIKI DYNAMIC LAYOUT MANIPULATION IN WD ABAP

http://wiki.sdn.sap.com/wiki/display/stage/dynamiclayoutmanipulationinWD+ABAP

it can help

regards,

amit