|
|
Re: Reusing a diagram [message #635034 is a reply to message #633060] |
Mon, 25 October 2010 13:38 |
Cedric Moonen Messages: 274 Registered: August 2009 |
Senior Member |
|
|
I've found something that could maybe be the beginning of a possible solution:
ResourceSet resourceSet = new ResourceSetImpl();
try {
URI modelURI = URI.createFileURI(new File("temp.plcopeneditor")
.getAbsolutePath());
Resource modelResource = resourceSet.createResource(modelURI);
modelResource.getContents().add(diagram.getElement());
modelResource.save(null);
URI diagramURI = URI.createFileURI(new File(
"temp.plcopeneditor_diagram").getAbsolutePath());
Resource diagramResource = resourceSet.createResource(diagramURI);
diagramResource.getContents().add(diagram);
diagramResource.save(null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The previous code creates a resource pointing to the file where I want the information stored (in fact two files, one for the model and one for the diagram). However, this has some serious problems right now
I often get an IllegalStateException thrown ("Cannot modify resource set without a write transaction") with the following stack trace:
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.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1033)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:319)
at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
at PLCOpenEditor.diagram.custom.ExecutionOrderView.save(ExecutionOrderView.java:167)
When this exception is thrown, the file is not saved. However, sometimes, I don't get an exception and the files are then saved properly.
But, when I switch back to the parent diagram it is asking to reload the model from the file and when the model is reloaded, my container block disappear (in fact, it is removed completely from the model). It is removed from the original file.
I think that all these problems come from the fact that when the resource is created and the model is added to the resource, it modifies the internal resource of the model. Thus, the complete model is now "used" by two different resources.
I also tried to load a container block from such a file but the same kind of problems arise.
Anyway, I'm thinking of changing my approach because I don't find a solution for all these problems. If the user wants to create a new block in a "library" he will in fact create a completely separate diagram (this will be done automatically for him).
He will then be able later to open such a library of blocks which has as a consequence to create a new drawer in the palette and populate it with the names of the blocks in the library. Once he creates such a block, the block will be filled programmatically but the user won't be able to open such a block. So, I don't need to take the graphical information into account, I can simply create a temporary model that will be loaded from the file and extract the information from the model to populate the real model on which the user is working on.
It's not a perfect solution but I have no clue how to do it in another way.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04022 seconds