blob: eb42b83f8ee26aaf5bf900501f0df2861362e6fd (
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
|
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.j2ee.internal.command;
import java.util.Iterator;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.command.CopyToClipboardCommand;
import org.eclipse.wst.common.internal.emf.utilities.EtoolsCopyUtility;
public class J2EECopyToClipboardOverrideCommand extends CopyToClipboardCommand {
//The collection of source objects, with bindings and extensions, if any exist
protected J2EEClipboard extendedSourceObjects;
protected boolean onlyRefObjects = true;
public J2EECopyToClipboardOverrideCommand(CopyToClipboardCommand cmd) {
super(cmd.getDomain(), cmd.getSourceObjects());
}
protected Command createCopyCommand() {
CompoundCommand cmd = new J2EECompoundCommand(CompoundCommand.MERGE_COMMAND_ALL);
Iterator it = extendedSourceObjects.iterator();
EtoolsCopyUtility copyUtil = new EtoolsCopyUtility();
while (it.hasNext()) {
Object o = it.next();
if (!(o instanceof EObject)) {
cmd.append(UnexecutableCommand.INSTANCE);
} else {
EObject r = (EObject) o;
cmd.append(new J2EECopyCommand(r, extendedSourceObjects.getBinding(r), extendedSourceObjects.getExtension(r), copyUtil));
}
}
return cmd.unwrap();
}
protected boolean prepare() {
prepareSourceObjects();
if (!onlyRefObjects) {
copyCommand = UnexecutableCommand.INSTANCE;
return copyCommand.canExecute();
}
if (!extendedSourceObjects.hasBindings() && !extendedSourceObjects.hasExtensions())
return super.prepare();
copyCommand = createCopyCommand();
return copyCommand.canExecute();
}
protected void prepareSourceObjects() {
extendedSourceObjects = new J2EEClipboard(getSourceObjects());
Iterator it = getSourceObjects().iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof EObject) {
// EObject r = (EObject) o;
// TODO switch to adaptable commands
// EObject bnd = BindingAndExtensionHelper.getBinding(r);
// EObject ext = BindingAndExtensionHelper.getExtension(r);
// if (bnd != null)
// extendedSourceObjects.addBinding(r, bnd);
// if (ext != null)
// extendedSourceObjects.addExtension(r, ext);
} else {
//Right now we can only handle ref objects in the tree
onlyRefObjects = false;
return;
}
}
}
}
|