Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Modifying a separate Ecore file outside Create-Features
icon5.gif  Modifying a separate Ecore file outside Create-Features [message #662421] Wed, 30 March 2011 15:36 Go to next message
Rainer Thome is currently offline Rainer Thome
Messages: 5
Registered: December 2010
Junior Member
Hello again,

I have recently tried to create new EObjects outside of a CreateFeature but eventually failed in many cases due to a concurrent write. Strangely, this has also been happening when e.g. working with a wizard.

I am able to create EObjects, but when trying to save the files in my resource set, I am getting the following error:

URI: platform:/resource/BPMNtest/new_file.bpmn2, cause: 
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
...


I can neither modify the resource by executing a Command on the CommandStack nor can I achieve my goal without a Command.
I don't really have a clue on how to solve the problem, but I hope that you can help me.

Best Regards
Rainer

Re: Modifying a separate Ecore file outside Create-Features [message #662424 is a reply to message #662421] Wed, 30 March 2011 15:39 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 108
Registered: October 2010
Senior Member
Rainer, can you give an example of your code both using and not using Command? Also, where is your code triggered? Is this through a Graphiti feature?

Jos
Re: Modifying a separate Ecore file outside Create-Features [message #662429 is a reply to message #662421] Wed, 30 March 2011 15:56 Go to previous messageGo to next message
Rainer Thome is currently offline Rainer Thome
Messages: 5
Registered: December 2010
Junior Member
Hi!

This is my code (using a RecordingCommand):

final BpmnDiagramEditor editor = (BpmnDiagramEditor) Util
	.getActiveEditor();
TransactionalEditingDomain domain = editor.getEditingDomain();
ResourceSet set = domain.getResourceSet();
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
	.put("wsdl", new WSDLResourceFactoryImpl());
Resource r = null;

r = set.createResource(URI.createURI(page.getFilePath()
	.replaceAll("\\\\", "/")
	.replace(Platform.getLocation().toString(), "")));

try {
	r.load(Collections.EMPTY_MAP);
} catch (IOException e) {
	return false;
}

r.setModified(false);
editor.getImportUtil().addResource(r, Util.PORTTYPES);
final List<EObject> objs = editor.getImportUtil()
	.getObjectsForResource(r);

Definitions def = null;
for (Resource res : set.getResources()) {
	if (res.getURI().fileExtension().equals("bpmn2")) {
		def = ((DocumentRoot) res.getContents().get(0))
			.getDefinitions();
		break;
	}
}

final Definitions finalDef = def;
domain.getCommandStack().execute(new RecordingCommand(domain) {
			
@Override
protected void doExecute() {
	for (EObject eObject : objs) {
		Interface iface = Bpmn2Factory.eINSTANCE.createInterface();
		iface.setId(EcoreUtil.generateUUID());
		iface.setImplementationRef(eObject);
		for (Operation op : (EList<Operation>) ((PortType) eObject)
				.getEOperations()) {
			org.eclipse.bpmn2.Operation newOp = Bpmn2Factory.eINSTANCE
					.createOperation();
			newOp.setImplementationRef(op);
			iface.getOperations().add(newOp);
		}
		finalDef.getRootElements().add(iface);
	}
}
});



The code is called inside a "performFinish()" method of a Jface Wizard. The Exception does not occur inside that code piece, but when I am saving the diagram.

Best Regards
Rainer

[Updated on: Wed, 30 March 2011 15:56]

Report message to a moderator

icon7.gif  Re: Modifying a separate Ecore file outside Create-Features [message #662637 is a reply to message #662421] Thu, 31 March 2011 11:35 Go to previous message
Rainer Thome is currently offline Rainer Thome
Messages: 5
Registered: December 2010
Junior Member
Okay, I managed to resolve the problem myself. It was not a problem of Graphiti itself but of the BPMN2 Metamodel, which I am using. It automatically tries to add an ID to all its elements, if the ID was not set before. This interferes with the save process initiated by the EmfService used by Graphiti. I should have known that, because I already experienced the error before, I just forgot about it.

Thanks for your time and sorry, that I kind of wasted it Embarrassed
Previous Topic:how to remove context menu items of a MultiPageEditor
Next Topic:Images from user directories (as opposed to plugin resources)
Goto Forum:
  


Current Time: Thu Oct 23 20:42:33 GMT 2014

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

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