Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Tracking resource changes using AdapterFactoryContentProvider
Tracking resource changes using AdapterFactoryContentProvider [message #419734] Wed, 04 June 2008 14:33 Go to next message
Artun Subasi is currently offline Artun SubasiFriend
Messages: 20
Registered: July 2009
Junior Member
Hello,

I have a tree viewer containing EObjects. My content provider extends
the AdapterFactoryContentProvider class. When I modify my data model
using commands, the viewer is updated without any problems.

I also GMF. The graphical editors are also working on the same data
model. However, changing my model using these graphical editors do not
affect my viewer. Because the underlying data models of the viewer and
the editors have the same resource, but they do not have the same EObjects.

To make it more clear, let's say I have an EObject of type 'Tree' in my
viewer. I double click on this object. A graphical editor is opened. The
editor reads the resource of this EObject and creates a duplicate
EObject of type tree. At this point the EObject of the editor and the
viewer are equal, however they are different objects. So modifying the
model in the editor does not affect the viewer.

What is a good approach to deal with this problem? Can I adjust my
content provider so that it uses the resources to synchronize?

Regards,
Artun
Re: Tracking resource changes using AdapterFactoryContentProvider [message #419740 is a reply to message #419734] Wed, 04 June 2008 16:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Artun,

Comments below.

Artun Subasi wrote:
> Hello,
>
> I have a tree viewer containing EObjects. My content provider extends
> the AdapterFactoryContentProvider class. When I modify my data model
> using commands, the viewer is updated without any problems.
>
> I also GMF. The graphical editors are also working on the same data
> model. However, changing my model using these graphical editors do not
> affect my viewer. Because the underlying data models of the viewer and
> the editors have the same resource, but they do not have the same
> EObjects.
I'm not sure what this means. They read contents from the same
underlying IFile, but into separate resource sets?
>
> To make it more clear, let's say I have an EObject of type 'Tree' in
> my viewer. I double click on this object. A graphical editor is
> opened. The editor reads the resource of this EObject and creates a
> duplicate EObject of type tree. At this point the EObject of the
> editor and the viewer are equal, however they are different objects.
> So modifying the model in the editor does not affect the viewer.
I see.
>
> What is a good approach to deal with this problem? Can I adjust my
> content provider so that it uses the resources to synchronize?
Ideally they'd share the underlying instance since that seems like the
only solution to me. The underlying backing store doesn't change until
you save the resource so I assume you'd like something much more
immediate than updates only after save...
>
> Regards,
> Artun


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Tracking resource changes using AdapterFactoryContentProvider [message #419744 is a reply to message #419740] Wed, 04 June 2008 16:58 Go to previous messageGo to next message
Artun Subasi is currently offline Artun SubasiFriend
Messages: 20
Registered: July 2009
Junior Member
Hello Ed,

Thank you for your comments!

They share the same underlying resources. Let's assume I have a single
resource. When I start my (rcp) application, the viewer loads this
resource and gets the contained EObject "Tree A". Then, I open this
resource with a graphical editor, it creates another EObject "Tree B".
Both "Tree A" and "Tree B" have the same underlying resource, but their
object identities are different. Therefore, the editor only modifies
"Tree A". Even after saving, the "Tree B" does not update, even though
the underlying resource is changed.

To open the editor, I use the openDiagram method which was generated by
GMF (and it uses the IEditorPart.openEditor method of eclipse
internally). It takes the diagram resource file as input. I can't seem
to say that it should use the same "Tree A" object as the model. It
contructs a new EObject.

Every day I discover something new in the EMF/GMF world. So instead of
implementing my own listeners and adapters, I am searching if EMF
already provides something to help me in this matter.

Updating the viewer only after saving is enough for me.

Regards,
Artun

Ed Merks schrieb:
> Artun,
>
> Comments below.
>
> Artun Subasi wrote:
>> Hello,
>>
>> I have a tree viewer containing EObjects. My content provider extends
>> the AdapterFactoryContentProvider class. When I modify my data model
>> using commands, the viewer is updated without any problems.
>>
>> I also GMF. The graphical editors are also working on the same data
>> model. However, changing my model using these graphical editors do not
>> affect my viewer. Because the underlying data models of the viewer and
>> the editors have the same resource, but they do not have the same
>> EObjects.
> I'm not sure what this means. They read contents from the same
> underlying IFile, but into separate resource sets?
>>
>> To make it more clear, let's say I have an EObject of type 'Tree' in
>> my viewer. I double click on this object. A graphical editor is
>> opened. The editor reads the resource of this EObject and creates a
>> duplicate EObject of type tree. At this point the EObject of the
>> editor and the viewer are equal, however they are different objects.
>> So modifying the model in the editor does not affect the viewer.
> I see.
>>
>> What is a good approach to deal with this problem? Can I adjust my
>> content provider so that it uses the resources to synchronize?
> Ideally they'd share the underlying instance since that seems like the
> only solution to me. The underlying backing store doesn't change until
> you save the resource so I assume you'd like something much more
> immediate than updates only after save...

>>
>> Regards,
>> Artun
Re: Tracking resource changes using AdapterFactoryContentProvider [message #419745 is a reply to message #419744] Wed, 04 June 2008 17:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Artun,

Comments below.


Artun Subasi wrote:
> Hello Ed,
>
> Thank you for your comments!
>
> They share the same underlying resources. Let's assume I have a single
> resource. When I start my (rcp) application, the viewer loads this
> resource and gets the contained EObject "Tree A". Then, I open this
> resource with a graphical editor, it creates another EObject "Tree B".
> Both "Tree A" and "Tree B" have the same underlying resource, but
> their object identities are different. Therefore, the editor only
> modifies "Tree A". Even after saving, the "Tree B" does not update,
> even though the underlying resource is changed.
In the generated EMF editor, you'll see there is a listener added to the
workspace that listens for resource deltas and updates the EMF resource
when the IFile it corresponds to changes...
>
>
> To open the editor, I use the openDiagram method which was generated
> by GMF (and it uses the IEditorPart.openEditor method of eclipse
> internally). It takes the diagram resource file as input. I can't seem
> to say that it should use the same "Tree A" object as the model. It
> contructs a new EObject.
I think the transactional editing domain supports some type of
registration that would allow sharing, but I'm not so familiar with how
that works. Maybe Christian will comment.
>
> Every day I discover something new in the EMF/GMF world. So instead of
> implementing my own listeners and adapters, I am searching if EMF
> already provides something to help me in this matter.
>
> Updating the viewer only after saving is enough for me.
Then probably looking at the logic in a generated EMF editor for
listening to workspace deltas will help a lot.
>
> Regards,
> Artun
>
> Ed Merks schrieb:
>> Artun,
>>
>> Comments below.
>>
>> Artun Subasi wrote:
>>> Hello,
>>>
>>> I have a tree viewer containing EObjects. My content provider
>>> extends the AdapterFactoryContentProvider class. When I modify my
>>> data model using commands, the viewer is updated without any problems.
>>>
>>> I also GMF. The graphical editors are also working on the same data
>>> model. However, changing my model using these graphical editors do
>>> not affect my viewer. Because the underlying data models of the
>>> viewer and the editors have the same resource, but they do not have
>>> the same EObjects.
>> I'm not sure what this means. They read contents from the same
>> underlying IFile, but into separate resource sets?
>>>
>>> To make it more clear, let's say I have an EObject of type 'Tree' in
>>> my viewer. I double click on this object. A graphical editor is
>>> opened. The editor reads the resource of this EObject and creates a
>>> duplicate EObject of type tree. At this point the EObject of the
>>> editor and the viewer are equal, however they are different objects.
>>> So modifying the model in the editor does not affect the viewer.
>> I see.
>>>
>>> What is a good approach to deal with this problem? Can I adjust my
>>> content provider so that it uses the resources to synchronize?
>> Ideally they'd share the underlying instance since that seems like
>> the only solution to me. The underlying backing store doesn't change
>> until you save the resource so I assume you'd like something much
>> more immediate than updates only after save...
>
>>>
>>> Regards,
>>> Artun


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Tracking resource changes using AdapterFactoryContentProvider [message #419747 is a reply to message #419745] Wed, 04 June 2008 18:33 Go to previous messageGo to next message
Artun Subasi is currently offline Artun SubasiFriend
Messages: 20
Registered: July 2009
Junior Member
Ed,

I generated editor code using the genmodel of my data model. I can
create and edit my model using this generated EMF editor. But the EMF
editor does not get updated if I change the corresponding file externally.

For example, I created a node using the EMF editor and saved the file. I
opened the same file using an external text editor, deleted the newly
xml node and saved it. The EMF editor did not get updated. It is only
updated if I close the EMF editor and reopen the model.

Are you referring to another EMF editor?

Regards,
Artun

Ed Merks schrieb:
> Artun,
>
> Comments below.
>
>
> Artun Subasi wrote:
>> Hello Ed,
>>
>> Thank you for your comments!
>>
>> They share the same underlying resources. Let's assume I have a single
>> resource. When I start my (rcp) application, the viewer loads this
>> resource and gets the contained EObject "Tree A". Then, I open this
>> resource with a graphical editor, it creates another EObject "Tree B".
>> Both "Tree A" and "Tree B" have the same underlying resource, but
>> their object identities are different. Therefore, the editor only
>> modifies "Tree A". Even after saving, the "Tree B" does not update,
>> even though the underlying resource is changed.
> In the generated EMF editor, you'll see there is a listener added to the
> workspace that listens for resource deltas and updates the EMF resource
> when the IFile it corresponds to changes...
>>
>>
>> To open the editor, I use the openDiagram method which was generated
>> by GMF (and it uses the IEditorPart.openEditor method of eclipse
>> internally). It takes the diagram resource file as input. I can't seem
>> to say that it should use the same "Tree A" object as the model. It
>> contructs a new EObject.
> I think the transactional editing domain supports some type of
> registration that would allow sharing, but I'm not so familiar with how
> that works. Maybe Christian will comment.
>>
>> Every day I discover something new in the EMF/GMF world. So instead of
>> implementing my own listeners and adapters, I am searching if EMF
>> already provides something to help me in this matter.
>>
>> Updating the viewer only after saving is enough for me.
> Then probably looking at the logic in a generated EMF editor for
> listening to workspace deltas will help a lot.
>>
>> Regards,
>> Artun
>>
>> Ed Merks schrieb:
>>> Artun,
>>>
>>> Comments below.
>>>
>>> Artun Subasi wrote:
>>>> Hello,
>>>>
>>>> I have a tree viewer containing EObjects. My content provider
>>>> extends the AdapterFactoryContentProvider class. When I modify my
>>>> data model using commands, the viewer is updated without any problems.
>>>>
>>>> I also GMF. The graphical editors are also working on the same data
>>>> model. However, changing my model using these graphical editors do
>>>> not affect my viewer. Because the underlying data models of the
>>>> viewer and the editors have the same resource, but they do not have
>>>> the same EObjects.
>>> I'm not sure what this means. They read contents from the same
>>> underlying IFile, but into separate resource sets?
>>>>
>>>> To make it more clear, let's say I have an EObject of type 'Tree' in
>>>> my viewer. I double click on this object. A graphical editor is
>>>> opened. The editor reads the resource of this EObject and creates a
>>>> duplicate EObject of type tree. At this point the EObject of the
>>>> editor and the viewer are equal, however they are different objects.
>>>> So modifying the model in the editor does not affect the viewer.
>>> I see.
>>>>
>>>> What is a good approach to deal with this problem? Can I adjust my
>>>> content provider so that it uses the resources to synchronize?
>>> Ideally they'd share the underlying instance since that seems like
>>> the only solution to me. The underlying backing store doesn't change
>>> until you save the resource so I assume you'd like something much
>>> more immediate than updates only after save...
>>
>>>>
>>>> Regards,
>>>> Artun
Re: Tracking resource changes using AdapterFactoryContentProvider [message #419748 is a reply to message #419747] Wed, 04 June 2008 18:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Artun,

Comments below.


Artun Subasi wrote:
> Ed,
>
> I generated editor code using the genmodel of my data model. I can
> create and edit my model using this generated EMF editor. But the EMF
> editor does not get updated if I change the corresponding file
> externally.
It does when you refresh the workspace. There's an option to auto
refresh the workspace when the Eclipse window is activated if you
actually do this a lot.
>
> For example, I created a node using the EMF editor and saved the file.
> I opened the same file using an external text editor, deleted the
> newly xml node and saved it. The EMF editor did not get updated. It is
> only updated if I close the EMF editor and reopen the model.
>
> Are you referring to another EMF editor?
The Eclipse text editor is even fancier and checks timestamps when the
editor is activated so it knows there's a change even without a
workspace refresh...
>
> Regards,
> Artun
>
> Ed Merks schrieb:
>> Artun,
>>
>> Comments below.
>>
>>
>> Artun Subasi wrote:
>>> Hello Ed,
>>>
>>> Thank you for your comments!
>>>
>>> They share the same underlying resources. Let's assume I have a
>>> single resource. When I start my (rcp) application, the viewer loads
>>> this resource and gets the contained EObject "Tree A". Then, I open
>>> this resource with a graphical editor, it creates another EObject
>>> "Tree B". Both "Tree A" and "Tree B" have the same underlying
>>> resource, but their object identities are different. Therefore, the
>>> editor only modifies "Tree A". Even after saving, the "Tree B" does
>>> not update, even though the underlying resource is changed.
>> In the generated EMF editor, you'll see there is a listener added to
>> the workspace that listens for resource deltas and updates the EMF
>> resource when the IFile it corresponds to changes...
>>>
>>>
>>> To open the editor, I use the openDiagram method which was generated
>>> by GMF (and it uses the IEditorPart.openEditor method of eclipse
>>> internally). It takes the diagram resource file as input. I can't
>>> seem to say that it should use the same "Tree A" object as the
>>> model. It contructs a new EObject.
>> I think the transactional editing domain supports some type of
>> registration that would allow sharing, but I'm not so familiar with
>> how that works. Maybe Christian will comment.
>>>
>>> Every day I discover something new in the EMF/GMF world. So instead
>>> of implementing my own listeners and adapters, I am searching if EMF
>>> already provides something to help me in this matter.
>>>
>>> Updating the viewer only after saving is enough for me.
>> Then probably looking at the logic in a generated EMF editor for
>> listening to workspace deltas will help a lot.
>>>
>>> Regards,
>>> Artun
>>>
>>> Ed Merks schrieb:
>>>> Artun,
>>>>
>>>> Comments below.
>>>>
>>>> Artun Subasi wrote:
>>>>> Hello,
>>>>>
>>>>> I have a tree viewer containing EObjects. My content provider
>>>>> extends the AdapterFactoryContentProvider class. When I modify my
>>>>> data model using commands, the viewer is updated without any
>>>>> problems.
>>>>>
>>>>> I also GMF. The graphical editors are also working on the same
>>>>> data model. However, changing my model using these graphical
>>>>> editors do not affect my viewer. Because the underlying data
>>>>> models of the viewer and the editors have the same resource, but
>>>>> they do not have the same EObjects.
>>>> I'm not sure what this means. They read contents from the same
>>>> underlying IFile, but into separate resource sets?
>>>>>
>>>>> To make it more clear, let's say I have an EObject of type 'Tree'
>>>>> in my viewer. I double click on this object. A graphical editor is
>>>>> opened. The editor reads the resource of this EObject and creates
>>>>> a duplicate EObject of type tree. At this point the EObject of the
>>>>> editor and the viewer are equal, however they are different
>>>>> objects. So modifying the model in the editor does not affect the
>>>>> viewer.
>>>> I see.
>>>>>
>>>>> What is a good approach to deal with this problem? Can I adjust my
>>>>> content provider so that it uses the resources to synchronize?
>>>> Ideally they'd share the underlying instance since that seems like
>>>> the only solution to me. The underlying backing store doesn't
>>>> change until you save the resource so I assume you'd like something
>>>> much more immediate than updates only after save...
>>>
>>>>>
>>>>> Regards,
>>>>> Artun


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Changing the Meta Model while there are Instances
Next Topic:Annotation to signal resource bundle key replacement
Goto Forum:
  


Current Time: Thu Apr 25 07:46:10 GMT 2024

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

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

Back to the top