Eclipse Plugin Development-menu

Source: Internet
Author: User

Org.eclipse.ui.menus

Locationuri

Menucontribution Locationuri = "[Scheme]:[id]? [Argument-list] "

1.menu or toolbar

2. Problem view

Popup:org.eclipse.ui.views.problemview?after=

Org.eclipse.ui.main.menu?after=

Org.eclipse.search.menu?dialoggroup

Org.eclipse.ui.popupMenus

Popup:org.eclipse.ui.views.problemview?after=additions

Popup:org.eclipse.ui.popup.any?after=additions

Steps

1.extension from menus

2.the menu location in where

Location URL

How does you find the Locationuri of menu contributions?

If you ALT+SHIFT+F1 are on the view, it would list the IDs of registered context menus

http://www.eclipse.org/pde/incubator/spy/

Tip:subclass Abstracthandler rather than implementing Ihandler.

Menu ' s handler

Import Org.eclipse.core.commands.AbstractHandler;

Iworkbenchwindow window = handlerutil.getactiveworkbenchwindowchecked (event);
Messagedialog.openinformation (
Window.getshell (),
"Demo",
"Hello, Eclipse World");

Operation Steps:

1. Add the org.eclipse.ui.commands extension to create a command

2. Add the Org.eclipse.ui.menus extension to create a menucontribution

3. Add the org.eclipse.ui.handlers extension, create a Handler,command ID to point to the command created in step 1, and write the implementation class for it

4. Specify an expression for the activation state for the handler created in step 3

Points:

1.

Q: When you create a command, do you need to specify the Catagory property for it?

A: Look at the situation. I personally feel that catagory is used to group menus. For example, a plug-in typically assigns its own menu to a unified catagory so that it can be put together when displayed or processed.

2.

Q: Do I need to specify the Name property for a new command?

The A:name property is required and of course you specify the:-) When the corresponding menu does not specify a label, the name is displayed in the menu.

3.

How is the Q:menu locationuri specified?

A: This is the first problem I've encountered because URIs need to be written in a description script, so how do I write a script? What are the rules for scripting? The answer is in the Eclipse Help document: Http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench _cmd_menus.htm

Example: Popup:org.eclipse.debug.ui.debugview?after=additions

This example URI can be regarded as 3 parts, the first part is "popup", which means that the style is right-click popup menu, the second part is "Org.eclipse.debug.ui.DebugView", meaning is displayed in which view of the pop-up menu, and the third part is "after= Additions ", meaning is where the pop-up menu is displayed (there are other menu items in the pop-up menu).

This is just one of many URIs, as well as adding items to the main menu and adding items to the toolbar, as described in the Help documentation link above.

Here, the menu should already be visible in the Debug window, but this raises the question: Whenever this menu is clicked, it is always reported: The chosen operation is not enabled. This is because the handler implementation class implements the Ihandler interface directly, and its Ishandled,isenabled method is automatically generated by Eclipse, all of which return false, unless necessary, Otherwise, the general situation should be inherited Org.eclipse.core.commands.AbstractHandler way to write handler implementation class, you can save a lot of trouble.

Note that: In the Plugin editor, clicking on the "Class" link in the handler's properties panel automatically creates the implementation class, which is not inherited Abstracthandler, but directly implements Ihandler, This is how I was brought into the ditch.

The problem with the error is solved, but it is not appropriate to find that the new menu can be displayed with the selected stack and without a stack selected, because if you want to copy stack information, at least one of them should be selected. So we should take steps to make this menu grayed out when no stack information is selected, which leads to another hard-to-understand framework: command core expression.

Command core expression is a scripting rule, and Eclipse defines a number of variables, attributes, which can be judged by core expression such as instanceof, Equals, and so on. This allows a Boolean value to be used to participate in the program's logic. For this problem, we only need to specify the Enabledwhen expression (core expression) for handler, so that handler is only activated when the stack information is selected.

The documentation for core expression in: Http://wiki.eclipse.org/Command_Core_Expressions also has a lot of information to refer to in the declaration document of the org.eclipse.ui.handlers extension.

In this example, we determine if there is a stack of information selected by counting the selection variable. For more information, please refer to the contents of the Plugin.xml file later in this article.

At this point, the process of adding a menu ends, seemingly simple, in fact involves a number of other applications, such as core expression, Locationuri and so on. Other problems are actually the same, constantly encountered problems, constantly tread on it, and constantly accumulate, slowly, a road will appear at the foot.

Eclipse Plugin Development-menu

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.