First you have to add the menu contribution to your plugin.xml
. I wanted to add an extra menu item to the project explorer so I used"popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions"
as locationURI. Next you only have to specify a class that will create the menu item and specify an id.
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<dynamic
class="com.sigasi.MydynamicMenu"
id="com.sigasi.myDynamicMenu">
</dynamic>
</menuContribution>
</extension>
Next you have to create the Java class that extends org.eclipse.jface.action.ContributionItem
(You can use autocomplete for this).
The method that you have to override for a dynamic menu is fill(Menu menu, int index)
.
In this method you have to create the new (dynamic) MenuItem. You can also simply return if (e.g. based on the selection) you do not want to show a menu item. In the example code below I simply display the current date in the dynamic menu item.
Do not forget to add a addSelectionListener
to the MenuItem, to start some action when the menu is selected.
That's it.
The complete java source:
package com.sigasi;
import java.util.Date;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
public class MyDynamicMenu extends ContributionItem {
public MyDynamicMenu() {
}
public MyDynamicMenu(String id) {
super(id);
}
@Override
public void fill(Menu menu, int index) {
MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
menuItem.setText("HiBuild");
Menu submenu = new Menu(menu.getShell(),SWT.DROP_DOWN);
menuItem.setMenu(submenu);
MenuItem menuItem1 = new MenuItem(submenu,SWT.NONE);
menuItem1.setText("HiBuild 1");
MenuItem menuItem2 = new MenuItem(submenu, SWT.NONE);
menuItem2.setText("HiBuild 2");
menuItem1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//what to do when menu is subsequently selected.
System.err.println("Dynamic menu selected 1");
}
});
//create the menu item
MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
menuItem.setText("My menu item (" + new Date() + ")");
menuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//what to do when menu is subsequently selected.
System.err.println("Dynamic menu selected");
}
});
}
}
相关推荐
在这个"DynamicMenu.rar"压缩包中,我们有一个使用C++编程语言在Visual Studio 2005环境下开发的简单动态菜单示例。这个示例特别适用于Windows XP Service Pack 3操作系统。 在Windows应用程序开发中,特别是使用...
"Mvc.DynamicMenu"项目是针对MVC 6框架的一个演示示例,展示了如何从数据库中动态生成导航菜单。在本文中,我们将深入探讨这个主题,了解MVC 6、动态菜单的概念以及如何实现它们。 **MVC 6框架** MVC(Model-View-...
在Eclipse JEE环境下,创建一个Maven项目并将其转换为Dynamic Web Project是开发Java Web应用程序的常见步骤。Maven是一种强大的项目管理工具,而Dynamic Web Project则是Eclipse中的一个特殊项目类型,专用于Web...
Dynamic ListItems介绍: 动态给列表(ListView)增加新的行(ListItem)。 测试环境: Eclipse 4.2, Android 3.0。 注意:测试环境并不代表适用环境。
近似动态规划方法,百度apollo2.0系统里planning模块...(Optimal Trajectory Generation for Dynamic Street Scenarios in a Frene´t Frame Moritz Werling, Julius Ziegler, So¨ren Kammel, and Sebastian Thrun)
Dynamic loading class in the java virtual machine
### Eclipse Web Project转Dynamic Project详解 #### 一、引言 在进行软件开发的过程中,我们经常需要使用到不同的IDE(集成开发环境),其中Eclipse是一款非常流行的开发工具,尤其是在Java开发领域。有时,我们...
Jenkins的Dynamic Parameter Plug-in是一款强大的插件,它允许用户在构建过程中动态地定义和配置构建参数。这个插件增加了构建的灵活性,可以根据不同的条件或输入来决定构建时的参数,提高了持续集成/持续部署(CI/...
Spring Dynamic Modules in Action is a comprehensive tutorial that presents OSGi concepts and maps them to the familiar ideas of the Spring framework. In it, you'll learn to effectively use Spring DM. ...
本文档记录了本人用eclipse搭建maven dynamic web3.0的详细过程,包含了搭建maven项目,把maven项目转换为web项目,Dynamic web Module 2.3转换为3.0等内容
【Eclipse Tomcat Dynamic Web Project】是一个用于开发和部署Java Web应用程序的工作流程,它整合了Eclipse IDE的强大功能和Apache Tomcat服务器的便捷性。在Eclipse中创建一个Dynamic Web Project,开发者可以轻松...
"Dynamic Parameter plug-in"是 Jenkins 插件家族中的一个重要成员,它为构建过程提供了更灵活的参数化构建功能。由于某种原因,这个插件在官方仓库可能无法直接搜索到,但它的价值在于能够帮助开发者自定义构建过程...
动态参数插件(Dynamic Parameter Plug-in)是Jenkins持续集成工具中的一个重要扩展,它为构建过程提供了更加灵活的参数化选项。在 Jenkins 中,参数化构建允许用户在触发构建时输入特定值,这些值可以影响构建的过程...
然而,有时在新的或定制的Eclipse环境中,可能找不到“Dynamic Web Project”模板,这使得创建Web项目变得困难。本教程将指导你如何在Eclipse中添加这个功能。 **一、检查Eclipse版本** 首先,你需要确定你正在...
在Eclipse这个强大的Java集成开发环境中,我们常常会遇到两种类型的项目:Eclipse下的Tomcat Project和Web Dynamic Project。这两种项目类型虽然都是用于开发Web应用,但它们在用途、结构和配置上存在一定的差异。 ...
for an ultimate control over dynamic menu items added from within fast explorer you can define your own look & feel using the custom-drawing feature. fast explorer is a very simple way to make your ...
### Eclipse in Action: A Comprehensive Guide for Web Developers #### Chapter Overview and Context The book titled "Eclipse in Action" provides a detailed guide for web developers on how to ...
深度学习 Dynamic Unary Convolution in Transformers
Class loaders are a powerful mechanism for dynamically loading software components on the Java platform. They ...maintain type safety in the presence of user-defined dynamic class loading.