贴一段eclipse插件开发中获取当前package explorer中选中的目录代码

IStructuredSelection structured = (IStructuredSelection)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");

Object selected = structured.getFirstElement();

if(selected instanceof File){

    File file = (File)selected;

    java.io.File f = file.getLocation().toFile();

    FormatXulSourcePage(f);

}else{

    if(selected instanceof PackageFragmentRoot){

        PackageFragmentRoot pfr = (PackageFragmentRoot)selected;

        java.io.File f = pfr.getResource().getLocation().toFile();

    }else if(selected instanceof PackageFragment){

        PackageFragment pf = (PackageFragment)selected;

        java.io.File f = pf.getResource().getLocation().toFile();

    }else if(selected instanceof Folder){

        Folder folder = (Folder)selected;

        java.io.File f = folder.getLocation().toFile();

    }

}

你可能感兴趣的:(贴一段eclipse插件开发中获取当前package explorer中选中的目录代码)