Eclipse rcp RCP-正确的寄存器侦听器不在视图中
我尝试从单独的插件(该类不是视图,只是简单的类)将我的类注册为Eclipse rcp RCP-正确的寄存器侦听器不在视图中,eclipse-rcp,listener,Eclipse Rcp,Listener,我尝试从单独的插件(该类不是视图,只是简单的类)将我的类注册为PostSelectionListener,我使用以下方法: Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService(). addPostSelectionListener(VIEWS_VISUALIZATION_TYP_ID, this); 它工作正常,但我有一个警告: - Discouraged access: The method g
PostSelectionListener
,我使用以下方法:
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService().
addPostSelectionListener(VIEWS_VISUALIZATION_TYP_ID, this);
它工作正常,但我有一个警告:
- Discouraged access: The method getActiveWorkbenchWindow()
from the type Workbench is not accessible due to restriction on required library F:
\elipseSource\plugins\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
- Discouraged access: The method getInstance()
from the type Workbench is not accessible due to restriction on required library F:\elipseSource\plugins
\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
- Discouraged access: The type Workbench is not accessible
due to restriction on required library F:\elipseSource\plugins
\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
如何以正确的方式注册侦听器?检查这是否是
MANFEST.MF
生成问题(请参阅)
打开基本项目的MANIFEST.MF
,查看运行时选项卡。要在其他插件中访问的包应列为导出包 尝试重新计算导出包的正确列表 如果这不起作用,如中所述,您仍然可以选择:
- Windows->首选项->Java->编译器->错误/警告
- (或:项目)属性->Java编译器->错误/警告
要完全解决此问题,请分析项目并定位受限类的使用,并采取必要的操作(删除这些引用或访问规则)
对于外部jar(不是您的情况),请执行以下操作: 如果我将Jar文件添加为外部Jar,并将其上移到JRE系统库之前(按导出顺序),则不会出现此错误
实际上,OP通过
平台UI
PlatformUI.getWorkbench()
而不是Workbench.getInstance()
您可以在课程中看到这种方法:
/**
*返回具有给定id的ViewPart当前是否可见
*活动工作台窗口的一个页面。也会回来
*当包含此视图的页码簿最小化时为true。
*
*@param viewID要查询的视图的id
*@返回视图是否可见
*/
公共静态布尔值isViewVisible(字符串JavaDoc viewID){
//IWorkbenchPage[]pages=Workbench.getInstance().getActiveWorkbenchWindow().getPages();
IWorkbenchPage[]pages=平台UI.getWorkbench().getActiveWorkbenchWindow().getPages();
对于(int i=0;i
我找到了一个解决方案,而不是
Workbench.getInstance()
我应该使用:
PlatformUI.getWorkbench()
我是RCP初学者,所以这对我来说并不明显谢谢你的反馈+1.我已更新了我的答案以反映该解决方案。另请参阅
/**
* Returns wether the ViewPart with the given id is currently visble in
* one of the pages of the active Workbench window. Will also return
* true when the page-book containing this view is minimized.
*
* @param viewID The id of the view to be queried
* @return Wether the view is visible
*/
public static boolean isViewVisible(String JavaDoc viewID) {
// IWorkbenchPage[] pages = Workbench.getInstance().getActiveWorkbenchWindow().getPages();
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
for (int i = 0; i < pages.length; i++) {
IWorkbenchPart part = pages[i].findView(viewID);
if (part != null) {
return isPartVisible(part);
}
}
return false;
}