Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Load Diagram from File in RCP
Load Diagram from File in RCP [message #709989] Thu, 04 August 2011 15:05 Go to next message
Christian B is currently offline Christian BFriend
Messages: 68
Registered: August 2011

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 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg ReichertFriend
Messages: 80
Registered: July 2009
Location: Leipzig

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) {

			protected void doExecute() {
				for(EObject modelRoot : modelRoots) {
				try {;;
				} catch(IOException ioe) {
		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)

PictogramLink link = PictogramsFactory.eINSTANCE.createPictogramLink();

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.


Need professional support for Xtext and EMF?
Go to:
Re: Load Diagram from File in RCP [message #713918 is a reply to message #709989] Tue, 09 August 2011 11:37 Go to previous messageGo to next message
Christian B is currently offline Christian BFriend
Messages: 68
Registered: August 2011
Hi thx for the help!

The way I interpret your code is that a new domain model file and a new diagram file are created in the method createEmfFileForDiagram and i can populate them with default business objects on startup. Am I right? If yes, i will use this method to create a new Diagram, but i also need a method to load an existing domain model file and an existing diagram file and open it in the editor.

Do I need to care about editing domain etc. or is the following code sufficient for loading the diagram file?

editorInput = new FileEditorInput(diagramFile);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);

Re: Load Diagram from File in RCP [message #714016 is a reply to message #713918] Tue, 09 August 2011 15:43 Go to previous message
David Huber is currently offline David HuberFriend
Messages: 1
Registered: August 2011
Junior Member
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);


[Updated on: Wed, 10 August 2011 07:51]

Report message to a moderator

Previous Topic:link from container and child shape to the same object?
Next Topic:Validation for DirectEditFeatures
Goto Forum:

Current Time: Thu Dec 03 23:11:25 GMT 2020

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

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

Back to the top