在Eclipse中突出显示包资源管理器中的类文件 [英] Highlighting a class file in the package explorer in Eclipse

查看:230
本文介绍了在Eclipse中突出显示包资源管理器中的类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了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;
        }
    }

提前感谢

推荐答案

您应该使用JDT API获取CompilationUnit:

You should use the JDT API to get a CompilationUnit:

ICompilationUnit cu = JavaCore.create(file);

然后将此CompilationUnit对象用于setSelection:

and then use this CompilationUnit object to setSelection:

ISelection selection = new StructuredSelection(cu);

顺便说一句,你为什么要自己开发这个功能? Ctrl + Sihft + T,您可以打开一个对话框来搜索类,并在编辑器中打开它。软件包资源管理器具有链接到编辑器工具栏项目,可以在活动编辑器中自动选择类。

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.

这篇关于在Eclipse中突出显示包资源管理器中的类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆