Home » Modeling » Graphiti » Editor marked dirty after loading default diagramm on startup
Editor marked dirty after loading default diagramm on startup [message #721673] |
Fri, 02 September 2011 13:56 |
Christian B Messages: 68 Registered: August 2011 |
Member |
|
|
Hi,
I have a RCP which loads the graphiti Editor post startup and initializes it with a default diagram. The resources of the diagram are also saved to disk. Everything works fine, except the editor is marked dirty
(and probably due to this a emf exception after creating a new model object and saving afterwards -> java.lang.IllegalStateException: Cannot modify resource set without a write transaction).
here are some code snippets for better understanding.
within the postStartup method in my ApplicationWorkbenchAdvisor:
URI uri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
TransactionalEditingDomain domain = FileService.createEmfFileForDiagram(uri, diagram);
String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
editorInput = new DiagramEditorInput(EcoreUtil.getURI(diagram), domain, providerId, true);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
} catch (PartInitException e) {
LOG.error("Error while opening diagram editor", e);
}
The method createEmfFileForDiagrampublic static TransactionalEditingDomain createEmfFileForDiagram(URI diagramResourceUri, final Diagram diagram) {
final TransactionalEditingDomain editingDomain = DiagramEditorFactory.createResourceSetAndEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
URI modelResourceUri = diagramResourceUri.trimFragment().
trimFileExtension().appendFileExtension(OtxPackage.eNS_PREFIX);
final Resource modelResource = resourceSet.createResource(modelResourceUri);
final Resource diagramResource = resourceSet.createResource(diagramResourceUri);
final CommandStack commandStack = editingDomain.getCommandStack();
commandStack.execute(new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
modelResource.setTrackingModification(true);
diagramResource.setTrackingModification(true);
diagramResource.getContents().add(diagram);
try {
EObject rootObject = OtxUtil.createDefaultOtxSkeleton();
modelResource.getContents().add(rootObject);
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
modelResource.save(options);
diagramResource.save(Collections.EMPTY_MAP);
} catch(IOException ioe) {
ioe.printStackTrace();
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
}
});
return editingDomain;
}
So what do i have to do for not marking the editor dirty)?
thx!
[Updated on: Fri, 02 September 2011 13:56] Report message to a moderator
|
|
| |
Re: Editor marked dirty after loading default diagramm on startup [message #721681 is a reply to message #721676] |
Fri, 02 September 2011 14:41 |
Christian B Messages: 68 Registered: August 2011 |
Member |
|
|
thanks, that resolved the "marked dirty" issue! (see new createEmfFileForDiagram () method below)
But the other problem was not solved.
After creating a new model object and saving afterwards, i get:java.lang.IllegalStateException: Cannot modify resource set without a write transaction But i think this is another issue and i will open another thread, if i cannot figure it out myself.
public static TransactionalEditingDomain createEmfFileForDiagram(
URI diagramResourceUri, final Diagram diagram) {
final TransactionalEditingDomain editingDomain = DiagramEditorFactory
.createResourceSetAndEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
URI modelResourceUri = diagramResourceUri.trimFragment()
.trimFileExtension().appendFileExtension(OtxPackage.eNS_PREFIX);
final Resource modelResource = resourceSet
.createResource(modelResourceUri);
final Resource diagramResource = resourceSet
.createResource(diagramResourceUri);
final CommandStack commandStack = editingDomain.getCommandStack();
final Map<Resource, Map<?, ?>> resourceOptionsMap = new HashMap<Resource, Map<?, ?>>();
commandStack.execute(new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
modelResource.setTrackingModification(true);
diagramResource.setTrackingModification(true);
diagramResource.getContents().add(diagram);
try {
EObject rootObject = OtxUtil.createDefaultOtxSkeleton();
modelResource.getContents().add(rootObject);
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
resourceOptionsMap.put(modelResource, options);
resourceOptionsMap.put(diagramResource, Collections.EMPTY_MAP);
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
}
});
save(editingDomain, resourceOptionsMap);
return editingDomain;
}
|
|
|
Re: Editor marked dirty after loading default diagramm on startup [message #722265 is a reply to message #721681] |
Mon, 05 September 2011 07:41 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
You need to do perform every change operation to your model inside an EMF
transaction, that will solve this issue.
HTH,
Michael
"buschcobolt" schrieb im Newsbeitrag news:j3qp9e$23g$1@news.eclipse.org...
thanks, that resolved the "marked dirty" issue! (see new
createEmfFileForDiagram () method below)
But the other problem was not solved.
After creating a new model object and saving afterwards, i
get:java.lang.IllegalStateException: Cannot modify resource set without a
write transactionBut i think this is another issue and i will open another
thread, if i cannot figure it out myself.
public static TransactionalEditingDomain createEmfFileForDiagram(
URI diagramResourceUri, final Diagram diagram) {
final TransactionalEditingDomain editingDomain = DiagramEditorFactory
..createResourceSetAndEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
URI modelResourceUri = diagramResourceUri.trimFragment()
..trimFileExtension().appendFileExtension(OtxPackage.eNS_PREFIX);
final Resource modelResource = resourceSet
..createResource(modelResourceUri);
final Resource diagramResource = resourceSet
..createResource(diagramResourceUri);
final CommandStack commandStack = editingDomain.getCommandStack();
final Map<Resource, Map<?, ?>> resourceOptionsMap = new HashMap<Resource,
Map<?, ?>>();
commandStack.execute(new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
modelResource.setTrackingModification(true);
diagramResource.setTrackingModification(true);
diagramResource.getContents().add(diagram);
try {
EObject rootObject = OtxUtil.createDefaultOtxSkeleton();
modelResource.getContents().add(rootObject);
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
resourceOptionsMap.put(modelResource, options);
resourceOptionsMap.put(diagramResource, Collections.EMPTY_MAP);
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
}
});
save(editingDomain, resourceOptionsMap);
return editingDomain;
}
|
|
|
Goto Forum:
Current Time: Fri Apr 26 19:20:23 GMT 2024
Powered by FUDForum. Page generated in 0.02299 seconds
|