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
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 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg ReichertFriend
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 #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
Member
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
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

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


Current Time: Thu Apr 25 09:18:58 GMT 2024

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

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

Back to the top