Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How can I be notified of changes to the workspace?"

 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Resource change listeners are notified of most changes that
+
Resource change listeners are notified of most changes that occur in the workspace, including when any file, folder, or project is created, deleted, or modified. Listeners can also be registered for some special events, such as before projects are deleted or closed and before and after workspace autobuilds. Registering a resource change listener is easy:
occur in the workspace, including when any file, folder, or project
+
 
is created, deleted, or modified. Listeners can also be registered
+
for some special events, such as before projects are deleted or
+
closed and before and after workspace autobuilds. Registering
+
a resource change listener is easy:
+
 
<pre>
 
<pre>
 
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
 
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
Line 13: Line 9:
 
   workspace.addResourceChangeListener(rcl);
 
   workspace.addResourceChangeListener(rcl);
 
</pre>
 
</pre>
Always make sure that you remove your resource change listener when you
+
 
no longer need it:
+
Always make sure that you remove your resource change listener when you no longer need it:
 +
 
 
<pre>
 
<pre>
 
   workspace.removeResourceChangeListener(rcl);
 
   workspace.removeResourceChangeListener(rcl);
 
</pre>
 
</pre>
  
Look at the javadoc for <tt>IWorkspace.addResourceChangeListener</tt>
+
Look at the javadoc for <tt>IWorkspace.addResourceChangeListener</tt> for more information on the various types of resource change events you can listen to and the  restrictions that apply. It is important to keep performance in mind when writing a resource change listener.   Listeners are notified at the end of every operation that changes the workspace, so any overhead that you add in your listener will degrade the performance of all such operations.  If your listener needs to do expensive processing, consider off-loading some of the work into another thread, preferably by using a Job as described in [[FAQ Does the platform have support for concurrency?]]
for more information on the various types of resource change events you
+
can listen to and the  restrictions that apply. It is important to
+
keep performance in mind when writing a resource change listener.
+
Listeners are notified at the end of every operation that changes the workspace,
+
so any overhead that you add in your listener will degrade the performance
+
of all such operations.  If your listener needs to do expensive processing,
+
consider off-loading some of the work into another thread, preferably
+
by using a Job as described in[[FAQ_Does_the_platform_have_support_for_concurrency%3F]]
+
  
 
== See Also: ==
 
== See Also: ==
 
+
*[[FAQ Does the platform have support for concurrency?]]
[[FAQ_Does_the_platform_have_support_for_concurrency%3F]]
+
*[http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.html Eclipse online article &#147;How You&#146;ve Changed! Responding to resource changes in the Eclipse workspace&#148;]
 
+
Go to '''Platform Plug-in Developer Guide &gt; Programmer&#146;s Guide
+
&gt; Resources overview &gt; Tracking resource changes''',
+
Eclipse online article &#147;How You&#146;ve Changed! Responding to resource changes in the Eclipse workspace&#148;
+
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 14:50, 7 January 2007

Resource change listeners are notified of most changes that occur in the workspace, including when any file, folder, or project is created, deleted, or modified. Listeners can also be registered for some special events, such as before projects are deleted or closed and before and after workspace autobuilds. Registering a resource change listener is easy:

   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IResourceChangeListener rcl = new IResourceChangeListener() {
      public void resourceChanged(IResourceChangeEvent event) {
      }
   };
   workspace.addResourceChangeListener(rcl);

Always make sure that you remove your resource change listener when you no longer need it:

   workspace.removeResourceChangeListener(rcl);

Look at the javadoc for IWorkspace.addResourceChangeListener for more information on the various types of resource change events you can listen to and the restrictions that apply. It is important to keep performance in mind when writing a resource change listener. Listeners are notified at the end of every operation that changes the workspace, so any overhead that you add in your listener will degrade the performance of all such operations. If your listener needs to do expensive processing, consider off-loading some of the work into another thread, preferably by using a Job as described in FAQ Does the platform have support for concurrency?

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.