[Eclipse] GEF Starter Series (11, one implementation of the tree)

Source: Internet
Author: User

GEF released the 3.1M7 version two days ago, but the use of it found no difference with M6, is it mainly for the eclipse version of the match? Hope that the 3.1 official version of the early release, should be a lot of new content. The previous post describes how to implement the table function, in the development process, another commonly used function is the tree, although SWT provides the standard tree control, but it is not intuitive and convenient to use it to complete the application such as organization chart. Although there is no direct support for the implementation of the tree in the current version of GEF (3.1M7), the draw2d provides examples of code that we can use (Org.eclipse.draw2d.examples.tree.TreeExample, the operating interface is shown below), it can save a lot of work.

Fig. 1 Treeexample in draw2d example

Remember, a few years ago, I used swing to do an org chart editing tool, at that time, the implementation is to allow the canvas to use xylayout, in the appropriate time to calculate and refresh the location of each tree node, the algorithm is the idea of a depth first search, the location of non-leaf nodes by the number and location of its child nodes. I think this should be a more intuitive way, but this time to see the implementation of the draw2d example is also very reasonable, never thought of before. In this example, the tree node graph is called Treebranch, which contains a pagenode (represented by a corner rectangle) and a transparent container contentspane (a layer, which is used to place child nodes). In general, Treebranch itself uses a layout manager named Normallayout to place the pagenode above the child nodes, while Contentspane uses a layout manager named Treelayout to calculate where each child node should be. So the whole tree we see is actually made up of many layers of subtrees, and the size of any graph corresponding to a non-leaf node is equal to the size of the area that the subtree of the root node occupies.

From this example we also see that the user can choose to use the horizontal or vertical organization tree (see Figure 2), you can compress the gaps between the nodes, each node can be horizontally or vertically arrange the child nodes, you can expand or receive the screwdriver node, etc., This provides a good foundation for us to implement a handy tree editor (the work of the View section is greatly simplified).

Fig. 2 Tree with vertical structure

Related Article

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.