1 17 package org.eclipse.emf.edit.command; 18 19 20 import java.util.Collection ; 21 import java.util.Collections ; 22 23 import org.eclipse.emf.common.command.Command; 24 import org.eclipse.emf.common.command.AbstractCommand; 25 import org.eclipse.emf.edit.EMFEditPlugin; 26 import org.eclipse.emf.edit.domain.EditingDomain; 27 28 29 33 public class CopyToClipboardCommand extends AbstractOverrideableCommand implements AbstractCommand.NonDirtying 34 { 35 38 public static Command create(EditingDomain domain, final Collection collection) 39 { 40 if (domain == null) 41 { 42 CopyToClipboardCommand command = new CopyToClipboardCommand(domain, collection); 43 return command; 44 } 45 else 46 { 47 Command command = domain.createCommand(CopyToClipboardCommand.class, new CommandParameter(null, null, collection)); 48 return command; 49 } 50 } 51 52 55 protected static final String LABEL = EMFEditPlugin.INSTANCE.getString("_UI_CopyToClipboardCommand_label"); 56 57 60 protected static final String DESCRIPTION = EMFEditPlugin.INSTANCE.getString("_UI_CopyToClipboardCommand_description"); 61 62 65 public CopyToClipboardCommand(EditingDomain domain, Collection collection) 66 { 67 super (domain, LABEL, DESCRIPTION); 68 69 this.sourceObjects = collection; 70 } 71 72 75 protected Collection sourceObjects; 76 77 80 protected Collection oldClipboard; 81 82 85 protected Command copyCommand; 86 87 90 public static Command create(EditingDomain domain, Object owner) 91 { 92 return create(domain, Collections.singleton(owner)); 93 } 94 95 98 public Collection getSourceObjects() 99 { 100 return sourceObjects; 101 } 102 103 protected boolean prepare() 104 { 105 copyCommand = CopyCommand.create(domain, sourceObjects); 106 return copyCommand.canExecute(); 107 } 108 109 public void doExecute() 110 { 111 copyCommand.execute(); 112 113 oldClipboard = domain.getClipboard(); 114 domain.setClipboard(copyCommand.getResult()); 115 } 116 117 public void doUndo() 118 { 119 copyCommand.undo(); 120 121 domain.setClipboard(oldClipboard); 122 } 123 124 public void doRedo() 125 { 126 copyCommand.redo(); 127 128 oldClipboard = domain.getClipboard(); 129 domain.setClipboard(copyCommand.getResult()); 130 } 131 132 public Collection doGetResult() 133 { 134 return copyCommand.getResult(); 135 } 136 137 public Collection doGetAffectedObjects() 138 { 139 return copyCommand.getAffectedObjects(); 140 } 141 142 public void doDispose() 143 { 144 if (copyCommand != null) copyCommand.dispose(); 145 } 146 147 151 public String toString() 152 { 153 StringBuffer result = new StringBuffer (super.toString()); 154 result.append(" (domain: " + domain + ")"); 155 result.append(" (sourceObjects: " + sourceObjects + ")"); 156 result.append(" (oldClipboard: " + oldClipboard + ")"); 157 158 return result.toString(); 159 } 160 } 161 | Popular Tags |