Load Diagram from File in RCP [message #709989] |
Thu, 04 August 2011 15:05 |
Christian B Messages: 68 Registered: August 2011 |
Member |
|
|
hi,
I intergrated the graphitor editor in my own RCP. On Start of the rcp i want to load a default diagram into the editor. With CreateDiagramWizard i was able to find out how to create a new diagram, but how to load one from a file?
thanks for your help!
[Updated on: Thu, 04 August 2011 15:06] Report message to a moderator
|
|
|
Re: Load Diagram from File in RCP [message #710236 is a reply to message #709989] |
Thu, 04 August 2011 20:58 |
Joerg Reichert Messages: 80 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hi,
you have to make your that your domain model files and your diagram file are in the same resource set.
public static TransactionalEditingDomain createEmfFileForDiagram(URI diagramResourceUri, URI modelResourceUri, final Diagram diagram, final EObject... modelRoots) {
final TransactionalEditingDomain editingDomain = DiagramEditorFactory.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();
}
}
});
return editingDomain;
}
With the TransactionalEditingDomain you create the editor input used to open the editor.
editorInput = new DiagramEditorInput(EcoreUtil.getURI(diagram), domain, providerId, true);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorId)
With
PictogramLink link = PictogramsFactory.eINSTANCE.createPictogramLink();
getDiagram().setLink(link);
link.getBusinessObjects().add(businessObject);
containerShape.setLink(link);
inside the add feature, pictogram elements are linked to domain objects.
If you want to add the figures for the existing domain objects automatically, have loke at this forum entry.
Regards,
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
Re: Load Diagram from File in RCP [message #714016 is a reply to message #713918] |
Tue, 09 August 2011 15:43 |
David Huber Messages: 1 Registered: August 2011 |
Junior Member |
|
|
Hi,
I managed to open a file using graphiti in an RCP application simply using:
URI uri = URI.createFileURI(pathToFile);
DiagramEditorFactory factory = new DiagramEditorFactory();
DiagramEditorInput input = factory.createEditorInput(new URIEditorInput(uri));
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, DiagramEditor.DIAGRAM_EDITOR_ID);
Regards
David
[Updated on: Wed, 10 August 2011 07:51] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02949 seconds