1 17 package org.eclipse.emf.mapping.command; 18 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 23 import org.eclipse.emf.common.command.Command; 24 import org.eclipse.emf.common.command.CompoundCommand; 25 import org.eclipse.emf.edit.command.AddCommand; 26 import org.eclipse.emf.edit.command.CopyCommand; 27 import org.eclipse.emf.edit.command.CreateCopyCommand; 28 import org.eclipse.emf.edit.command.PasteFromClipboardCommand; 29 import org.eclipse.emf.mapping.domain.MappingDomain; 30 31 32 35 public class PasteFromClipboardOverrideCommand extends PasteFromClipboardCommand 36 { 37 public PasteFromClipboardOverrideCommand(MappingDomain domain, PasteFromClipboardCommand command) 38 { 39 super(domain, command.getOwner(), command.getFeature(), command.getIndex(), domain.getOptimizeCopy()); 40 } 41 42 protected boolean optimizedCanExecute() 43 { 44 Collection collection = domain.getClipboard(); 45 if (collection == null) 46 { 47 return false; 48 } 49 50 CopyCommand.Helper copyHelper = new CopyCommand.Helper(); 55 CompoundCommand shallowCopyCommand = new CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL); 56 for (Iterator objects = collection.iterator(); objects.hasNext(); ) 57 { 58 if (!shallowCopyCommand.appendAndExecute(CreateCopyCommand.create(domain, objects.next(), copyHelper))) 59 { 60 shallowCopyCommand.dispose(); 61 return false; 62 } 63 } 64 65 Command addCommand = AddCommand.create(domain, owner, feature, shallowCopyCommand.getResult()); 66 boolean result = addCommand.canExecute(); 67 68 shallowCopyCommand.dispose(); 69 addCommand.dispose(); 70 71 return result; 72 } 73 74 } 75 | Popular Tags |