Hi,
I know that i have to wrap every model change into an EMF transaction. I have done that, but I get that error anyway.
How to produce the error?
- I have a RCP with the Graphiti Editor. On Startup a default model file is created and saved to disk, which works fine
- Add a model element (ConfirmDialog)
- Save
Then this error occurs (BUT the model is actually saved correctly, so the new ConfirmDialog appears in the model file)
!ENTRY org.eclipse.graphiti.ui 0 0 2011-09-12 14:13:47.809
!MESSAGE The following resources could not be saved:
URI: platform:/resource/tempEditorProject/diagrams/newDiagram.model, 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)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
at org.eclipse.emf.ecore.util.EcoreEList.dispatchNotification(EcoreEList.java:255)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:300)
at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:591)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(XMLSaveImpl.java:292)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:270)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:206)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1406)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:993)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService$1$1.run(EmfService.java:250)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService$1.run(EmfService.java:261)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1957)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:273)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:211)
at org.eclipse.graphiti.ui.internal.editor.DiagramEditorBehavior$3.execute(DiagramEditorBehavior.java:500)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
!STACK 0
java.lang.RuntimeException
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:275)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:211)
at org.eclipse.graphiti.ui.internal.editor.DiagramEditorBehavior$3.execute(DiagramEditorBehavior.java:500)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
!ENTRY org.eclipse.graphiti.ui 4 0 2011-09-12 14:13:47.809
!MESSAGE The following resources could not be saved:
URI: platform:/resource/tempEditorProject/diagrams/newDiagram.model, 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)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
at org.eclipse.emf.ecore.util.EcoreEList.dispatchNotification(EcoreEList.java:255)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:300)
at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:591)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(XMLSaveImpl.java:292)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:270)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:206)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1406)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:993)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService$1$1.run(EmfService.java:250)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService$1.run(EmfService.java:261)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1957)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:273)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:211)
at org.eclipse.graphiti.ui.internal.editor.DiagramEditorBehavior$3.execute(DiagramEditorBehavior.java:500)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
!STACK 0
java.lang.RuntimeException
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:275)
at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:211)
at org.eclipse.graphiti.ui.internal.editor.DiagramEditorBehavior$3.execute(DiagramEditorBehavior.java:500)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
The problem has to be in the Create feature of the ConfirmDialog or the saveToModelFile() method. I show you the code snippets:
ConfirmDialog:public Object[] create(ICreateContext context) {
// create ConfirmDialog with title and message
final ConfirmDialog newConfirmDialog = EMFFactory.eINSTANCE.createConfirmDialog();
final StringLiteral defaultTitle = EMFFactory.eINSTANCE.createStringLiteral();
final StringLiteral defaultMessage = EMFFactory.eINSTANCE.createStringLiteral();
defaultTitle.setValue("Title");
newConfirmDialog.setTitle(defaultTitle);
defaultMessage.setValue("Message");
newConfirmDialog.setMessage(defaultMessage);
//Use the following instead of the above line to store the model
//data in a seperate file parallel to the diagram file
try {
try {
DiagramUtil.saveToModelFile(newConfirmDialog , getDiagram(), getDiagramEditor().getEditingDomain());
} catch (IOException e) {
e.printStackTrace();
}
} catch (CoreException e) {
e.printStackTrace();
}
// do the add
addGraphicalRepresentation(context, newConfirmDialog);
// activate direct editing after object creation
getFeatureProvider().getDirectEditingInfo().setActive(true);
// return newly created business object(s)
return new Object[] { newConfirmDialog};
}
Here the saveToModelFile() method. (Most of it is copied from org.eclipse.graphiti.examples.tutorial.TutorialUtil.saveToModelFile)public static void saveToModelFile(final EObject obj, final Diagram d,
TransactionalEditingDomain editingDomain) throws CoreException,
IOException {
URI uri = d.eResource().getURI();
uri = uri.trimFragment();
uri = uri.trimFileExtension();
uri = uri.appendFileExtension("model");
ResourceSet rSet = d.eResource().getResourceSet();
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace()
.getRoot();
IResource file = workspaceRoot.findMember(uri.toPlatformString(true));
if (file == null || !file.exists()) {
Resource createResource = rSet.createResource(uri);
createResource.save(Collections.emptyMap());
createResource.setTrackingModification(true);
}
final Resource resource = rSet.getResource(uri, true);
if (obj instanceof DiagramDialog) {
final CommandStack commandStack = editingDomain.getCommandStack();
commandStack.execute(new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
//Save DiagramDialog at proper position
((DocumentRoot) resource.getContents().get(0)).getProcedure().get(0).add((DiagramDialog ) obj);
}
});
}
}
Any ideas? I try to solve this for about 3 hours now and i am running out of ideas...
thx!
[Updated on: Mon, 12 September 2011 08:58]
Report message to a moderator