zoukankan      html  css  js  c++  java
  • 【Eclipse Plug-Ins 】刷新资源管理器功能

    最近在做向导开发,中间遇到了很多有意思的事情。今天把工作中遇到的知识点呢梳理一下,以备后用哈~

    项目大致背景:

    在Eclipse Runtime工作空间创建一个简单的Java项目。

     

     然后呢现在有一个向导Wizard,在向导页面中,我选择到了这个项目中的src目录。

    然后在向导中点击Finish按钮后,会执行Wizard类的performFinish类方法。很多处理的事情都放在这里做。

    那么假如向导页名字叫做AWizardPage.java,向导名字叫做BWizard.java

    即可通过一些操作获取到我们需要的内容。

    获取src目录:TheSimplestProject/src 
    
    String str = AWizardPage.getPackageFragmentRootText();     

    获取项目名字
    String temp =
    str.split("/");
    projectName = temp[0];
    
    获取Runtime项目的位置:D:/eclipse/runtime-workspace
    
    String projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); 

    当向导执行完毕后,需要刷新资源管理器的内容

    /**
     * 
     * @param refreshType    project:refresh the whole project; file:refresh the file; etc
     * @param resourcePath    the relative path of the resource which need to refresh, if want to refresh the project, the resourcePaht can be null.
     * @param projectName    the target peoject name
     */
    public static void refresh(String refreshType, String resourcePath, String projectName){
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(projectName);
        if (project.exists()) {
            try {
                // Refresh Project
                if ("project".equals(refreshType)) {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                }else if ("package".equals(refreshType) || "folder".equals(refreshType)) {
                    // Refresh the package or folder
                    IFolder folder = project.getFolder(resourcePath);
                    if (folder.exists()) {
                        folder.refreshLocal(IResource.DEPTH_INFINITE, null);
                    }
                }else if ("packagefile".equals(refreshType) || "folderfile".equals(refreshType) || "file".equals(refreshType)) {
                    IFile file = project.getFile(resourcePath);
                    if (file.exists()) {
                        file.refreshLocal(IResource.DEPTH_INFINITE, null);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    ---------------------------------------------------------------------------------
    参数实例:

      refreshType:“project”

      resourcePath:""

      projectName: "TheSimplestProject"

     
  • 相关阅读:
    seata 1.3.0 seata Global lock wait timeout
    Tika解析word文件
    我的第一款微信小程序:iteye附件下载器,希望大家好好爱惜
    读书《尸检报告》 [英]卡拉·瓦伦丁 / 中信出版集团2019-08
    读书《另一种选择》 [美] 谢丽尔·桑德伯格 / 中信出版集团2017-08
    读书《不朽的失眠》 张晓风 / 四川人民出版社2018-09
    Uniapp 修改内置组件样式无效解决方法
    Android studio中.9图片的含义及制作教程
    Diff算法
    js new一个对象的过程,实现一个简单的new方法
  • 原文地址:https://www.cnblogs.com/Night-Watch/p/12674618.html
Copyright © 2011-2022 走看看