原文鏈接:https://blog.csdn.net/vking_wang/article/details/8716073
添加菜單欄
1)首先在WorkbenchWindowAdvisor中顯示菜單欄
@Override public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize(new Point(400, 300)); configurer.setShowCoolBar(false); configurer.setShowMenuBar(true);//顯示菜單欄 configurer.setShowStatusLine(true); configurer.setTitle("Hello RCP"); }
2)在ActionBarAdvisor中添加動作
public class ApplicationActionBarAdvisor extends ActionBarAdvisor { private IWorkbenchAction exitAction; private IWorkbenchAction aboutAction; public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } @Override protected void makeActions(IWorkbenchWindow window) { exitAction = ActionFactory.QUIT.create(window); aboutAction = ActionFactory.ABOUT.create(window); register(exitAction); register(aboutAction); } @Override protected void fillMenuBar(IMenuManager menuBar) { MenuManager fileMenuMgr = new MenuManager("&File", "File"); fileMenuMgr.add(exitAction); MenuManager helpMenuMgr = new MenuManager("&Help", "Help"); helpMenuMgr.add(aboutAction); menuBar.add(fileMenuMgr); menuBar.add(helpMenuMgr); } }
現在的界面如下:
添加工具欄
1)在WorkbenchWindowAdvisor中顯示工具欄
configurer.setShowCoolBar(true);
2)在ActionBarAdvisor中添加動作
@Override protected void fillCoolBar(ICoolBarManager icoolbarmanager){ IToolBarManager toolbar = new ToolBarManager(icoolbarmanager.getStyle()); icoolbarmanager.add(toolbar); toolbar.add(aboutAction); toolbar.add(exitAction); }
現在的界面如下:
添加狀態欄
1)在WorkbenchWindowAdvisor中顯示狀態欄
configurer.setShowStatusLine(true);
2)在WorkbenchWindowAdvisor中添加動作
@Override public void postWindowOpen(){ IStatusLineManager statusLine = getWindowConfigurer(). getActionBarConfigurer(). getStatusLineManager(); statusLine.setMessage("-login : "+new Date().toLocaleString()); }
現在的界面如下: