为什么在Eclipse插件中没有刷新我的资源?

时间:2021-02-11 22:49:37

I have a custom Eclipse plugin I am working on. It has a CustomerExplorer View(Part) that effectively replaces the 'Project Explorer' and it has a number of MultiPageEditorParts, each has a XML editor and a Form editor, both modifying the same configuration file. The XML editor is a TextEditor. The form and the XML are linked and each updates the other whenever there is a pageChange().

我有一个定制的Eclipse插件。它有一个CustomerExplorer视图(Part),可以有效地替换“Project Explorer”,并且它有多个multiply editorpart,每个都有一个XML编辑器和一个表单编辑器,都修改了相同的配置文件。XML编辑器是一个TextEditor。表单和XML是链接的,每当有pageChange()时,每个都更新另一个。

My problem lies in the external modification of files opened in my Eclipse plugin. If I edit a file in an external editor and then load it (from CustomerExplorer View), upon switching to the XML tab I will recieve the message:

我的问题在于对Eclipse插件中打开的文件进行外部修改。如果我在一个外部编辑器中编辑一个文件,然后加载它(从CustomerExplorer视图),在切换到XML选项卡时,我将收到消息:

"Resource is out of sync with the file system: '/example/example.xml'.

Press 'F5' or select File > Refresh to refresh the file.

I am familiar with this error from using Eclipse and usually simply pushing F5, right clicking the file in question and choosing refresh or choosing File > Refresh from the menu bar usually solves it. However, in this case F5 does nothing, File > Refresh is greyed out and right clicking on the file (in my custom view), the context menu does not contain 'refresh'. I have tried opening the 'Project Explorer' view, where 'Refresh' is available in the context menu, but this does nothing.

我很熟悉使用Eclipse时出现的这个错误,通常只需要按F5,右键单击有问题的文件,然后从菜单栏中选择refresh或选择file > refresh就可以解决这个问题。但是,在这种情况下,F5什么都不做,文件> Refresh是灰色的,在我的自定义视图中,右键单击文件,上下文菜单不包含' Refresh '。我尝试过打开“Project Explorer”视图,其中“Refresh”在上下文菜单中可用,但这没有任何作用。

From reading around I have been led to understand that these resources should be refreshed by eclipse but they are not. Any pointers as to why?

通过阅读,我了解到这些资源应该被eclipse刷新,但它们不是。有什么建议吗?

2 个解决方案

#1


0  

Hard to say exactly what is happening here, but you may need to explicitly add the action set for refreshing resources to your custom view.

很难说这里到底发生了什么,但您可能需要显式地将用于刷新资源的操作集添加到自定义视图中。

#2


0  

Another way of solving your issue might be to track change to the file an update your view when there is one:

另一种解决问题的方法可能是跟踪文件的更改,当有更新时更新视图:

ResourcesPlugin.getWorkspace().addResourceChangeListener(new MyResourceTracker(), IResourceChangeEvent.POST_CHANGE);

With something like that:

这样的:

public class MyResourceTrackerimplements IResourceChangeListener {
    @Override
    public void resourceChanged(final IResourceChangeEvent ev) {
        if (ev.getDelta() != null) {
            try {
                ev.getDelta().accept(new IResourceDeltaVisitor() {
                    @Override
                    public boolean visit(final IResourceDelta delta)
                            throws CoreException {
                        // TODO do something
                        return true;
                    }
                });
            } catch (CoreException e) {
                // TODO
            }
        }
    }
}

#1


0  

Hard to say exactly what is happening here, but you may need to explicitly add the action set for refreshing resources to your custom view.

很难说这里到底发生了什么,但您可能需要显式地将用于刷新资源的操作集添加到自定义视图中。

#2


0  

Another way of solving your issue might be to track change to the file an update your view when there is one:

另一种解决问题的方法可能是跟踪文件的更改,当有更新时更新视图:

ResourcesPlugin.getWorkspace().addResourceChangeListener(new MyResourceTracker(), IResourceChangeEvent.POST_CHANGE);

With something like that:

这样的:

public class MyResourceTrackerimplements IResourceChangeListener {
    @Override
    public void resourceChanged(final IResourceChangeEvent ev) {
        if (ev.getDelta() != null) {
            try {
                ev.getDelta().accept(new IResourceDeltaVisitor() {
                    @Override
                    public boolean visit(final IResourceDelta delta)
                            throws CoreException {
                        // TODO do something
                        return true;
                    }
                });
            } catch (CoreException e) {
                // TODO
            }
        }
    }
}