Add a multi-level menu on the eclipse Platform

Source: Internet
Author: User

Adding a menu on the eclipse workbench is simple. You can use the org. Eclipse. UI. actionsets extension point of the plug-in to add menus, menu items, and toolbar items to the workbench menu and toolbar. At the same time, the eclipse workbench plug-in development environment also implements Org. eclipse. UI. the actionsets extension provides a hello World template to add a "sample operation" menu to the menu of the eclipse workbench and add a "sample operation" button to the toolbar. However, this template provides only one menu item. How do I implement a multilevel structure in the menu items already available in the eclipse workbench, as shown in?

In fact, it is not difficult. The key to the problem is to correctly set menu and toolbar attributes. Below, we implement multi-level menu items.

Create a plug-in project in the eclipse workbench and use the hello World template. The project name can be set to "menuplugin". In addition, we do not generateCodeModify the configuration file plugin. xml.

Modify the extension of the template to org. Eclipse. UI. actionsets into the following structure:

Now in the same operation set, there is a directory item with the ID of menu, the label is "directory", and there is a directory item with the ID of submenu, the label is "subdirectory ", used as a subdirectory of the "directory" directory. Under the "directory" and "sub-directory" directory items, we have defined several seperator. Under the directory item named "directory", we have defined two seperator, the names are "slot1" and "slot2" respectively. Under the directory item named "sub-directory", a seperator is defined and named "slot3 ". Here, we define four actions: "sample operation 1", "sample operation 2", "sample operation 3", and "sample operation 4 ", they are used under the "directory" and "sub-directory" respectively. The actions "sample operation 1" and "sample operation 2" are directly placed under the "directory" directory. Therefore, for their menubarpath, we only need to set it to menu/slot1 like the original settings of the template. Let's take a look at how the "subdirectory" directory item becomes the sub-directory item of the "directory" directory item:

Similarly, we set the path attribute value of the "subdirectory" directory item to menu/slot1. Menu is the ID of the Directory item "directory", and slot1 is a seperator contained in it. In this way, the "subdirectory" directory item is placed under the slot1 seperator of the "directory" directory item. Of course, if you do not put any action in the "subdirectory" directory item, this directory item will not be displayed. Next we will add two actions in the "subdirectory" directory, "sample operation 3" and "sample operation 4 ".

As shown in, the menubarpath attribute of the action "sample operation 3" is set to menu/submenu/slot3. Menu is the ID of the Directory item "directory", submenu is the ID of the Directory item "subdirectory", and slot3 is a seperator contained under the directory item "subdirectory.
In this way, "sample operation 3" is placed in the slot3 seperator under the "subdirectory" sub-directory under the "directory" directory item.

The following describes the content of the plugin. xml file. You may need to note the content marked with "<.
<? XML version = "1.0" encoding = "UTF-8"?>
<? Eclipse version = "3.0"?>
<Plugin>
<Extension
Point = "org. Eclipse. UI. actionsets">
<Actionset
Label = "sample operation set"
Visible = "true"
Id = "menuplugin. actionset">

<Menu
Id = "menu" <---
Label = "directory"
>
<Separator
Name = "slot1"> <---
</Separator>
<Separator
Name = "slot2"> <---
</Separator>
</Menu>
<Action
Class = "menuplugin. Actions. sampleaction"
Icon = "icons/sample.gif"
Id = "acion1"
Label = "sample operation 1"
Menubarpath = "menu/slot1" <---
Tooltip = "Hello, eclipse world">
</Action>
<Action
Class = "menuplugin. Actions. sampleaction"
Icon = "icons/sample.gif"
Id = "acion2"
Label = "sample operation 2"
Menubarpath = "menu/slot1" <---
Tooltip = "Hello, eclipse world">
</Action>

<Menu
Id = "submenu"
Label = "subdirectory"
Path = "menu/slot2"> <---
<Separator
Name = "slot3">
</Separator>
</Menu>
<Action
Class = "menuplugin. Actions. sampleaction"
Icon = "icons/sample.gif"
Id = "action3"
Label = "sample operation 3"
Menubarpath = "menu/submenu/slot3" <---
Tooltip = "Hello, eclipse world">
</Action>
<Action
Class = "menuplugin. Actions. sampleaction"
Icon = "icons/sample.gif"
Id = "acion4"
Label = "sample operation 4"
Menubarpath = "menu/submenu/slot3" <---
Tooltip = "Hello, eclipse world">
</Action>

</Actionset>
</Extension>
</Plugin>

You can use a similar method to set the toolbar path. For more information about menu and toolbar paths, you can view the menu and toolbar path section in the "advanced workbench concepts" section in the "Platform Plug-in developer Guide" in eclipse help.

 

<? XML version = "1.0" encoding = "UTF-8" ?>
<? Eclipse version = "3.2" ?>
< Plugin >

< Extension Point = "Org. Eclipse. UI. actionsets" >
< Actionset Label = "Sample action set" Visible = "True" ID = "Cn.net. comsys. Portlet. mdd. actionset" >
< Menu Label = "Kangsai MDD" ID = "Comsysmddmenu" >
< Separator Name = "Dir1" >   </ Separator >
</ Menu >
< Menu Label = "Portal development" ID = "Portlet_menu_01" Path = "Comsysmddmenu/dir1" >
< Separator Name = "Portaldev"   >   </ Separator >
</ Menu >
< Action
Label = "Added Portlet support"
Icon = "Icons/sample.gif"
Class = "Cn.net. comsys. Portlet. mdd. Actions. sampleaction"
Tooltip = "Hello, eclipse world"
Menubarpath = "Comsysmddmenu/portlet_menu_01/portaldev"
Toolbarpath = "Samplegroup"
ID = "Cn.net. comsys. Portlet. mdd. Actions. sampleaction" >
</ Action >
</ Actionset >
</ Extension >

</Plugin>

 

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.