浏览器示例中的 BrowserAdvisor 提供的主要定制是指定工作台窗口的操作栏内容:
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();
}
};
有关可重定目标的操作以及如何定义并实现它们的完整讨论,请参阅可重定目标的操作。