Browse Source

#895: Copying subdiagrams within copied regions.

Thomas Kutz 9 years ago
parent
commit
223ad8c299

+ 6 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/clipboardsupport/NotationClipboardOperationHelper.java

@@ -130,7 +130,7 @@ public class NotationClipboardOperationHelper extends AbstractClipboardSupport {
 		if ((eReference.isTransient()) || (eReference.isDerived())) {
 			return false;
 		} else if (eReference.equals(NotationPackage.eINSTANCE
-				.getView_Element()) && !(context instanceof Diagram && value instanceof State)) {
+				.getView_Element()) && !isSubdiagram(context, value)) {
 			return true;
 		} else {
 			return eReference.isContainment();
@@ -161,7 +161,7 @@ public class NotationClipboardOperationHelper extends AbstractClipboardSupport {
 		// to allow paste into diagram elements
 		if ((parentEObject instanceof View) && (eObject instanceof View)) {
 			EObject semanticChildElement = ((View) eObject).getElement();
-			if (semanticChildElement == null) {
+			if (semanticChildElement == null || isSubdiagram(eObject, semanticChildElement)) {
 				return true;
 			}
 
@@ -213,6 +213,10 @@ public class NotationClipboardOperationHelper extends AbstractClipboardSupport {
 		return false;
 	}
 
+	private boolean isSubdiagram(EObject container, Object element) {
+		return (container instanceof Diagram) && (element instanceof State);
+	}
+
 	/**
 	 * By default, don't provide any child paste override behaviour.
 	 * 

+ 20 - 5
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/providers/SubdiagramAwareCopyCommand.java

@@ -25,7 +25,9 @@ import org.eclipse.gmf.runtime.emf.clipboard.core.ClipboardUtil;
 import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.Edge;
 import org.eclipse.gmf.runtime.notation.View;
+import org.yakindu.sct.model.sgraph.Region;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
 
 /**
@@ -131,17 +133,30 @@ public class SubdiagramAwareCopyCommand extends CopyCommand implements ICommand
 			View viewElement = (View) iter.next();
 			if (viewElement != null) {
 				EObject semanticElement = viewElement.getElement();
-				if (semanticElement != null && semanticElement instanceof State) {
-					State semanticState = (State) semanticElement;
-					if (semanticState.isComposite()) {
-						subDiagrams.addAll(getAllSubDiagrams(semanticState));
-					}
+				if (semanticElement instanceof State) {
+					collectSubdiagramsInState(subDiagrams, (State) semanticElement);
+				} else if (semanticElement instanceof Region) {
+					collectSubdiagramsInRegion(subDiagrams, (Region) semanticElement);
 				}
 			}
 		}
 		return subDiagrams;
 	}
 
+	protected void collectSubdiagramsInRegion(List<Diagram> subDiagrams, Region region) {
+		for (Vertex vertex : region.getVertices()) {
+			if (vertex instanceof State) {
+				collectSubdiagramsInState(subDiagrams, (State) vertex);
+			}
+		}
+	}
+
+	protected void collectSubdiagramsInState(List<Diagram> subDiagrams, State state) {
+		if (state.isComposite()) {
+			subDiagrams.addAll(getAllSubDiagrams(state));
+		}
+	}
+
 	protected Collection<? extends Diagram> getAllSubDiagrams(State semanticState) {
 		List<Diagram> subDiagrams = new ArrayList<>();
 		addSubDiagram(semanticState, subDiagrams);