[Eclipse] GEF Getting Started series (vi, adding menus and toolbars)

Source: Internet
Author: User

I have found that once you have a little experience of GEF, it will naturally attract you. Not only because it makes a good graphical interface, more importantly, the most complex and subtle issues in the UI are well considered and solved in the design of GEF, and when you understand these, you can completely transform these solutions to solve other areas of design problems. Last year Huang Lu, after the end of a GEF project, has not given up on its continuing research, and is now even using its spare time to develop a GEF-based swt/jface enhancement package, as evidenced by the charms of Eclipse and GEF. I believe that in the next two years, due to the maturity of RCP/GEF and other technologies, Java standalone applications will be developed, in the B/S mode is difficult to achieve the part of the field play an important role.

The theme of this article is to implement the menu functionality, because Eclipse's extensible design adds a few more considerations to the GEF application, so I'll start by introducing some of the concepts of the eclipse in the menu, and then how to add menus, toolbars, and context menus to GEF.

As we know, eclipse itself is just a platform (Platform) that users cannot work directly with, and its role is to provide a basic environment for those parts that provide practical functionality, all of which construct interfaces and use resources in a way that is specified by the platform. In eclipse, these widgets are called plug-ins (Plugins), such as the Java Development Environment (JDT), ant support, CVS client and Help system, and so on, because the eclipse itself that we downloaded from eclipse.org already contains these common plug-ins, So no extra installation is required, just as Windows itself already contains tools like Notepad, drawing, and so on. If we need new features, we'll install them on the Eclipse platform by downloading the installation or online updates, such as the XML Editor, the properties file editor, Java EE Development Support, and so on, including the GEF development package. Plug-ins are typically installed in the plugins subdirectory of the Eclipse installation directory, or they can be installed in a different location using link mode.

One of the great things about the eclipse platform is that so many plug-ins can be perfectly integrated in the same environment, knowing that each plug-in may have complex elements such as editors, views, menus, toolbars, file associations, and so on, so that they can coexist peacefully is not an easy task. To this end, Eclipse offers a number of mechanisms to address the problems that arise. Due to space limitations, here are just a few of the menu and sidebar sections, and more on the plugin development Help documentation that eclipse has randomly provided.

In most cases, we say that developing an eclipse based application means developing an Eclipse plug-in (plugin), and each plug-in in eclipse has a file called Plugin.xml to define the various elements in the plug-in. For example, what are the editors for this plugin, which views and so on. Use menus and toolbars in the view please refer to the previous posts, this article only describes the editor, because most of the GEF applications are based on the editor.

Figure 1 Several components of the Eclipse platform

First of all, introduce the concept of the Retarget action, which is a certain semantic but no actual function of the action, its only function is in the main menu bar or the main toolbar occupies an item position, the editor can map the action of the actual function to a retarget Action, when the editor is activated, the Retarget action on the main Menu/toolbar will have that action function. For example, Eclipse provides iworkbenchactionconstants.copy this retarget Action, and its text and icons are predefined, assuming that our editor needs a "copy node to clipboard" feature because "Replication node "and" copy "two words have very similar semantics, so you can create a new copynodeaction (extends action) with actual functionality, and then call the following code to implement the mapping in the appropriate place:

IActionBars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyNodeAction)

When the editor is activated, Eclipse examines the mapping, makes the copy available, and executes the code defined in Copynodeaction, the Run () method, when the user presses it. The purpose of Eclipse's introduction of the Retarget action is to minimize the cost of rebuilding the main Menu/toolbar, and to facilitate consistency in user usage. In a GEF application, because more than one view is likely to exist (for example, edit view and outline view, even if there is only one view at a time, consider extending to more than one), each view should be able to perform similar operations. For example, in the outline view of the tree structure, you should also delete the selected node as you would edit the view, so the general action should be established in a way that maps to the Retarget action.

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.