简体   繁体   English

Eclipse插件-刷新Eclipse项目中的链接文件夹

[英]Eclipse plugin - refresh linked folders in eclipse project

I'm trying to implement a refresh algorithm for an Eclipse plugin and can't find a way to handle linked folders. 我正在尝试为Eclipse插件实现刷新算法,但找不到处理链接文件夹的方法。

To sum it up I have some features in my application which generate some files in the same project I work in. In order to see those files I usually have to press F5. 综上所述,我的应用程序中具有一些功能,这些功能会在我从事的同一个项目中生成一些文件。为了查看这些文件,我通常必须按F5键。 However I tried implementing a refresh algorithm so I don't have to press F5 anymore and the refresh to be made automatically. 但是,我尝试实现一种刷新算法,因此不必再按F5即可自动进行刷新。

Here is a part of my algorithm 这是我算法的一部分

        File osFile = iPath.toFile();
        if (osFile.exists()) {
            if (osFile.isFile()) {
                IFile[] filesArr = workspaceRoot
                        .findFilesForLocationURI(iPath.toFile().toURI());

                if (filesArr != null && filesArr.length > 0) {
                    for (IFile file : filesArr) {
                        try {
                            file.refreshLocal(IResource.DEPTH_INFINITE,
                                    new NullProgressMonitor());
                        } catch (CoreException e) {
                            Activator.getDefault().log(IStatus.ERROR,
                                    e.getLocalizedMessage(), e);
                        }
                    }
                }
            } else if (osFile.isDirectory()) {
                iPath = iPath.makeRelativeTo(workspaceRoot.getLocation());

                IResource resource = null;
                if (iPath.segmentCount() == 1) {
                    resource = workspaceRoot.getProject(iPath.toString());
                } else {
                    try {
                        resource = workspaceRoot.getFolder(iPath);
                    } catch (Exception e) {
                        Activator.getDefault().log(IStatus.ERROR,
                                e.getLocalizedMessage(), e);
                    }
                }

                try {
                    if (resource != null) {
                        resource.refreshLocal(IResource.DEPTH_INFINITE,
                                new NullProgressMonitor());
                    }
                } catch (CoreException e) {
                    Activator.getDefault().log(IStatus.ERROR,
                            e.getLocalizedMessage(), e);
                }
            }

Where iPath is the absolute path (C:......) to the file or folder I want to refresh. 其中iPath是我要刷新的文件或文件夹的绝对路径(C:......)。

For individual files and for non-linked folders this works great, however when it comes to linked folders it fails. 对于单个文件和未链接的文件夹,此方法效果很好,但是,当涉及链接文件夹时,它将失败。 The problem comes at this very line: 问题就在这行:

iPath = iPath.makeRelativeTo(workspaceRoot.getLocation());

Where at a non-linked folder it will transform an absolute path(C:......) to an Eclipse local path (MyProject/tmp/destinationFolder), for a linked folder it will just get the absolute path on the OS. 在非链接文件夹中,它将绝对路径(C:......)转换为Eclipse本地路径(MyProject / tmp / destinationFolder),对于链接文件夹,它将仅获得操作系统上的绝对路径。

Then the following line of code: 然后是以下代码行:

resource = workspaceRoot.getFolder(iPath);

Will remove the "C:\\" from the path and concatenate it to a tentative eclipse path (resulting something like F/user/desktop/project/folder) ultimately pointing to nothing. 将从路径中删除“ C:\\”,并将其连接到一个临时的月食路径(结果是F / user / desktop / project / folder之类的东西),最终什么也没有指向。

So, can anyone help me refactor my algorithm in order to correctly handle linked folders? 因此,有人可以帮助我重构算法以正确处理链接的文件夹吗? There might be some methods or classes I'm not familiar with and missing out on, that might deal with exactly this kind of issues. 有些方法或类可能是我不熟悉并错过的,可能恰好解决了这类问题。

IWorkspaceRoot具有findContainersForLocationURI ,该容器返回位置URI的容器(容器可以是文件夹,也可以是项目)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM