首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

Eclipse RCP平添菜单

2012-07-20 
Eclipse RCP添加菜单一、单级菜单1.ApplicationWorkbenchWindowAdvisor.java添加configurer.setShowMenuBar

Eclipse RCP添加菜单

一、单级菜单

1.ApplicationWorkbenchWindowAdvisor.java添加configurer.setShowMenuBar(true);

?

public void preWindowOpen() {        IWorkbenchWindowConfigurer configurer = getWindowConfigurer();        configurer.setInitialSize(new Point(400, 300));        configurer.setShowMenuBar(true);        configurer.setShowCoolBar(false);        configurer.setShowStatusLine(false);        configurer.setTitle("Hello RCP"); //$NON-NLS-1$    }
?

?

2.新建Action

?

package com.dianbo.first.actions;import org.eclipse.jface.action.Action;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.internal.IWorkbenchGraphicConstants;import org.eclipse.ui.internal.WorkbenchImages;@SuppressWarnings("restriction")public class MyFirstMenuAction extends Action {private IWorkbenchWindow window;public MyFirstMenuAction(IWorkbenchWindow window) {this.window = window;this.setText("&导航@Ctrl+Alt+N");setToolTipText("open new Action!");ImageDescriptor imageDes = WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_EXPORT_WIZ);this.setImageDescriptor(imageDes);}public void run(){MessageDialog.openInformation(window.getShell(), "Memo", "Mr.Taxi By ????");}}

?3.ApplicationActionBarAdvisor.java

?

private MyFirstMenuAction newOpenAction;public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {super(configurer);}protected void makeActions(IWorkbenchWindow window) {newOpenAction = new MyFirstMenuAction(window);}protected void fillMenuBar(IMenuManager menuBar) {MenuManager firstMenuManager = new MenuManager("&HiFisrt",IWorkbenchActionConstants.M_WINDOW);firstMenuManager.add(newOpenAction);menuBar.add(firstMenuManager);;}
?


Eclipse RCP平添菜单

?
Eclipse RCP平添菜单

二、多级菜单

ApplicationActionBarAdvisor.java

protected void fillMenuBar(IMenuManager menuBar) {MenuManager firstMenuManager = new MenuManager("&Fisrt",IWorkbenchActionConstants.M_WINDOW);MenuManager secondMenuManager = new MenuManager("&Second",IWorkbenchActionConstants.M_WINDOW);secondMenuManager.add(newOpenAction);firstMenuManager.add(secondMenuManager);menuBar.add(firstMenuManager);;}
?


Eclipse RCP平添菜单

?

热点排行