Simple tree learning notes-darg and drop event

Source: Internet
Author: User

I haven't updated this blog for a long time. I have nothing to do this weekend, so I just need to update it. It's the beginning! Today, I want to learn how to implement the drag and drop event on the simple tree.

First, consider that to implement the drag and drop event, there must be an entity to carry the drag, and there will also be an entity to carry the drop, the two entities can be the same. In this instance, the simple tree is selected as the drag entity, Textedit is the object of drop. That is, drag a node from the simple tree to textedit. Therefore, we first implement the drag event on the simple tree to implement the drop event on the textedit.

It is difficult to implement a drag event on a simple tree and a drop event on textedit, but it is easier to understand the principle as long as the idea is clarified. So first, let's look at some implementation principles.

In the reository browser, select class/interface, and then select cl_gui_simple_tree. Expand the events folder and we can see the on_drag time. Then we can see that the on_drag time has node_key and drag_drop_object. the node_key parameter is mainly used to indicate which node the drag has. Therefore, the on_drag event must be implemented in the program. After the drag event is completed, it is followed by the drop event. The drop event should be implemented in the textedit entity. Therefore, you can view an on_drop event on textedit in the same way. This event has four parameters: Index, line, POs, and dragdrop_object.

After figuring out the two events, let's look at how to implement these two events. Let's look at the code without talking nonsense.

 

// Define the event
Class dragdrop_receiver definition.
Public section.
Methods:
Darg for event on_drag of cl_gui_simple_tree
Importing node_key drag_drop_object,
Drop for event on_drop of cl_gui_textedit
Importing index line POS dragdrop_object.
Endclass. "dragdrop_receiver Definition

// Event implementation

 

Class dragdrop_receiver implementation.
Method darg.
Data drag_object type ref to lcl_drag_object.
Read Table nodes with key node_key = node_key into node.
Create object drag_object.
Drag_object-> text = node-text.
Drag_drop_object-> Object = drag_object.
Endmethod. "darg
Method drop.
Data textline (256 ).
Data text_table like standard table of textline.
Data drag_object type ref to lcl_drag_object.
Catch system-exceptions move_cast_error = 1.
Drag_object? = Dragdrop_object-> object.
Endcatch.
If sy-subrc = 1.
Call method dragdrop_object-> abort.
Exit.
Endif.
Call method edit-> get_text_as_stream
Importing
TEXT = text_table.
Call method cl_gui_cfw => flush.
Textline = drag_object-> text.
Insert textline into text_table Index 1.
Call method edit-> set_text_as_stream
Exporting
TEXT = text_table
Exceptions
Error_dp = 1
Error_dp_create = 2.
Endmethod. "drop

After the drag and drop event is implemented, the next step is to implement the example tree and textedit In the PBo module and register the event accordingly. It is worth noting that when adding notes to the simple tree, you should specify which notes can be drag and which cannot be. The specific method is:

 

Data handle_tree type I.

Clear node.
Node-node_key = 'first _ child '.
Node-TEXT = 'Chinese '.
Node-dragdropid = ''.
Node-relatkey = 'root '.
Node-relatship = cl_gui_simple_tree => relat_last_child.
Node-dragdropid = handle_tree.
Append node to nodes.

Next, we need to define two

Cl_dragdrop object and then create the instance of this object. One instance is used to pass the previously defined handle_tree through

The get_handle method is appended.

Set_dragdrop method appended.

Let's write it here. It's better to directly read the code without knowing how to express your speech.

/Files/flysky927/ztest_dragdrop.txt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.