Home » Language IDEs » Java Development Tools (JDT) » Getting non-saved changes using IResourceChangeListener
Getting non-saved changes using IResourceChangeListener [message #649601] |
Wed, 19 January 2011 21:09 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi all,
I need to get all files modified (added, changed or deleted) in a project immediately after the change is done. For this, I am now using a custom implementation of IResourceChangeListener, which works pretty good in general.
I can get the DELETED and ADDED events as soon as they are performed on the project I am interested in, however I cannot get the CHANGED events immediately. I only get them (as a bunch of events some times) when user saves the related file(s).
Is there a way to get these events before the user saves the file? If no, is there another way to do what I want to do (i.e., get events as soon as they are done)?
Thanks in advance, regards,
|
|
|
Re: Getting non-saved changes using IResourceChangeListener [message #649644 is a reply to message #649601] |
Thu, 20 January 2011 03:23 |
Deepak Azad Messages: 543 Registered: July 2009 |
Senior Member |
|
|
On 1/20/2011 2:39 AM, Kivanc Muslu wrote:
> Hi all,
>
> I need to get all files modified (added, changed or deleted) in a
> project immediately after the change is done. For this, I am now using a
> custom implementation of IResourceChangeListener, which works pretty
> good in general.
>
> I can get the DELETED and ADDED events as soon as they are performed on
> the project I am interested in, however I cannot get the CHANGED events
> immediately. I only get them (as a bunch of events some times) when user
> saves the related file(s).
A resource - a file on the file system - is not changed until the file
is saved. Till the file is saved the changes remain in the editor and
its underlying buffer.
> Is there a way to get these events before the user saves the file? If
> no, is there another way to do what I want to do (i.e., get events as
> soon as they are done)?
>
> Thanks in advance, regards,
Are you trying to do this in Java editor ?
|
|
|
Re: Getting non-saved changes using IResourceChangeListener [message #649645 is a reply to message #649644] |
Thu, 20 January 2011 03:30 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi Deepak,
Thanks again for the answer.
I am still trying to implement my plug-in where a copy project should be in sync with the project I am monitoring. So I need to use Eclipse API to get the notifications.
If I remember correctly you suggested me to use IResourceChangeListener, which works great, but as I mentioned the problem is that I cannot get the changes unless user actually saves them.
On the other hand the eclipse itself, can show the result of the changes before the user saves them (think that you are using the Eclipse to write code). When you write something that would generate an error (I think you also need autobuild to be selected), the thing you write is automatically underlined and a quick fix on the left automatically appears before you even save the file.
I need to mimic this behavior (somehow) on the copy project, so I need to get the changes that are not saved (so that I can apply them to the copy). As far as I can see IElementChangedListener can do this, however as you also suggested, the events generated by this listener is just huge. So if it does the trick I really do need a way to filter some of the related events I am interested about (I am not sure if it really does the job).
I hope the question is more clear now, please ask if any part does not make sense.
Thanks a lot again, regards,
|
|
|
Re: Getting non-saved changes using IResourceChangeListener [message #649650 is a reply to message #649645] |
Thu, 20 January 2011 04:39 |
Deepak Azad Messages: 543 Registered: July 2009 |
Senior Member |
|
|
On 1/20/2011 9:00 AM, Kivanc Muslu wrote:
> Hi Deepak,
>
> Thanks again for the answer.
>
> I am still trying to implement my plug-in where a copy project should be
> in sync with the project I am monitoring. So I need to use Eclipse API
> to get the notifications.
> If I remember correctly you suggested me to use IResourceChangeListener,
> which works great, but as I mentioned the problem is that I cannot get
> the changes unless user actually saves them.
I can't imagine why you would need a 'copy project', but I am sure you
have good reasons for this. :)
> On the other hand the eclipse itself, can show the result of the changes
> before the user saves them (think that you are using the Eclipse to
> write code). When you write something that would generate an error (I
> think you also need autobuild to be selected), the thing you write is
> automatically underlined and a quick fix on the left automatically
> appears before you even save the file.
As I said only the editor knows about these changes. The reconciling
happens in
org.eclipse.jdt.internal.ui.text.JavaReconciler.ElementChang edListener.elementChanged(ElementChangedEvent).
See
org.eclipse.jdt.internal.ui.text.JavaReconciler.ElementChang edListener.canIgnore(IJavaElementDelta[])
for the filtering bit.
> I need to mimic this behavior (somehow) on the copy project, so I need
> to get the changes that are not saved (so that I can apply them to the
> copy). As far as I can see IElementChangedListener can do this, however
> as you also suggested, the events generated by this listener is just
> huge. So if it does the trick I really do need a way to filter some of
> the related events I am interested about (I am not sure if it really
> does the job).
>
> I hope the question is more clear now, please ask if any part does not
> make sense.
>
> Thanks a lot again, regards,
|
|
|
Re: Getting non-saved changes using IResourceChangeListener [message #649655 is a reply to message #649601] |
Thu, 20 January 2011 06:49 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
On 19.01.2011 22:09, Kivanc Muslu wrote:
> Hi all,
>
> I need to get all files modified (added, changed or deleted) in a
> project immediately after the change is done. For this, I am now using
> a custom implementation of IResourceChangeListener, which works pretty
> good in general.
>
> I can get the DELETED and ADDED events as soon as they are performed
> on the project I am interested in, however I cannot get the CHANGED
> events immediately. I only get them (as a bunch of events some times)
> when user saves the related file(s).
> Is there a way to get these events before the user saves the file?
See org.eclipse.core.filebuffers.IFileBufferListener.
Dani
> If no, is there another way to do what I want to do (i.e., get events
> as soon as they are done)?
>
> Thanks in advance, regards,
|
|
| | |
Re: Getting non-saved changes using IResourceChangeListener [message #651017 is a reply to message #649662] |
Thu, 27 January 2011 13:16 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi Dani,
Thanks a lot for the suggestion it works excellent. I have some sub-question:
1- I am getting a lot of events (almost one for each keystroke), is this normal? I guess it is...
2- I had to add a new IBufferChangedListener for each .java file in the project. I tried adding one listener to the IJavaProject's buffer, however it returned null, so didn't work. Is this the way I should do (i.e., use one listener for each files in the project)? Or is it possible to use IBufferChangedListener in project level (i.e., use one listener to get every buffer change inside the project files)?
3- If I apply refactoring to the original project (that I am listening), applying deltas (i.e., particular events) to the other project does not seem to work. Is there an exception (with respect to buffers) for refactoring? Does refactoring delete and re-create the file?
The best part of IBufferChangedListener is that I can get the exact difference between two files and only apply that to the second file (which is I think better than copying the whole file every time).
Thanks in advance, regards,
~ Kivanc
|
|
|
Re: Getting non-saved changes using IResourceChangeListener [message #651197 is a reply to message #651017] |
Fri, 28 January 2011 10:35 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
On 27.01.2011 14:16, Kivanc Muslu wrote:
> Hi Dani,
>
> Thanks a lot for the suggestion it works excellent. I have some
> sub-question:
>
> 1- I am getting a lot of events (almost one for each keystroke), is
> this normal? I guess it is...
Yes.
> 2- I had to add a new IBufferChangedListener for each .java file in
> the project. I tried adding one listener to the IJavaProject's buffer,
> however it returned null, so didn't work. Is this the way I should do
> (i.e., use one listener for each files in the project)? Or is it
> possible to use IBufferChangedListener in project level (i.e., use one
> listener to get every buffer change inside the project files)?
No.
> 3- If I apply refactoring to the original project (that I am
> listening), applying deltas (i.e., particular events) to the other
> project does not seem to work. Is there an exception (with respect to
> buffers) for refactoring? Does refactoring delete and re-create the file?
Not sure what you mean.
Dani
>
> The best part of IBufferChangedListener is that I can get the exact
> difference between two files and only apply that to the second file
> (which is I think better than copying the whole file every time).
>
> Thanks in advance, regards,
> ~ Kivanc
|
|
|
Re: Getting non-saved changes using IResourceChangeListener [message #651201 is a reply to message #651197] |
Fri, 28 January 2011 10:55 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi Dani,
What I am trying to say is the following:
So my main goal is to sync to files always. When I apply the first file a refactoring (from Eclipse menu), then IBufferChangeListener gets tons of events related to this refactoring (which might be true), however after I apply all of these events, it throws an Exception (I might provide you what it is, if it would help) and change both files to an old stage. Since the only sync problem I had was during refactoring, I wondered if there is something special about it (that it messes up with the buffer events). To me it seemed that after the refactoring is calculated, the original file is deleted, then recreated and the content (which was calculated as the result of the refactoring) is written into it. I know that this is quite weird explanation, however do you know if it is true, or refactoring is actually a sophisticated text edit?
Thank you,
|
|
| |
Goto Forum:
Current Time: Wed Sep 25 21:55:11 GMT 2024
Powered by FUDForum. Page generated in 0.04993 seconds
|