Skip to main content



      Home
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 09:56 Go to next message
Eclipse UserFriend
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 createEmfFileForDiagram
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();
	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 09:56] by Moderator

Re: Editor marked dirty after loading default diagramm on startup [message #721676 is a reply to message #721673] Fri, 02 September 2011 10:12 Go to previous messageGo to next message
Eclipse UserFriend
Not sure about your issue but:

I guess your FileService class is copied from the examples.common jar (as I did)
Then, didn't you try to call the save() method of that class, after createEmfFileForDiagram(),
instead of doing the save inside it?
Re: Editor marked dirty after loading default diagramm on startup [message #721681 is a reply to message #721676] Fri, 02 September 2011 10:41 Go to previous messageGo to next message
Eclipse UserFriend
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 03:41 Go to previous message
Eclipse UserFriend
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;
}
Previous Topic:Implementing features on which level?
Next Topic:creating nested shapes
Goto Forum:
  


Current Time: Wed Jul 23 18:41:25 EDT 2025

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

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

Back to the top