java的包资源管理器怎么弄出来,在Eclipse中突出显示包资源管理器中的类文件

I have developed a plugin for eclipse to add an option to the pop-up menu of the project. This option will search a class by name, then it should highlight the class in the package explorer. I have problem regarding the highlighting part. I search for the class in the folders, so i have the class path, but i don't know how to highlight it.

I tried this but I didn't get any results:

String path = "D:\\Programs\\eclipse\\runtime-EclipseApplication\\tessssst\\src\\testClass.java";

IPath iPath = new Path(path);

IFile file = project.getFile(iPath);

file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(iPath);

ISelection selection = new StructuredSelection(file);

IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();

PlatformUI.getWorkbench().getActiveWorkbenchWindow()

.getActivePage().resetPerspective();

for(IViewReference view:views){

if("org.eclipse.jdt.ui.PackageExplorer".equals(view.getId())){

IViewPart pExplorer = view.getView(true);

pExplorer.getViewSite().getSelectionProvider().setSelection(selection);

break;

}

}

Thanks in advance

解决方案

You should use the JDT API to get a CompilationUnit:

ICompilationUnit cu = JavaCore.create(file);

and then use this CompilationUnit object to setSelection:

ISelection selection = new StructuredSelection(cu);

And, by the way, why you want to develop this function yourself? Ctrl+Sihft+T, you can open an dialog to search class and open it in editor. And the package explorer has an "Link with editor" toolbar item that can auto select the class in the active editor.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值