|
|
@@ -10,6 +10,7 @@
|
|
|
*/
|
|
|
package org.yakindu.sct.ui.editor.commands;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.eclipse.core.commands.ExecutionException;
|
|
|
@@ -23,8 +24,10 @@ import org.eclipse.gmf.runtime.common.ui.action.actions.global.ClipboardManager;
|
|
|
import org.eclipse.gmf.runtime.common.ui.util.CustomData;
|
|
|
import org.eclipse.gmf.runtime.common.ui.util.CustomDataTransfer;
|
|
|
import org.eclipse.gmf.runtime.common.ui.util.ICustomData;
|
|
|
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
|
|
|
import org.eclipse.gmf.runtime.emf.clipboard.core.ClipboardUtil;
|
|
|
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
|
|
|
+import org.eclipse.gmf.runtime.notation.View;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -38,10 +41,10 @@ public class SemanticCopyCommand extends AbstractTransactionalCommand {
|
|
|
// TODO
|
|
|
public static final String DRAWING_SURFACE = "Drawing Surface";
|
|
|
|
|
|
- private final List<EObject> selectedObjects;
|
|
|
+ private final List<IGraphicalEditPart> selectedObjects;
|
|
|
|
|
|
public SemanticCopyCommand(TransactionalEditingDomain domain,
|
|
|
- List<EObject> selectedObjects) {
|
|
|
+ List<IGraphicalEditPart> selectedObjects) {
|
|
|
super(domain, COPY, null);
|
|
|
this.selectedObjects = selectedObjects;
|
|
|
}
|
|
|
@@ -49,18 +52,40 @@ public class SemanticCopyCommand extends AbstractTransactionalCommand {
|
|
|
@Override
|
|
|
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
|
|
|
IAdaptable info) throws ExecutionException {
|
|
|
- String clipString = ClipboardUtil.copyElementsToString(
|
|
|
- getSelectedObjects(), null, new NullProgressMonitor());
|
|
|
+ String semanticString = ClipboardUtil.copyElementsToString(
|
|
|
+ getSemanticElements(), null, new NullProgressMonitor());
|
|
|
+ String notationString = ClipboardUtil.copyElementsToString(
|
|
|
+ getNotationElements(), null, new NullProgressMonitor());
|
|
|
|
|
|
- CustomData data = new CustomData(DRAWING_SURFACE, clipString.getBytes());
|
|
|
- ClipboardManager.getInstance().addToCache(new ICustomData[] { data },
|
|
|
- CustomDataTransfer.getInstance());
|
|
|
+ CustomData semanticData = new CustomData(DRAWING_SURFACE,
|
|
|
+ semanticString.getBytes());
|
|
|
+ CustomData notationData = new CustomData(DRAWING_SURFACE,
|
|
|
+ notationString.getBytes());
|
|
|
|
|
|
+ ClipboardManager.getInstance().addToCache(
|
|
|
+ new ICustomData[] { notationData, semanticData },
|
|
|
+ CustomDataTransfer.getInstance());
|
|
|
+
|
|
|
+ ClipboardManager.getInstance().flushCacheToClipboard();
|
|
|
+
|
|
|
return CommandResult.newOKCommandResult();
|
|
|
}
|
|
|
|
|
|
- private List<EObject> getSelectedObjects() {
|
|
|
- return selectedObjects;
|
|
|
+ protected List<EObject> getSemanticElements() {
|
|
|
+ List<EObject> result = new ArrayList<EObject>();
|
|
|
+ for (IGraphicalEditPart editPart : selectedObjects) {
|
|
|
+ EObject resolveSemanticElement = editPart.resolveSemanticElement();
|
|
|
+ result.add(resolveSemanticElement);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
+ protected List<View> getNotationElements() {
|
|
|
+ List<View> result = new ArrayList<View>();
|
|
|
+ for (IGraphicalEditPart editPart : selectedObjects) {
|
|
|
+ View view = editPart.getNotationView();
|
|
|
+ result.add(view);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|