ブラウザー・サンプルの BrowserAdvisor で提供される 1 次カスタマイズでは、ワークベンチ・ウィンドウのアクション・バー・コンテンツを指定します。
public void fillActionBars(IWorkbenchWindow window, IActionBarConfigurer configurer, int flags) { ... BrowserActionBuilder builder = new BrowserActionBuilder(window); getWorkbenchConfigurer().getWindowConfigurer(window).setData(BUILDER_KEY, builder); builder.fillActionBars(configurer, flags); }
これらのアクションが BrowserActionBuilder にどのように定義されているのかを詳しく見てみましょう。 特に、ブラウザー・ビューで処理されるアクションを確認します。
private void makeActions() { ... backAction = new RetargetAction("back", "&Back"); backAction.setToolTipText("Back"); backAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_BACK)); window.getPartService().addPartListener(backAction); forwardAction = new RetargetAction("forward", "&Forward"); forwardAction.setToolTipText("Forward"); forwardAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD)); window.getPartService().addPartListener(forwardAction); stopAction = new RetargetAction("stop", "Sto&p"); stopAction.setToolTipText("Stop"); window.getPartService().addPartListener(stopAction); refreshAction = new RetargetAction("refresh", "&Refresh"); refreshAction.setToolTipText("Refresh"); window.getPartService().addPartListener(refreshAction); ... }
アクションが再ターゲット可能なアクションとして定義されているため、個々のビューは、ハンドラー・アクションをインプリメントできます。 BrowserView は、ビューのコントロールを作成するときにハンドラー・アクションをウィンドウの再ターゲット可能なアクションに関連付けます。
private Browser createBrowser(Composite parent, final IActionBars actionBars) { ... actionBars.setGlobalActionHandler("back", backAction); actionBars.setGlobalActionHandler("forward", forwardAction); actionBars.setGlobalActionHandler("stop", stopAction); actionBars.setGlobalActionHandler("refresh", refreshAction); ... }
これらのアクションは、ビューが最初に作成されたときに作成されます。
private Action backAction = new Action("Back") { public void run() { browser.back(); } };
再ターゲット可能なアクションと再ターゲット可能なアクションの定義および実装方法についての詳細は、『再ターゲット可能なアクション』を参照してください。