Gef faq 3: Self-connection

Source: Internet
Author: User

In the class diagram, we can see that some objects have their own references. These references are usually used to express the tree structure, that is, both parent and child nodes are the same class objects. Using GEF to draw such a connection line is generally achieved through a turning point (bendpoint), if your GEF applicationProgramYou cannot use bendpoint. Follow the steps described in the previous article to add support for bendpoint.

In the past, our gefpractice application did not allow the start and end of a connection line to be in the same graph, because this would cause the connection line to shrink into a point and hide it below the graph, the user does not know its existence. At that time, we made the following judgment in the canexecute () method of the createconnectioncommand class:

Public   Boolean Canexecute (){
If (Source. Equals (target ))
Return   False ;

}

Therefore, we need to delete these two sentences first. Then, the execute () method is used to slightly process the connection itself. The processing method is to add three bendpoints to the connection line at the appropriate position, you can also modify the number and position of bendpoint Based on the desired connection line shape.

Public   Void Execute (){
Connection =   New Connection (source, target );
If (Source = Target ){
// The start and end points of our connection are both at the center of the rectangle,
// So the two relative dimensions are equal.
Connectionbendpoint =   New Connectionbendpoint ();
CBP. setrelativedimensions ( New Dimension ( 0 , - 60 ), New Dimension ( 0 , - 60 ));
Connection. addbendpoint ( 0 , CBP );
Connectionbendpoint cbp2 =   New Connectionbendpoint ();
Cbp2.setrelativedimensions ( New Dimension ( 100 , - 60 ), New Dimension ( 100 , - 60 ));
Connection. addbendpoint ( 1 , Cbp2 );
Connectionbendpoint cbp3 =   New Connectionbendpoint ();
Cbp3.setrelativedimensions ( New Dimension ( 100 , 0 ), New Dimension ( 100 , 0 ));
Connection. addbendpoint ( 2 , Cbp3 );
}
}

Now, you only need to select the Connection Tool and click two consecutive points on a node to create your own connection, as shown in.


Self-connection

Click here to download the project, which is modified from gefpractice-BP in gef faq 2. the target file extension is. gefpracticesc.

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.