Load Diagram from File in RCP [message #709989] |
Thu, 04 August 2011 11:05  |
Eclipse User |
|
|
|
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 11:06] by Moderator
|
|
|
Re: Load Diagram from File in RCP [message #710236 is a reply to message #709989] |
Thu, 04 August 2011 16:58   |
Eclipse User |
|
|
|
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
|
|
|
|
Re: Load Diagram from File in RCP [message #714016 is a reply to message #713918] |
Tue, 09 August 2011 11:43  |
Eclipse User |
|
|
|
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 03:51] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04017 seconds