【发布时间】:2013-12-10 21:42:52
【问题描述】:
我有一个带有一些视图的 RCP 应用程序和一个为应用程序创建工具栏的 ActionBarAdvisor。工具栏的初始化如下:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor
...
protected void fillCoolBar(ICoolBarManager coolBar)
{
// Create new Toolbar
IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
// Adds toolbar to perspective
coolBar.add(toolbar);
...
ActionContributionItem compareFilesCI = new ActionContributionItem(compareFiles);
compareFilesCI.setMode(ActionContributionItem.MODE_FORCE_TEXT);
toolbar.add(compareFilesCI);
...
}
此工具栏项的目的是切换 JFace 表的值的颜色。用户可以通过按下按钮来打开或关闭表格中的颜色。 但是告诉表格应该启用/禁用着色的最佳方法是什么?目前我已经这样做了:
public class ActionCompareFiles extends Action implements ISelectionListener, ActionFactory.IWorkbenchAction
{
...
public void run()
{
// Check if the button is enabled. When it is enabled, comparison should be performed
try
{
// Get the label values view
final ViewFileValues labelViewer = (ViewFileValues) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences()[3].getView(true);
// Refresh the view
labelViewer.setColoringValues(this.isChecked());
}
catch (Exception e)
{
System.out.println("Exception when searching the values view");
}
}
...
按下按钮时,我会看到包含表格的视图。在这个视图类中有一个方法“SetColoringValues”,它通知表格列的标签提供者按钮被按下并更新表格。 这可行,但我不确定它是否是最好的解决方案......
我的第一个想法是简单地向按钮添加侦听器。按下按钮后,将通知听众。但这似乎不起作用,因为我没有得到 ActionBarAdvisor 对象,是 工具栏已创建。作为工作台窗口一部分的工具栏似乎没有 getter 方法。
这个问题的最佳解决方案是什么?
【问题讨论】:
标签: java eclipse eclipse-rcp rcp