Home » Modeling » Graphiti » Diagram does not update after model is changed
| |
Re: Diagram does not update after model is changed [message #1694626 is a reply to message #1694553] |
Wed, 06 May 2015 17:52 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
Michael,
That's what I thought when I was reading the documentation, however I am running into issues where I cannot even create shapes or get fonts unless I perform these functions in context of a Command.
For example:
IGaService gaService = Graphiti.getGaService();
channelFont = gaService.manageFont(getDiagram(), "Tahoma" , 15, false, true);
channelContainerFont = gaService.manageFont(getDiagram(), "Tahoma" , 10, false, false);
channelContainer = createService.createContainerShape(getDiagram(), true);
All throw java.lang.IllegalStateException: Cannot modify resource set without a write transaction exception. I am not sure if this is because of how I am setting editingDomain by reusing Graphiti's domain, this is how I set it:
public void init(IEditorSite site, IEditorInput editorInput) {
// TODO Auto-generated method stub
diagramEditor = new ChannelDiagramEditor();
IFile inputFile = ((FileEditorInput)editorInput).getFile();
IFile file = inputFile.getParent().getFile(new Path(inputFile.getName().substring(0,inputFile.getName().lastIndexOf(".")) + "." + WorkspaceUtil.inline_channel_diagram_extension));
diagramEditor.setInputFile(file);
input = new FileEditorInput(file);
try {
diagramEditor.init(site, input);
editingDomain = diagramEditor.getDiagramBehavior().getEditingDomain(); <--- used by TreeViewer
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.init(site, editorInput);
}
I've done some debugging in this area and see that when for example, in the following code
gaService.manageFont(getDiagram(), "Tahoma" , 15, false, true);
Exception is thrown at line
in manageFont(...). Further down it looks like in TransactionalChangeRecorder.assertWriting() the InternalTransaction does not resolve to anything in
InternalTransaction tx = domain.getActiveTransaction();
and hence the exception.
I also checked IDs for editing domains that I am using in TreeViewer editor and Graphiti editor and they are the same.
Thanks,
Alex
[Updated on: Thu, 07 May 2015 18:05] Report message to a moderator
|
|
| |
Re: Diagram does not update after model is changed [message #1694876 is a reply to message #1694811] |
Fri, 08 May 2015 15:49 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
Yes you are right, I am indeed still using different TEDs. I guess too much debugging took its toll
Here is my issue, in my wizard I create model and diagram model:
...
URI modelURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
Diagram diagram = Graphiti.getPeCreateService().createDiagram("ChannelDiagramType", diagramName, true);
IFile diagramFile = ((IFolder)iwresourceFolder).getFile(diagramName + "." + WorkspaceUtil.inline_channel_diagram_extension); //$NON-NLS-1$
URI diagramURI = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
final TransactionalEditingDomain editingDomain = GraphitiUiInternal.getEmfService().createResourceSetAndEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
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);
for(EObject modelRoot : modelRoots) {
modelResource.getContents().add(modelRoot);
}
diagramResource.getContents().add(diagram);
try {
modelResource.save(Collections.EMPTY_MAP);
diagramResource.save(Collections.EMPTY_MAP);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
});
....
This works, however when my editor class that extends DiagramEditor opens it calls DiagramEditor's init(IEditorSite site, IEditorInput input) method which in turn creates TED again:
diagramBehavior.getUpdateBehavior().createEditingDomain(diagramEditorInput);
This is why I think in the end I have two different TEDs. I can't really change behavior of init() method because diagramBehavior is private. Any suggestions on how to keep TEDs in sync here?
I created a Singleton that mimic EmfService.createResourceSetAndEditingDomain() method which allows me to set TED in wizard during model creation. I implemented my own DIagramBehavior and DefaultUpdateBehavior to use this Singelton to get, and as in case of DefaultUpdateBehavior create TED. Doesn't fully work yes as side effects of this change is sudden appearance of DocumentRoot in my TreeViewer, creation of which I suppress in ResourceFactoryImpl, so I am not too sure what happened there. Regardless, does this sound like an acceptable approach to keep TED same through out my transactions, or am I missing some simple solution?
Edit: My Singleton was giving all sorts of weird issues, so I went with implementing org.eclipse.emf.transaction.editingDomains extension point which seems to work better.
Alex
[Updated on: Mon, 11 May 2015 18:09] Report message to a moderator
|
|
|
Re: Diagram does not update after model is changed [message #1695381 is a reply to message #1694876] |
Wed, 13 May 2015 21:17 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
After trying to use editing domain extension point it also turned out to be fruitless. So I tried to go a different route and create model resource in wizard and set up diagram model in the editor. In order to share editing domain created by Graphiti I have the following code:
@Override
public void init(IEditorSite site, IEditorInput editorInput) {
// TODO Auto-generated method stub
diagramEditor = new ChannelDiagramEditor();
IFile inputFile = ((FileEditorInput)editorInput).getFile();
IFile file = inputFile.getParent().getFile(new Path(inputFile.getName().substring(0,inputFile.getName().lastIndexOf(".")) + "." + WorkspaceUtil.inline_channel_diagram_extension));
diagramEditor.setInputFile(file);
input = new FileEditorInput(file);
try {
diagramEditor.init(site, input);
editingDomain = diagramEditor.getEditingDomain();
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.init(site, editorInput);
}
@Override
protected void addPages() {
try {
if (getEditorInput() instanceof MigrateChannelEditorInput) {
addPage(new ChannelMigrationPage(this));
setActivePage(0);
} else {
initializeDescriptors();
validator = new ChannelValidator(this);
//decorator = new ChannelTreeViewerDecorator2(validator);
masterDetailsPage = new ChannelMasterDetailsPage(this);
addPage(masterDetailsPage);
setActivePage(0);
}
/*diagramEditor = new ChannelDiagramEditor();
IFile inputFile = getInputFile();
IFile file = inputFile.getParent().getFile(new Path(inputFile.getName().substring(0,inputFile.getName().lastIndexOf(".")) + "." + WorkspaceUtil.inline_channel_diagram_extension));
diagramEditor.setInputFile(file);
FileEditorInput input = new FileEditorInput(file);*/
addPage(1, diagramEditor, input);
setPageText(1, "Design");
} catch (PartInitException e) {
ChannelEditorPlugin.getDefault().logError(e.getLocalizedMessage(), e);
}
}
The idea here is that during call to init() I created DiagramEditor which in turn sets up editingDomain (protected variable in base class) and then that editing domain is set in base class of my editor (TreeViewer). This works, however addPages() method initialized DiagramEditor again and thus another editingDomain is created and earlier created files are attempted to be written again. I am not sure what to do here. In my MultiEditor I must have TreeViewer tab first and Diagram tab second, so I must pre-create editing domain. I know about FIleService class with method createEmfFileForDiagram(), but this method does not preset UpdateBehavior with editingDomain that it creates. I of course can create my own UpdateBehavior, but it still leaves me with init() method being called twice.
|
|
|
Goto Forum:
Current Time: Tue Mar 19 13:28:58 GMT 2024
Powered by FUDForum. Page generated in 0.02477 seconds
|