Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Problem with catching ElementChangedEvent with an open editor. (still open)
Problem with catching ElementChangedEvent with an open editor. (still open) [message #715921] Tue, 16 August 2011 00:43 Go to next message
Eclipse UserFriend
I have a java project with the "pack1" package and the "Class1" class.
I open java editor on "Class1.java" and add or remove a method to "Class1".
I want to catch the moment when Java Model is changed.

    myListener= new MyListener();
    JavaCore.addElementChangedListener(myListener,ElementChangedEvent.POST_CHANGE); 


When I open a java editor I receives:

1:
org.eclipse.jdt.core.ElementChangedEvent[source=Java Model[*]: {CHILDREN}
    TestJ2[*]: {CHILDREN}
        src[*]: {CHILDREN}
            pack111[*]: {CHILDREN}
                [Working copy] FailTezt.java[*]: {PRIMARY WORKING COPY}]


This is ok as Eclipse creates new "Working copy" of java file.

But when I make a change and save the file myListener receives the next delta:

2:
org.eclipse.jdt.core.ElementChangedEvent[source=Java Model[*]: {CHILDREN}
    TestJ2[*]: {CHILDREN}
        src[*]: {CHILDREN}
            pack111[*]: {CHILDREN}
                [Working copy] FailTezt.java[*]: {PRIMARY RESOURCE}]


This is strange as after a save my changes should be applied to Java Model, not to Working copy. When I close my editor I receives:

3:
org.eclipse.jdt.core.ElementChangedEvent[source=Java Model[*]: {CHILDREN}
    TestJ2[*]: {CHILDREN}
        src[*]: {CHILDREN}
            pack111[*]: {CHILDREN}
                FailTezt.java[*]: {PRIMARY WORKING COPY}]


This could be ok, as it could mean that the changes eventually reached Java Model. However if I open and close java editor without any changes I receives 1: 3: as well. So I cannot distinguish between model changes and just open/close editor operations.

Please help me. I've really spent many hours trying to figure this out. I have several ideas, but none of them interprets the situation above.

[Updated on: Wed, 17 August 2011 10:27] by Moderator

Report message to a moderator

Re: Problem with catching ElementChangedEvent with an open editor. [message #715935 is a reply to message #715921] Tue, 16 August 2011 03:37 Go to previous messageGo to next message
Eclipse UserFriend
On an open/close editor operations, the delta's changeFlags field of the modified element is F_PRIMARY_WORKING_COPY indicating that a change in the working copy. When the file is saved, the changeFlags is set to F_PRIMARY_RESOURCE indicating that the file is really modified.
Re: Problem with catching ElementChangedEvent with an open editor. [message #716037 is a reply to message #715935] Tue, 16 August 2011 09:09 Go to previous messageGo to next message
Eclipse UserFriend
Then why CompilationUnit::isWorkingCopy() returns true in 1: case and false in 3:.
So what is the code to check if CompilationUnit is WorkingCopy ???

if ((flags & IJavaElementDelta.F_PRIMARY_WORKING_COPY) != 0)
    return true;

if ( ((flags & IJavaElementDelta.F_PRIMARY_RESOURCE) ==0) && (unit.isWorkingCopy())
    return true;


Is it correct?

[Updated on: Tue, 16 August 2011 09:43] by Moderator

Report message to a moderator

Re: Problem with catching ElementChangedEvent with an open editor. [message #716057 is a reply to message #716037] Tue, 16 August 2011 11:10 Go to previous messageGo to next message
Eclipse UserFriend
The delta is generated after the working copy is discarded and hence the CompilationUnit::isWorkingCopy() returns false.
Re: Problem with catching ElementChangedEvent with an open editor. [message #716063 is a reply to message #716057] Tue, 16 August 2011 11:35 Go to previous messageGo to next message
Eclipse UserFriend
So how to catch all and only Java Model changes?

[Updated on: Tue, 16 August 2011 11:36] by Moderator

Report message to a moderator

Re: Problem with catching ElementChangedEvent with an open editor. [message #716447 is a reply to message #716063] Wed, 17 August 2011 12:34 Go to previous messageGo to next message
Eclipse UserFriend
Look at the change flags specified in IJavaElementDelta to find out what all you need.
Re: Problem with catching ElementChangedEvent with an open editor. [message #717404 is a reply to message #716447] Sat, 20 August 2011 12:12 Go to previous message
Eclipse UserFriend
It is not enough to just "look at" these flags. Please read my comments above.

[Updated on: Sun, 21 August 2011 00:11] by Moderator

Report message to a moderator

Previous Topic:does anyone know how to configure this feature
Next Topic:Dynamic help text in XML text editor not working
Goto Forum:
  


Current Time: Fri Feb 14 19:25:00 GMT 2025

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

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

Back to the top