1 17 package org.eclipse.emf.mapping.command; 18 19 20 import java.util.Iterator ; 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 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 CopyCommand.Helper copyHelper = new CopyCommand.Helper(); 53 CompoundCommand shallowCopyCommand = new CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL); 54 for (Iterator 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 |