Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » register IResourceChangeListener
register IResourceChangeListener [message #319578] Mon, 27 August 2007 04:24 Go to next message
Eclipse UserFriend
Originally posted by: alexjaquet.gmail.com

Hi,

How in a class can I register a IResourceChangeListener. t


thx

Alexandre
Re: register IResourceChangeListener [message #319579 is a reply to message #319578] Mon, 27 August 2007 04:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexjaquet.gmail.com

To be more precise wich class (I'm working on a plugin) should register
the listener

I found this interesting article
http://www.eclipse.org/articles/Article-Resource-deltas/reso urce-deltas.html


but they doesn't say wich class should implement this
Re: register IResourceChangeListener [message #319581 is a reply to message #319579] Mon, 27 August 2007 05:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexjaquet.gmail.com

I finaly found how to register a IResourceChangeListener

public PageDesignerEditor () {
ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s);
}

and implemented the resourceChanged method like this :

public void resourceChanged(IResourceChangeEvent event) {
if(event.getType() == IResourceChangeEvent.POST_CHANGE){
IResource resource = event.getResource();
try {
if(resource.getType() == IResource.PROJECT && ((IProject)
resource).hasNature(JavaCore.NATURE_ID)) {
resource.delete(true, null);
}
}catch (Exception ex) {

}
}
}
but now I'm facing a problem with the resource, it's always null.

Do you have any idea why ?

Thanks
Re: register IResourceChangeListener [message #319585 is a reply to message #319579] Mon, 27 August 2007 06:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Alexandre,

You had a related question in the EMF newsgroup where I mentioned having
a look at the generated EMF editor to see how it uses
resourceChangeListener to respond to changes in the workbench. E.g., to
close the editor if the resource being edited is deleted, or to remove
from the resource set a resource corresponding to a workspace IFile
that's been deleted.


Alexandre Jaquet wrote:
> To be more precise wich class (I'm working on a plugin) should
> register the listener
>
> I found this interesting article
> http://www.eclipse.org/articles/Article-Resource-deltas/reso urce-deltas.html
>
>
> but they doesn't say wich class should implement this
Re: register IResourceChangeListener [message #319587 is a reply to message #319581] Mon, 27 August 2007 06:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------030600010403060807010808
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Alexandre,

The Javadoc says this for getResource():

/**
* Returns the resource in question or <code>null</code>
* if not applicable to this type of event.
* <p>
* If the event is a <code>PRE_CLOSE</code> or
* <code>PRE_DELETE</code> event then the resource
* will be the affected project. Otherwise the resource will
* be <code>null</code>.
* </p>
* @return the resource, or <code>null</code> if not applicable
*/



Alexandre Jaquet wrote:
> I finaly found how to register a IResourceChangeListener
>
> public PageDesignerEditor () {
>
> ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s);
> }
>
> and implemented the resourceChanged method like this :
>
> public void resourceChanged(IResourceChangeEvent event) {
> if(event.getType() == IResourceChangeEvent.POST_CHANGE){
> IResource resource = event.getResource();
> try {
> if(resource.getType() == IResource.PROJECT &&
> ((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
> resource.delete(true, null);
> }
> }catch (Exception ex) {
>
> }
> }
> }
> but now I'm facing a problem with the resource, it's always null.
>
> Do you have any idea why ?
>
> Thanks


--------------030600010403060807010808
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alexandre,<br>
<br>
The Javadoc says this for getResource():<br>
<blockquote><small>&nbsp;&nbsp;&nbsp; /**</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* Returns the resource in question or
&lt;code&gt;null&lt;/code&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* if not applicable to this type of event. </small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* &lt;p&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* If the event is a &lt;code&gt;PRE_CLOSE&lt;/code&gt; or
</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* &lt;code&gt;PRE_DELETE&lt;/code&gt; event then the
resource </small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* will be the affected project. Otherwise the resource
will </small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* be &lt;code&gt;null&lt;/code&gt;.</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* &lt;/p&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;* @return the resource, or &lt;code&gt;null&lt;/code&gt;
if not applicable</small><br>
<small>&nbsp;&nbsp;&nbsp; &nbsp;*/</small><br>
</blockquote>
<br>
<br>
Alexandre Jaquet wrote:
<blockquote cite="mid:fau6q2$lis$1@build.eclipse.org" type="cite">I
finaly found how to register a IResourceChangeListener
<br>
<br>
public PageDesignerEditor () {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
ResourcesPlugin.getWorkspace().addResourceChangeListener(thi s);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>
and implemented the resourceChanged method like this :
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;public void resourceChanged(IResourceChangeEvent event) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if(event.getType() == IResourceChangeEvent.POST_CHANGE){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IResource resource = event.getResource();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(resource.getType() == IResource.PROJECT &amp;&amp;
((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; resource.delete(true, null);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }catch (Exception ex) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
but now I'm facing a problem with the resource, it's always null.
<br>
<br>
Do you have any idea why ?
<br>
<br>
Thanks
<br>
</blockquote>
<br>
</body>
</html>

--------------030600010403060807010808--
Re: register IResourceChangeListener [message #319588 is a reply to message #319587] Mon, 27 August 2007 06:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexjaquet.gmail.com

Hi Ed,

First thanks for responding, but
if(event.getType() == IResourceChangeEvent.PRE_DELETE) doesn't work I ve
to do
if(event.getType() == IResourceChangeEvent.POST_CHANGE)

how can I get the file to delete ?
Re: register IResourceChangeListener [message #319590 is a reply to message #319588] Mon, 27 August 2007 07:17 Go to previous message
Eclipse UserFriend
Originally posted by: alexjaquet.gmail.com

Finally by adding the implementation of IResourceDeltaVisitor helps to work.
Previous Topic:Is it possible to navigate screens behind a JFace Wizard?
Next Topic:How to add JUnit classpath container when creating new Java project?
Goto Forum:
  


Current Time: Mon Jun 16 07:45:22 EDT 2025

Powered by FUDForum. Page generated in 0.25649 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top