Bug 287025 - IElementChangedListener doesn't receive change events
Summary: IElementChangedListener doesn't receive change events
Status: NEW
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Brian Vosburgh CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2009-08-19 03:17 EDT by Stefan Dimov CLA
Modified: 2012-10-02 16:35 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Dimov CLA 2009-08-19 03:17:20 EDT
Build ID: I20090611-1540


In a tool developed in our NWDS we are using:

JavaCore.addElementChangedListener(<instance of IElementChangedListener>, ElementChangedEvent.POST_CHANGE | ElementChangedEvent.POST_RECONCILE);

in order to track when a certain working copy of a compilation unit has been changed and differs from the original. It appears that the listener doesn't receive POST_CHANGE event when the working copy is changed. It receives only POST_RECONCILE events, but only if the compilation unit is open in some java editor. If the compilation unit is not open in a java editor the listener receives neither POST_CHANGE nor POST_RECONCILE events.
Comment 1 Srikanth Sankaran CLA 2009-08-20 02:03:38 EDT
POST_RECONCILE events are "real-time" feedback of changes
happening to working copy. POST_CHANGE gets sent only when
there is a underlying resource change via a save or commit
working copy operation.

I could verify that even when the resource change is effected
via means other than a java editor (e.g via a CVS replace 
operation) POST_CHANGE gets generated and posted. So I am
not sure there is a defect here.

So how exactly is the java element undergoing change in your
case ? What is the agent of change ? 

Do you see this behavior on 3.5 as well ? 

Do you have a code snippet you can share with us ? 

Jay, can you please follow up ? Thanks

Comment 2 Stefan Dimov CLA 2009-08-20 02:45:03 EDT
(In reply to comment #1)

> ... POST_CHANGE gets sent only when
> there is a underlying resource change via a save or commit
> working copy operation ...

Exactly, but this doesn't suit me, because I need to know when the working copy has been changed and DIFFERS from the underlying resource, which has NOT been changed (yet). How am I supposed to get event for this case?



Comment 3 Srikanth Sankaran CLA 2009-08-20 03:08:57 EDT
(In reply to comment #2)
> (In reply to comment #1)
> > ... POST_CHANGE gets sent only when
> > there is a underlying resource change via a save or commit
> > working copy operation ...
> Exactly, but this doesn't suit me, because I need to know when the working copy
> has been changed and DIFFERS from the underlying resource, which has NOT been
> changed (yet). How am I supposed to get event for this case?

So, it looks like what you are really wondering about
is NOT the missing POST_CHANGE event, but the seemingly
missing POST_RECONCILE event when the change to the working
copy is happening via some agent other than the Java editor.

Who exactly is this change agent ? In general the protocol
is for a change agent to invoke one of the implementations
of (the overloaded) org.eclipse.jdt.core.ICompilationUnit.reconcile.

A change agent first declares its intent to modify something
by invoking the becomeWorkingCopy operation, makes changes, 
reconciles at "appropriate" times, and finally
commits or discards the working copy. If reconcile is not invoked,
then listners don't get to the see the POST_RECONCILE events and
have no clue what changes if any are being made to the working copy.
JDT/Core (as well as platform) would be oblivious to any changes
made, so they cannot notify listeners.

So, in your case, how exactly is the java element undergoing change
in your case ? What is the agent of change ?




Comment 4 Stefan Dimov CLA 2009-08-20 04:14:32 EDT
(In reply to comment #3)

> ... So, in your case, how exactly is the java element undergoing change
> in your case ? What is the agent of change ?

It's a graphical editor based on GEF, which gets working copies of all the visualized java classes and makes changes in them triggered by user actions (mouse-clicks and etc.) These java classes are JPA entities. Also the editor is supposed to reflect immediately all the changes made into the model (from outside the editor). If a certain entity is open (and changed) in a Java editor the IElementChangedListener is being notified with POST_RECONCILE event, but the problem rises when the entity is NOT open in any other editor and the user makes changes in it using JPA details view. Then my listener gets no events.

Comment 5 Srikanth Sankaran CLA 2009-08-20 04:32:48 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > ... So, in your case, how exactly is the java element undergoing change
> > in your case ? What is the agent of change ?
> It's a graphical editor based on GEF, which gets working copies of all the
> visualized java classes and makes changes in them triggered by user actions
> (mouse-clicks and etc.) These java classes are JPA entities. Also the editor is
> supposed to reflect immediately all the changes made into the model (from
> outside the editor).

Sorry, I am not familiar with this - Is this graphical editor part of some eclipse.org project, If so I can forward this defect to that project for
comment.

> If a certain entity is open (and changed) in a Java editor
> the IElementChangedListener is being notified with POST_RECONCILE event, but
> the problem rises when the entity is NOT open in any other editor and the user
> makes changes in it using JPA details view. Then my listener gets no events.

Do you mean to say you are getting POST_RECONCILE events in your listener
when the java files are changed by this graphical editor AND when it is
open in a java editor with only the graphical editor effecting the changes ?

Or that when changes are made in the Java editor you are seeing the
RECONCILE events ?

The latter is not surprising since the java editor would call reconcile
routinely as changes are made.


Comment 6 Stefan Dimov CLA 2009-08-20 04:35:39 EDT
(In reply to comment #5)

> Sorry, I am not familiar with this - Is this graphical editor part of some
> eclipse.org project, If so I can forward this defect to that project for
> comment.

No, it's SAP internal project


> Or that when changes are made in the Java editor you are seeing the
> RECONCILE events ?

Precisely!
Comment 7 Srikanth Sankaran CLA 2009-08-20 04:40:54 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > Sorry, I am not familiar with this - Is this graphical editor part of some
> > eclipse.org project, If so I can forward this defect to that project for
> > comment.
> No, it's SAP internal project
> > Or that when changes are made in the Java editor you are seeing the
> > RECONCILE events ?
> Precisely!

As mentioned in comment#5 this is the expected behavior and there is
no surprise here.

The graphical editor which obtains working copies and changes them
should invoke reconcile operations. If not, there won't be any
notifications to any listeners.

Are you in a position to check if the graphical editor does this ?



Comment 8 Stefan Dimov CLA 2009-08-20 04:48:14 EDT
> The graphical editor which obtains working copies and changes them
> should invoke reconcile operations. If not, there won't be any
> notifications to any listeners.
> 
> Are you in a position to check if the graphical editor does this ?

Yes, I am and no, it does not! But it's not a problem since the editor 'knows' when by itself changes the working copies. 

The question is: How the graphical editor is supposed to trigger a reconciliation since it doesn't 'know' the exact moment when a certain JPA entity has been changed from OUTSIDE the editor and SPECIFICALLY from the JPA details view?

Comment 9 Srikanth Sankaran CLA 2009-08-20 05:17:05 EDT
(In reply to comment #8)
> > The graphical editor which obtains working copies and changes them
> > should invoke reconcile operations. If not, there won't be any
> > notifications to any listeners.
> > 
> > Are you in a position to check if the graphical editor does this ?
> Yes, I am and no, it does not! But it's not a problem since the editor 'knows'
> when by itself changes the working copies. 
> The question is: How the graphical editor is supposed to trigger a
> reconciliation since it doesn't 'know' the exact moment when a certain JPA
> entity has been changed from OUTSIDE the editor and SPECIFICALLY from the JPA
> details view?

I think understand this better now. In this scenario, it doesn't matter
if your graphical editor calls reconcile or not.

When the user makes changes using JPA details view and saves the changes
still you don't see a POST_CHANGE ? 

The save from the JPA details view I assume modifies some Java elements ?
Comment 10 Stefan Dimov CLA 2009-08-20 07:01:54 EDT
(In reply to comment #9)
 
> When the user makes changes using JPA details view and saves the changes
> still you don't see a POST_CHANGE ?

The problem is that when the user makes changes in some java elements using JPA details these changes are immediately reflected in the working copy. At that moment the working copy becomes different from the underlying resource (which is still not changed) and I need an event at that right moment, NOT after saving them ...

Comment 11 Srikanth Sankaran CLA 2009-08-20 07:12:12 EDT
(In reply to comment #10)
> (In reply to comment #9)
> > When the user makes changes using JPA details view and saves the changes
> > still you don't see a POST_CHANGE ?
> The problem is that when the user makes changes in some java elements using JPA
> details these changes are immediately reflected in the working copy. At that
> moment the working copy becomes different from the underlying resource (which
> is still not changed) and I need an event at that right moment, NOT after
> saving them ...


Perhaps the JPA code making these changes to the working
copy is not calling reconcile.

Move to JPA/Dali project for comment.
Comment 12 Stefan Dimov CLA 2009-08-20 07:14:10 EDT
(In reply to comment #11)

> Perhaps the JPA code making these changes to the working
> copy is not calling reconcile.

You mean - the code of the JPA details view?

> Move to JPA/Dali project for comment.

Ok, I will ...

Comment 13 Srikanth Sankaran CLA 2009-08-20 07:18:44 EDT
(In reply to comment #12)
> (In reply to comment #11)
> > Perhaps the JPA code making these changes to the working
> > copy is not calling reconcile.
> You mean - the code of the JPA details view?

Yes, Isn't that the code that is making the changes to a working
version about which changes you are not getting a reconcile event ? 

> > Move to JPA/Dali project for comment.
> Ok, I will ...

Actually, I have moved it myself. The Move to ... was just a comment



Comment 14 Stefan Dimov CLA 2009-08-20 07:21:43 EDT
(In reply to comment #13)

> Yes, Isn't that the code that is making the changes to a working
> version about which changes you are not getting a reconcile event ? 

Yes, it is ...

Okay, let's see what the Dali team have to say ...
Comment 15 Neil Hauge CLA 2009-11-02 11:40:52 EST
(In reply to comment #14)

> Okay, let's see what the Dali team have to say ...

Sorry...this bug fell off my radar for some time.  As Stefan noted, we are not calling reconcile, and I would guess this is the root of the issue here.  Unfortunately we were not aware that this was the protocol.  We will look at fixing this in the next Galileo maintenance release, unless you would only need this for Helios?
Comment 16 Neil Hauge CLA 2010-01-26 10:25:04 EST
Is this requested for Galileo maintenance?
Comment 17 Brian Vosburgh CLA 2010-02-26 10:35:08 EST
I don't see a problem; but maybe I don't understand.

Whenever the JPA Details view manipulates its corresponding Java source file, a POST_RECONCILE event is generated. Whenever the user saves that same file, a POST_CHANGE event is generated. (The JPA Details view does not save an open file.)

I'm not sure what you mean by "If the compilation unit is not open in a java editor the listener receives neither POST_CHANGE nor POST_RECONCILE events" (in your initial Description comment); since the JPA Details view only manipulates open Java source files. Even so, I played around with manipulating closed Java source files, and the appropriate POST_CHANGE event is generated.

Could you tell me how to re-create your problem in a plain WTP workspace (i.e. a workspace w/o your tool installed)?

Thanks.
Comment 18 Neil Hauge CLA 2010-04-01 17:21:45 EDT
Untargeting for now until we get more feedback.