设为首页 收藏本站
查看: 868|回复: 0

[经验分享] SAP Control framework–实例

[复制链接]

尚未签到

发表于 2015-9-20 13:11:45 | 显示全部楼层 |阅读模式
  引用:翱翔云天
  274 views

  1.1 例子
  好了,说了这么多,我们举一个小例子,来使用这三个类,关于dragdrop类,我们会在后面介绍其具体的使用方法。
  背景:
  我们得到了一个图片,然后把它显示在picture control中。添加一个toolbar,通过toolbar中的按钮控制图片的大小以及显示方式。通过使用context menu,可以实现一些控制,比如删除图片,打开新图片等等。
  
  8.4.1 定义数据
  *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 创建屏幕
DSC0000.jpg
DSC0001.jpg
  定义context menu form
DSC0002.jpg
  定义context menu
DSC0003.jpg
  处理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.
  定义pic类
  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 'ENJOY',
  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,
  url(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 定义toolbar类
  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 定义event处理类
  *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_vh type c.
  * Catch cast exception
  data: cast type c.
  data: pict type ref to cl_gui_picture.
  endclass.
  8.4.6 Implementation 各个类
  对于pic类,方法init_screen初始化屏幕
  method init_screen.
  call method set_pf_status.
  * Create custom container for picture container
  create object container_pic
  exporting
  container_name = 'CONTAINER_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 处理
  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
  所有代码
  1.2 测试结果
DSC0004.jpg
DSC0005.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-116266-1-1.html 上篇帖子: 设置SAP后台的显示和修改 下篇帖子: SAP BDC批量导入数据(转)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表