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.CommandWrapper; 25 import org.eclipse.emf.edit.EMFEditPlugin; 26 import org.eclipse.emf.edit.domain.EditingDomain; 27 28 29 33 public class CutToClipboardCommand extends CommandWrapper 34 { 35 39 public static Command create(EditingDomain domain, Object value) 40 { 41 if (domain == null) 42 { 43 return new CutToClipboardCommand(domain, RemoveCommand.create(domain, value)); 44 } 45 else 46 { 47 return domain.createCommand(CutToClipboardCommand.class, new CommandParameter(null, null, Collections.singleton(value))); 48 } 49 } 50 51 55 public static Command create(EditingDomain domain, Object owner, Object feature, Object value) 56 { 57 if (domain == null) 58 { 59 return new CutToClipboardCommand(domain, RemoveCommand.create(domain, owner, feature, value)); 60 } 61 else 62 { 63 return domain.createCommand(CutToClipboardCommand.class, new CommandParameter(owner, feature, Collections.singleton(value))); 64 } 65 } 66 67 71 public static Command create(EditingDomain domain, Collection collection) 72 { 73 if (domain == null) 74 { 75 return new CutToClipboardCommand(domain, RemoveCommand.create(domain, collection)); 76 } 77 else 78 { 79 return domain.createCommand(CutToClipboardCommand.class, new CommandParameter(null, null, collection)); 80 } 81 } 82 83 87 public static Command create(EditingDomain domain, Object owner, Object feature, Collection collection) 88 { 89 if (domain == null) 90 { 91 return new CutToClipboardCommand(domain, RemoveCommand.create(domain, owner, feature, collection)); 92 } 93 else 94 { 95 return domain.createCommand(CutToClipboardCommand.class, new CommandParameter(owner, feature, collection)); 96 } 97 } 98 99 102 protected static final String LABEL = EMFEditPlugin.INSTANCE.getString("_UI_CutToClipboardCommand_label"); 103 104 107 protected static final String DESCRIPTION = EMFEditPlugin.INSTANCE.getString("_UI_CutToClipboardCommand_description"); 108 109 112 protected EditingDomain domain; 113 114 117 protected Collection oldClipboard; 118 119 122 public CutToClipboardCommand(EditingDomain domain, Command command) 123 { 124 super(LABEL, DESCRIPTION, command); 125 126 this.domain = domain; 127 } 128 129 public void execute() 130 { 131 super.execute(); 132 133 if (domain != null) 134 { 135 oldClipboard = domain.getClipboard(); 136 domain.setClipboard(command.getResult()); 137 } 138 } 139 140 public void undo() 141 { 142 super.undo(); 143 144 if (domain != null) 145 { 146 domain.setClipboard(oldClipboard); 147 } 148 } 149 150 public void redo() 151 { 152 super.redo(); 153 154 if (domain != null) 155 { 156 oldClipboard = domain.getClipboard(); 157 domain.setClipboard(command.getResult()); 158 } 159 } 160 161 165 public String toString() 166 { 167 StringBuffer result = new StringBuffer (super.toString()); 168 result.append(" (domain: " + domain + ")"); 169 result.append(" (oldClipboard: " + oldClipboard + ")"); 170 171 return result.toString(); 172 } 173 } 174 | Popular Tags |