1.在ActionBarAdvisor类中定义工具栏位置
java 代码
- public final class NetStarActionBarAdvisor extends ActionBarAdvisor ...{
-
-
- private static final String TOOLBAR_SELL_TICKET = "tbSellTicket";
-
-
-
-
-
-
- @Override
- protected void fillCoolBar(final ICoolBarManager coolBar) ...{
- coolBar.add(new ToolBarContributionItem(createSellTicketToolBar(coolBar
- } .getStyle()), TOOLBAR_SELL_TICKET));
-
-
-
-
-
-
-
- private IToolBarManager createSellTicketToolBar(final int style) ...{
- final IToolBarManager toolBar = new ToolBarManager(style);
- toolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- return toolBar;
- }
- ...
- }
2.扩展Action,指定toolbarPath位置为"tbSellTicket/groupMarker1",其中groupMarker1是分组,tbSellTicket可以有多个组。
xml 代码
- <action
- accelerator="F2"
- class="com.cepiao.netstar.client.ticket.actions.TicketAction"
- definitionId="netstar.client.ticket.actions.SellTicket"
- icon="icons/saleticket.gif"
- id="com.cepiao.netstar.client.ticket.TicketAction"
- label="售票(&S)"
- menubarPath="sellTicket/groupMarker1"
- style="push"
- toolbarPath="tbSellTicket/groupMarker1"
- tooltip="售票、售留票、改票">
- action>
3.实现Action类,继承ActionDelegate.
java 代码
-
-
-
-
- package com.cepiao.netstar.client.ticket.actions;
-
- import org.eclipse.jface.action.IAction;
- import org.eclipse.ui.IWorkbenchPage;
- import org.eclipse.ui.PlatformUI;
- import org.eclipse.ui.WorkbenchException;
- import org.eclipse.ui.actions.ActionDelegate;
-
- import com.cepiao.netstar.client.core.ui.ExceptionHandler;
- import com.cepiao.netstar.client.core.ui.TicketViewConstants;
-
-
-
-
-
-
-
- public final class MyTicketAction extends ActionDelegate ...{
-
-
-
-
-
- @Override
- public void run(final IAction action) ...{
- final IWorkbenchPage page =
- PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage();
- if (page == null) ...{
- return;
- }
-
- try ...{
- page.showView(TicketViewConstants.TICKET_VIEW_ID);
- } catch (final WorkbenchException e) ...{
- ExceptionHandler.handle(e);
- }
- }
- }