Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 5581decf71dff4747da24681e621aa6c41b99ed6 (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
90
91
92
93
94
95
96
/*******************************************************************************
 * 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.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jst.j2ee.internal.provider.J2EEUIEditingDomain;
import org.eclipse.wst.common.internal.emf.utilities.CopyGroup;
import org.eclipse.wst.common.internal.emf.utilities.EtoolsCopyUtility;


/**
 * Insert the type's description here. Creation date: (06/11/01 8:45:21 AM)
 * 
 * @author: Administrator
 */
public class J2EECopyFromClipboardCommand extends AbstractCommand {
	private J2EEUIEditingDomain domain;
	private J2EEClipboard result;
	private EtoolsCopyUtility copyUtil;

	public J2EECopyFromClipboardCommand(J2EEUIEditingDomain editingDomain) {
		domain = editingDomain;

	}

	/**
	 * This will perform the command activity required for the effect. The effect of calling execute
	 * when canExecute returns false, or when canExecute hasn't been called, is undefined.
	 */
	public void execute() {
		if (copyUtil != null)
			return;
		copyUtil = new EtoolsCopyUtility();
		J2EEClipboard clipboard = domain.getJ2EEClipboard();
		result = new J2EEClipboard(new ArrayList(0));
		for (int i = 0; i < clipboard.size(); i++) {
			CopyGroup group = new CopyGroup();
			EObject o = (EObject) clipboard.get(i);
			group.add(o);
			EObject bnd = clipboard.getBinding(o);
			if (bnd != null)
				group.add(bnd);
			EObject ext = clipboard.getExtension(o);
			if (ext != null)
				group.add(ext);
			copyUtil.copy(group);
			EObject copy = copyUtil.getCopy(o);
			result.add(copy);
			if (bnd != null)
				result.addBinding(copy, copyUtil.getCopy(bnd));
			if (ext != null)
				result.addExtension(copy, copyUtil.getCopy(ext));
		}
		//Reset the util so redo will actuall redo
		copyUtil = null;
	}

	public Collection getAffectedObjects() {
		return result;
	}

	public Collection getResult() {
		return result;
	}

	protected boolean prepare() {
		return true;
	}

	/**
	 * This will again perform the command activity required to redo the effect after undoing the
	 * effect. The effect, if any, of calling redo before undo is called is undefined. Note that if
	 * you implement redo to call execute then any derived class will be restricted to by that
	 * decision also.
	 */
	public void redo() {
		execute();
	}

	public void undo() {
		result = null;
	}
}

Back to the top