简体   繁体   中英

Why aren't my Resources being refreshed in my Eclipse plugin?

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().

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:

"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.

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?

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

很难确切说明这里发生了什么,但是您可能需要显式添加操作集以刷新资源到自定义视图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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