blob: 6a11fb2eafdf483f7168c8b2e8581f2f38505f28 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*****************************************************************************
* Copyright (c) 2014 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.AbstractOverrideableCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
/**
* Command that puts a list of object in the clipboard, and that copy them.
*/
public class DefaultCopyCommand extends AbstractOverrideableCommand implements NonDirtying {
/** list of objects to put in the clipboard */
private final Collection<Object> objectsToPutInClipboard;
public Collection<Object> getObjectsToPutInClipboard() {
return objectsToPutInClipboard;
}
/** old list of the clipboard, for undo */
private Collection<Object> oldClipboardContent;
/**
* Creates a new Command that set the new content of the clipboard
*
* @param domain
* editing domain for which the clipboard is set.
*/
public DefaultCopyCommand(EditingDomain domain, PapyrusClipboard papyrusClipboard, Collection<EObject> pObjectsToPutInClipboard) {
super(domain);
objectsToPutInClipboard = new ArrayList<Object>();
EcoreUtil.Copier copier = new EcoreUtil.Copier();
copier.copyAll(pObjectsToPutInClipboard);
copier.copyReferences();
papyrusClipboard.addAllInternalCopyInClipboard(copier);
objectsToPutInClipboard.add(copier.values());
}
/**
* {@inheritDoc}
*/
@Override
public void doExecute() {
oldClipboardContent = domain.getClipboard();
domain.setClipboard(objectsToPutInClipboard);
}
/**
* {@inheritDoc}
*/
@Override
public void doUndo() {
domain.setClipboard(oldClipboardContent);
}
/**
* {@inheritDoc}
*/
@Override
public void doRedo() {
domain.setClipboard(objectsToPutInClipboard);
}
/**
* {@inheritDoc}
*/
@Override
protected boolean prepare() {
return domain != null;
}
}
|