Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Handling Resource moves in Workspace
Handling Resource moves in Workspace [message #423360] Mon, 29 September 2008 13:55 Go to next message
Eclipse UserFriend
Originally posted by: twominutehate.joinpoint.org

Hi,

I'd like to know what the preferred way is to handle a move of a
resource, which is contained in a resource set, to a different location.
A WorkspaceSynchronizer looks out for such changes.

Is it better to use Resource.setURI() on the moved Resource, so I don't
have to reload anything?

Or should I rather create a fresh Resource instance at the destination
URI and move the contents from the old Resource to the new one?


Cheers Ömer
Re: Handling Resource moves in Workspace [message #423366 is a reply to message #423360] Mon, 29 September 2008 14:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30822
Registered: July 2009
Senior Member
Ömer,

Comments below.

Ömer Yildiz wrote:
> Hi,
>
> I'd like to know what the preferred way is to handle a move of a
> resource, which is contained in a resource set, to a different location.
It's an interesting question because while the workspace has a notion of
moving something, it's not something that's directly supported by EMF's
APIs...

> A WorkspaceSynchronizer looks out for such changes.
>
> Is it better to use Resource.setURI() on the moved Resource, so I
> don't have to reload anything?
Changing the resource's URI to the new URI, saving it, and using the
URIConverter's delete method on the old URI would certainly do the
trick. If you need an actual workspace delta that's a move as opposed
to and add and a remove you'd have to use the workspace APIs directly...
>
> Or should I rather create a fresh Resource instance at the destination
> URI and move the contents from the old Resource to the new one?
It's probably easier to change the URI of the resource and do the save
and delete thing... It all depends on whether the details of the
resource delta that result are important...
>
>
> Cheers Ömer
Re: Handling Resource moves in Workspace [message #423396 is a reply to message #423366] Mon, 29 September 2008 20:16 Go to previous messageGo to next message
Ã?mer Yildiz is currently offline Ã?mer YildizFriend
Messages: 8
Registered: July 2009
Junior Member
Hi Ed,

there's an issue using any of both methods.
Consider the following situation:

- Instance x* of class X.
- x* is contained in Resource R1.
- Instance y* of class Y.
- Y has a multi-valued containment reference "REF" to X.
- X has a opposite reference to its container.
- y* is contained in Resource R2.

Assume, that currently only R2 is loaded and the user moves R1 to
another directory. To set R1's new URI I first have to load it, of
course. But saving both Resources after that isn't enough, as REF
only contains a proxy object for x* in its list. The proxy's URI
doesn't get updated automatically, so saving R2 doesn't have any effect.
I could iterate through REF to resolve all proxies before saving, but
that seems somehow hacky and not generic enough for me.



Ed Merks schrieb:
> Ömer,
>
> Comments below.
>
> Ömer Yildiz wrote:
>> Hi,
>>
>> I'd like to know what the preferred way is to handle a move of a
>> resource, which is contained in a resource set, to a different location.
> It's an interesting question because while the workspace has a notion of
> moving something, it's not something that's directly supported by EMF's
> APIs...
>
>> A WorkspaceSynchronizer looks out for such changes.
>>
>> Is it better to use Resource.setURI() on the moved Resource, so I
>> don't have to reload anything?
> Changing the resource's URI to the new URI, saving it, and using the
> URIConverter's delete method on the old URI would certainly do the
> trick. If you need an actual workspace delta that's a move as opposed
> to and add and a remove you'd have to use the workspace APIs directly...
>>
>> Or should I rather create a fresh Resource instance at the destination
>> URI and move the contents from the old Resource to the new one?
> It's probably easier to change the URI of the resource and do the save
> and delete thing... It all depends on whether the details of the
> resource delta that result are important...
>>
>>
>> Cheers Ömer
Re: Handling Resource moves in Workspace [message #423398 is a reply to message #423396] Mon, 29 September 2008 20:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30822
Registered: July 2009
Senior Member
Ömer,

Comments below.

Ömer Yildiz wrote:
> Hi Ed,
>
> there's an issue using any of both methods.
> Consider the following situation:
>
> - Instance x* of class X.
> - x* is contained in Resource R1.
> - Instance y* of class Y.
> - Y has a multi-valued containment reference "REF" to X.
> - X has a opposite reference to its container.
> - y* is contained in Resource R2.
>
> Assume, that currently only R2 is loaded and the user moves R1 to
> another directory. To set R1's new URI I first have to load it, of
> course. But saving both Resources after that isn't enough, as REF
> only contains a proxy object for x* in its list. The proxy's URI
> doesn't get updated automatically, so saving R2 doesn't have any effect.
> I could iterate through REF to resolve all proxies before saving, but
> that seems somehow hacky and not generic enough for me.
EcoreUtil.resolveAll applied to the resource set will ensure that all
resources are loaded and all proxies in them are resolved. You can use
the OPTION_SAVE_ONLY_IF_CHANGED so that only if the resource actually
needs to be saved will it be saved...
>
>
>
> Ed Merks schrieb:
> > Ömer,
> >
> > Comments below.
> >
> > Ömer Yildiz wrote:
> >> Hi,
> >>
> >> I'd like to know what the preferred way is to handle a move of a
> >> resource, which is contained in a resource set, to a different
> location.
> > It's an interesting question because while the workspace has a
> notion of
> > moving something, it's not something that's directly supported by EMF's
> > APIs...
> >
> >> A WorkspaceSynchronizer looks out for such changes.
> >>
> >> Is it better to use Resource.setURI() on the moved Resource, so I
> >> don't have to reload anything?
> > Changing the resource's URI to the new URI, saving it, and using the
> > URIConverter's delete method on the old URI would certainly do the
> > trick. If you need an actual workspace delta that's a move as opposed
> > to and add and a remove you'd have to use the workspace APIs
> directly...
> >>
> >> Or should I rather create a fresh Resource instance at the destination
> >> URI and move the contents from the old Resource to the new one?
> > It's probably easier to change the URI of the resource and do the save
> > and delete thing... It all depends on whether the details of the
> > resource delta that result are important...
> >>
> >>
> >> Cheers Ömer
Previous Topic:EMF and JET generating a new package.
Next Topic:Manual Notificatios
Goto Forum:
  


Current Time: Mon Jan 27 16:00:54 GMT 2020

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

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

Back to the top