KickJava   Java API By Example, From Geeks To Geeks.

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


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: DragAndDropOverrideCommand.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.Iterator JavaDoc;
21
22 import org.eclipse.emf.common.command.Command;
23 import org.eclipse.emf.common.command.CompoundCommand;
24 import org.eclipse.emf.edit.command.AddCommand;
25 import org.eclipse.emf.edit.command.CopyCommand;
26 import org.eclipse.emf.edit.command.CreateCopyCommand;
27 import org.eclipse.emf.edit.command.DragAndDropCommand;
28 import org.eclipse.emf.mapping.domain.MappingDomain;
29
30
31 /**
32  * This command overrides the PasteFromClipboardCommand for cross-domain (optimized) copies.
33  */

34 public class DragAndDropOverrideCommand extends DragAndDropCommand
35 {
36   public DragAndDropOverrideCommand(MappingDomain domain, DragAndDropCommand command)
37   {
38     super(domain, command.getOwner(), command.getLocation(), command.getOperations(), command.getOperation(), command.getCollection(), domain.getOptimizeCopy());
39   }
40
41   protected boolean optimizedCanExecute()
42   {
43     if (collection == null)
44     {
45       return false;
46     }
47
48     // We'll try adding a shallow copy of the clipboard contents, instead of a full copy.
49
// Note: we can't just try adding the clipboard contents itself, because the copy may be a
50
// different type then what's on the clipboard (e.g. EJB Field -> RDB Column).
51
//
52
CopyCommand.Helper copyHelper = new CopyCommand.Helper();
53     CompoundCommand shallowCopyCommand = new CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL);
54     for (Iterator JavaDoc objects = collection.iterator(); objects.hasNext(); )
55     {
56       if (!shallowCopyCommand.appendAndExecute(CreateCopyCommand.create(domain, objects.next(), copyHelper)))
57       {
58         shallowCopyCommand.dispose();
59         return false;
60       }
61     }
62
63     Command addCommand = AddCommand.create(domain, owner, null, shallowCopyCommand.getResult());
64     boolean result = addCommand.canExecute();
65
66     shallowCopyCommand.dispose();
67     addCommand.dispose();
68
69     return result;
70   }
71
72 }
73
Popular Tags