[Eclipse] GEF Getting Started series (iv, Other features)

Source: Internet
Author: User

Recently because of the heavy laboratory task, has not continued to study GEF, has already mastered some things seem to have lost a lot, really helpless ah, it seems to be often touched. Friends who have just contacted GEF have the impression that there are too many concepts in GEF to compare around, some of the functions that can be directly implemented must be turned into another class, and many of the names are very similar, and without knowing their role, it feels like mess. I think the situation is determined by the complexity of the graphical user interface (GUI), which is seemingly simple and actually contains quite a lot of logic, especially the way the graphical editing of GEF is handled, which can be said to be the most complex. Every class in GEF should say that there is a reason for it, and we need to understand the author's intentions as much as possible, which requires a lot of examples of documentation and reconciliation.

Viewing documents and code in Eclipse is quite handy, such as our use of a class is not clear, usually first look for its comments (select the class or method to press F2), and then you can see where it is used elsewhere (select a class or method to press Ctrl+shift+g), and find its source code (CTRL + Left mouse button or F3), in addition Ctrl+shift+t can find a class by name, and so on. To learn GEF is to see the code, of course, still need time and patience.

OK, less gossip, let's get to the point. This post will continue with an article on how to implement Directedit, property pages, and outline views, which are essential features that a full GEF application needs to provide.

Implement Directedit

The so-called Directedit (also known as In-place-edit) allows users to modify content directly, such as selecting a file in Windows Explorer, and then pressing F2 to begin modifying the file name. The principle of implementing directedit is straightforward: When a user makes a change request (Req_direct_edit), it overwrites a text box (or a Drop-down box, where we only discuss the text) as an editor, and when the editor is finished, You can then apply the contents of the editor to the model. (For similar functionality, refer to: Add Edit function to table cells)

Figure 1 Direct Edit

In GEF, this pop-up editor is managed by the Directeditmanager class, in our Nodepart class, by overwriting the Performrequest () method in response to the user's Directedit request, in this The method typically constructs an instance of the Directeditmanager class (the Nodedirecteditmanager in the example) and passes in the necessary arguments, including the Editpart (which is itself, this) that accepts the request, and the editor type (using Textcelleditor) and the Celleditorlocator (nodecelleditorlocator) used to locate the editor, and then display the editor with the Show () method, and the contents shown in the editor are already in the constructor method. A simple look at the Nodecelleditorlocator class, its key approach in relocate (), when the contents of the editor change, this method is called so that the editor is always in the correct coordinate position. Directeditmanager has an important initcelleditor () method, whose primary role is to set the editor's initial value. In our example, the initial value is set to the name attribute value of the corresponding model (Node) of the edited Nodepart, and the ability to set the editor font and select all text (SelectAll) is also completed, as it is more in line with the general usage.

In the Nodepart also add a role for Direct_edit_role Editpolicy, it should inherit from Directeditpolicy, there are two ways to implement: Getdirecteditcommand () and Showcurrenteditvalue (), although not yet encountered, but the role of the former you should not be unfamiliar--at the end of the edit to generate a command object to modify the results of the model, the latter is to update the display in figure, Although our editor covers the text in figure, it does not seem to require the display of the tube figure, but the consistency of the two texts at all times in the editor does not appear to be "unable to cover" situations, such as when the text in the editor is shorter.

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.