2

プロジェクトのポップアップメニューにオプションを追加するためのEclipse用プラグインを開発しました。このオプションはクラスを名前で検索し、パッケージ エクスプローラーでクラスを強調表示します。ハイライト部分に問題があります。フォルダー内のクラスを検索したので、クラスパスはありますが、強調表示する方法がわかりません。

これを試しましたが、結果が得られませんでした:

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;
        }
    }

前もって感謝します

4

1 に答える 1

2

CompilationUnit を取得するには、JDT API を使用する必要があります。

ICompilationUnit cu = JavaCore.create(file);

次に、この CompilationUnit オブジェクトを使用して setSelection を実行します。

ISelection selection = new StructuredSelection(cu);

ところで、なぜこの機能を自分で開発したいのですか? Ctrl+Sihft+T で、ダイアログを開いてクラスを検索し、エディターで開くことができます。また、パッケージ エクスプローラーには、アクティブなエディターでクラスを自動選択できる "エディターとのリンク" ツールバー項目があります。

于 2013-02-05T03:02:43.800 に答える