Explorar el Código

SharedEditingDomain: If the editor is a subdiagram, set the dirty flag to true if the resourceset is dirty

Andreas Mülder hace 13 años
padre
commit
f95ee5f49d

+ 22 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/providers/DiagramPartitioningDocumentProvider.java

@@ -11,6 +11,7 @@
 package org.yakindu.sct.ui.editor.providers;
 
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.emf.transaction.util.TransactionUtil;
 import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
@@ -35,6 +36,27 @@ public class DiagramPartitioningDocumentProvider extends FileDiagramDocumentProv
 		return super.createInputWithEditingDomain(editorInput, domain);
 	}
 
+	@Override
+	protected ElementInfo createElementInfo(Object element) throws CoreException {
+		ElementInfo info = super.createElementInfo(element);
+		// If the editor is a subdiagram, set the dirty flag to true if the
+		// resourceset is dirty
+		if (element instanceof IDiagramEditorInput) {
+			Diagram diagram = ((IDiagramEditorInput) element).getDiagram();
+			info.fCanBeSaved = isDirty(TransactionUtil.getEditingDomain(diagram));
+		}
+		return info;
+	}
+
+	protected boolean isDirty(TransactionalEditingDomain domain) {
+		for (final Resource resource : domain.getResourceSet().getResources()) {
+			if (resource.isLoaded() && !domain.isReadOnly(resource) && resource.isModified()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	@Override
 	protected boolean setDocumentContent(IDocument document, IEditorInput editorInput) throws CoreException {
 		if (editorInput instanceof IDiagramEditorInput) {