KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > command > CopyToClipboardOverrideCommand


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: CopyToClipboardOverrideCommand.java,v 1.2 2005/06/08 06:21:43 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.command;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.emf.common.command.IdentityCommand;
23 import org.eclipse.emf.edit.command.CopyCommand;
24 import org.eclipse.emf.edit.command.CopyToClipboardCommand;
25 import org.eclipse.emf.mapping.domain.MappingDomain;
26
27
28 /**
29  * This command overrides the CopyToClipboardCommand for cross-domain copies.
30  */

31 public class CopyToClipboardOverrideCommand extends CopyToClipboardCommand
32 {
33   /**
34    * This is the collection of read-only (input) objects that don't need to actually be copied.
35    */

36   protected Collection JavaDoc inputObjects;
37
38   /**
39    * This constructs a command that copies the given collections of objects to the clipboard.
40    */

41   public CopyToClipboardOverrideCommand(MappingDomain domain, Collection JavaDoc nonInputObjects, Collection JavaDoc inputObjects)
42   {
43     super(domain, nonInputObjects);
44
45     this.inputObjects = inputObjects;
46   }
47
48   protected boolean prepare()
49   {
50     // Since input objects are read-only, we don't need to make a copy of them for the clipboard.
51
// We can just put a pointer to the original object(s) on the clipboard.
52
//
53
copyCommand = new IdentityCommand(inputObjects);
54
55     // Do we also have some non-input objects to copy?
56
//
57
if (sourceObjects.size() > 0)
58     {
59       copyCommand = copyCommand.chain(CopyCommand.create(domain, sourceObjects));
60     }
61
62     return copyCommand.canExecute();
63   }
64
65 }
66
Popular Tags