Home » Modeling » EMF » Cross-document references & resource deletion(Cross-document references & resource deletion)
|
Re: Cross-document references & resource deletion [message #498572 is a reply to message #498432] |
Tue, 17 November 2009 14:39 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Paul,
Comments below.
Paul wrote:
> I'm looking for some pointers regarding the handling of resource
> deletion (and renaming) in the context of cross-document references.
> Having set up an EMF/GMF based tool that supports splitting models
> over multiple files using cross-document references, I found that when
> I delete a file, the references to objects in that file are not removed.
>
> There is some information on cross-document references in the EMF book
> and the forum, so followed that route, with a combination of a
> WorkspaceSynchronizer and the EcoreUtil cross referencer classes, but
> I couldn't get that to work (the resource appeared to be read only),
> so I suspect I'm doing something fundamentally wrong.
>
> Can anyone point me in the right direction please?
The following type of approach ought to work. Load all the resources,
ensure that all proxies are resolved (EcoreUtil.resolveAll), use
EcoreUtil.delete on the root object(s) of the resource being deleted,
the use Resource.delete to actually delete it. Renaming involves the
same first two steps, changing the URIs, then saving all the resources.
>
> Thanks,
> Paul
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Cross-document references & resource deletion [message #498764 is a reply to message #498432] |
Wed, 18 November 2009 15:09 |
Paul Mising name Messages: 6 Registered: November 2009 |
Junior Member |
|
|
Ed,
Thanks for your quick response. I tried to follow your tips by implementing my own delete resource action which tests a platform resource to see if it is EMF based, in which case it carries out some processing to try and remove cross references to it. It then delegates to the org.eclipse.ui.actions.DeleteResourceAction to handle the platform resource deletion.
For the handling of the EMF based resource, my test code does the following once I have a handle on the EMF resource (mySelectedEMFResource):
ResourceSet resourceSet = mySelectedEMFResource.getResourceSet();
EcoreUtil.resolveAll(resourceSet);
editingDomain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDom ain(resourceSet);
AbstractEMFOperation operation = new AbstractEMFOperation(editingDomain, "Delete") {
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
EObject rootObj = mySelectedEMFResource.getContents().get(0);
EcoreUtil.delete(rootObj, true);
return Status.OK_STATUS;
}
};
try {
OperationHistoryFactory.getOperationHistory().execute(operat ion, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
e.printStackTrace();
}
for (Resource resource : resourceSet.getResources()) {
try {
if (resource != mySelectedEMFResource)
resource.save(getSaveOptions());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Unfortunately, it does not remove the unwanted proxy refs from the other resources. I'm continuing to debug, but just thought I'd pass my test code in front of you in case you spotted anything obvious wrong.
Thanks again,
Paul
|
|
|
Re: Cross-document references & resource deletion [message #498828 is a reply to message #498764] |
Wed, 18 November 2009 18:13 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Paul,
Comments below.
Paul wrote:
> Ed,
>
> Thanks for your quick response. I tried to follow your tips by
> implementing my own delete resource action which tests a platform
> resource to see if it is EMF based, in which case it carries out some
> processing to try and remove cross references to it. It then delegates
> to the org.eclipse.ui.actions.DeleteResourceAction to handle the
> platform resource deletion.
Even using Resource.delete should do the trick...
>
> For the handling of the EMF based resource, my test code does the
> following once I have a handle on the EMF resource
> (mySelectedEMFResource):
>
> ResourceSet resourceSet = mySelectedEMFResource.getResourceSet();
> EcoreUtil.resolveAll(resourceSet);
>
> editingDomain =
> TransactionalEditingDomain.Factory.INSTANCE.createEditingDom
> ain(resourceSet);
> AbstractEMFOperation operation = new
> AbstractEMFOperation(editingDomain, "Delete") {
> protected IStatus doExecute(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
> EObject rootObj =
> mySelectedEMFResource.getContents().get(0);
> EcoreUtil.delete(rootObj, true);
> return Status.OK_STATUS;
> }
> };
>
> try {
>
> OperationHistoryFactory.getOperationHistory().execute(operat ion, new
> NullProgressMonitor(), null);
> } catch (ExecutionException e) {
> e.printStackTrace();
> }
>
> for (Resource resource : resourceSet.getResources()) {
> try {
> if (resource != mySelectedEMFResource)
> resource.save(getSaveOptions());
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> Unfortunately, it does not remove the unwanted proxy refs from the
> other resources.
Of course EcoreUtil.resolveAll only resolves outgoing references; it
can't magically know about all incoming references. You'd need to load
all (related) EMF models into one resource set to know all references...
> I'm continuing to debug, but just thought I'd pass my test code in
> front of you in case you spotted anything obvious wrong.
>
> Thanks again,
> Paul
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Cross-document references & resource deletion [message #498971 is a reply to message #498862] |
Thu, 19 November 2009 11:37 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Paul,
Comments below.
Paul wrote:
>> Of course EcoreUtil.resolveAll only resolves outgoing references;
>> it can't magically know about all incoming references. You'd need to
>> load
>> all (related) EMF models into one resource set to know all references...
>
> Sorry if I'm hitting basic stuff here, but if all I have is a handle
> on the EMF resource I want to delete, how do I go about loading all
> the EMF resources that reference it implicity?
It's a good question with only a brute force answer.
> Is there some way of calculating which resources have references to
> objects within the resource I'm about to delete?
Generally one needs to load a resource to know its references. The EMF
Index project will help with things like this by maintaining an index...
>
>> Even using Resource.delete should do the trick...
>
> I do understand that. I went down the route of delegating to
> org.eclipse.ui.actions.DeleteResourceAction simply because I assumed I
> didn't have an easy way of determining whether or not a file I was
> attempting to delete was an EMF based resource up front.
The URI converter is responsible for performing delete using the
platform's resource APIs when that' the appropriate thing.
> So I've implemented my own DeleteResourceAction which does the
> necessary pre-processing of EMF resource deletion if its appropriate,
> but then goes through the normal processing of resource deletion
> whether the resource is EMF based or not.
I see.
>
> I realised that the WorkspaceSynchronizer approach wasn't going to
> help as the events it listens to are too late on in the lifecycle and
> I would be unable to carry out any state changing actions. I would
> much rather go down an approach which utilised the normal platform
> resource deletion machinery with some sort of a listener, so please
> advise if there is a neater approach!
There are no silver bullet solutions for finding all incoming references.
>
> Thanks again for your input,
> Paul
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Mon Sep 23 17:43:55 GMT 2024
Powered by FUDForum. Page generated in 0.03963 seconds
|