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