RoG
RoG

Reputation: 421

Plugin development: listener to resource change in plugin

I am developing plugin of graph that use the objects in the current file that open. If I change the file that open, I want the graph will update. Now, I am using setFocus() method in my class that extends ViewPart, and update the graph in every call to this function. This is not what I want, I want to update the graph only when the resource change. I found this link:

link to similar question

This is like my question, but there is no answer

I need to put the following code in the activator.java file of my plugin?:

   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IResourceChangeListener listener = new IResourceChangeListener() {
      public void resourceChanged(IResourceChangeEvent event) {
         System.out.println("Something changed!");
      }
   };
   workspace.addResourceChangeListener(listener);

   //... some time later one ...
   workspace.removeResourceChangeListener(listener);

If I need to add this code, where to put it? In which method to put it in the activator.java file? If not, what I need to do?

Upvotes: 0

Views: 562

Answers (1)

greg-449
greg-449

Reputation: 111142

Set up the listener in the view part createPartControl.

The activator is not a suitable place to set up listeners as it is only run when some other code in the plugin runs.

Upvotes: 1

Related Questions