Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » change EMF model programmatically after loading from file(what kind of command to use?)
change EMF model programmatically after loading from file [message #1241003] Fri, 07 February 2014 10:27 Go to next message
Jan Mazak is currently offline Jan MazakFriend
Messages: 1
Registered: February 2014
Junior Member
I have a generated GMF editor. My aim is to save the diagram file location in a property of my root model object. I am doing it after the DocumentProvider loads the file by a call to DiagramIOUtil.load(). .The following way works:

	protected void setDocumentContent(IDocument document, IEditorInput element)
			throws CoreException {
		IDiagramDocument diagramDocument = (IDiagramDocument) document;
		TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
		if (element instanceof FileEditorInput) {
			final IStorage storage = ((FileEditorInput) element).getStorage();
			Diagram diagram = DiagramIOUtil.load(domain, storage, true,	getProgressMonitor());
                   OpenDAFDiagram dg = (OpenDAFDiagram) diagram.getElement();
                   Command cmd = SetCommand.create(domain, dg,
                		   OpendafPackage.eINSTANCE.getOpenDAFDiagram_Path(),
                		   storage.getFullPath().toOSString());
                   domain.getCommandStack().execute(cmd);
			document.setContent(diagram);
		}



However, this breaks the editor: it never gets dirty (e.g. when adding elements) and when saving the diagram file under another name, the new save does not contain the diagram element(s):
<?xml version="1.0" encoding="UTF-8"?>
<notation:Diagram xmi:version="2.0" xmlns:xmi="..." xmlns:xsi="..." xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" type="Opendaf" name="default.mxd" measurementUnit="Pixel">
  <children xsi:type="notation:Shape" type="2010" fontName="Sans">
    <children xsi:type="notation:DecorationNode" type="5010"/>
    <element href="default.mxd#_EMudwI9CEeOd0ZQmWSMfrQ"/>
    <layoutConstraint xsi:type="notation:Bounds" x="204" y="132"/>
  </children>
  <styles xsi:type="notation:DiagramStyle"/>
  <element href="default.mxd#_qWVHgI9BEeOTNNzP4umS5w"/>
</notation:Diagram>

instead of
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="..." xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:opendaf="...">
  <opendaf:OpenDAFDiagram xmi:id="_qWVHgI9BEeOTNNzP4umS5w" name="" path="">
    <elements xmi:type="opendaf:InputCommand" xmi:id="_EMudwI9CEeOd0ZQmWSMfrQ" name="ic2">
      <outputPorts xmi:type="opendaf:OutputPort" xmi:id="_EMudwY9CEeOd0ZQmWSMfrQ" element="_EMudwI9CEeOd0ZQmWSMfrQ"/>
    </elements>
  </opendaf:OpenDAFDiagram>
  <notation:Diagram xmi:id="_qW69YI9BEeOTNNzP4umS5w" type="Opendaf" element="_qWVHgI9BEeOTNNzP4umS5w" name="default.mxd" measurementUnit="Pixel">
    <children xmi:type="notation:Shape" xmi:id="_ENNl8I9CEeOd0ZQmWSMfrQ" type="2010" element="_EMudwI9CEeOd0ZQmWSMfrQ" fontName="Sans">
      <children xmi:type="notation:DecorationNode" xmi:id="_ENPbII9CEeOd0ZQmWSMfrQ" type="5010"/>
      <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ENNl8Y9CEeOd0ZQmWSMfrQ" x="216" y="96"/>
    </children>
    <styles xmi:type="notation:DiagramStyle" xmi:id="_qW7kcI9BEeOTNNzP4umS5w"/>
  </notation:Diagram>
</xmi:XMI>

What is the right way to do direct model changes?
(I had to remove some links from xmls because of odd forum restrictions.)
Re: change EMF model programmatically after loading from file [message #1241198 is a reply to message #1241003] Fri, 07 February 2014 16:16 Go to previous message
Ralf Buschermoehle is currently offline Ralf BuschermoehleFriend
Messages: 8
Registered: August 2013
Junior Member
Hi,

I think you could change the ResourceHandler by overwriting

public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options)

and change & store the file.

HTH,

Ralf

[Updated on: Fri, 07 February 2014 16:17]

Report message to a moderator

Previous Topic:Disable actions in GMF editor
Next Topic:Loading Model takes forever
Goto Forum:
  


Current Time: Tue Apr 23 17:30:00 GMT 2024

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

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

Back to the top