Andrew
Andrew

Reputation: 83

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?

Upvotes: 0

Views: 433

Answers (2)

Serge Farny
Serge Farny

Reputation: 932

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

Upvotes: 0

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

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.

Upvotes: 0

Related Questions