1 17 package org.eclipse.emf.common.command; 18 19 20 import java.util.Collection ; 21 import java.util.Collections ; 22 23 import org.eclipse.emf.common.CommonPlugin; 24 25 26 61 public class CommandWrapper extends AbstractCommand 62 { 63 66 protected Command command; 67 68 72 public CommandWrapper(Command command) 73 { 74 super(command.getLabel(), command.getDescription()); 75 this.command = command; 76 } 77 78 83 protected CommandWrapper(String label, Command command) 84 { 85 super(label, command.getDescription()); 86 this.command = command; 87 } 88 89 95 public CommandWrapper(String label, String description, Command command) 96 { 97 super(label, description); 98 this.command = command; 99 } 100 101 106 protected CommandWrapper() 107 { 108 super(); 109 } 110 111 117 protected CommandWrapper(String label) 118 { 119 super(label); 120 } 121 122 129 protected CommandWrapper(String label, String description) 130 { 131 super(label, description); 132 } 133 134 139 public Command getCommand() 140 { 141 return command; 142 } 143 144 150 protected Command createCommand() 151 { 152 return null; 153 } 154 155 161 protected boolean prepare() 162 { 163 if (command == null) 164 { 165 command = createCommand(); 166 } 167 168 boolean result = command.canExecute(); 169 return result; 170 } 171 172 175 public void execute() 176 { 177 if (command != null) 178 { 179 command.execute(); 180 } 181 } 182 183 186 public boolean canUndo() 187 { 188 return command == null || command.canUndo(); 189 } 190 191 194 public void undo() 195 { 196 if (command != null) 197 { 198 command.undo(); 199 } 200 } 201 202 205 public void redo() 206 { 207 if (command != null) 208 { 209 command.redo(); 210 } 211 } 212 213 217 public Collection getResult() 218 { 219 return 220 command == null ? 221 Collections.EMPTY_LIST : 222 command.getResult(); 223 } 224 225 229 public Collection getAffectedObjects() 230 { 231 return 232 command == null ? 233 Collections.EMPTY_LIST : 234 command.getAffectedObjects(); 235 } 236 237 241 public String getLabel() 242 { 243 return 244 label == null ? 245 command == null ? 246 CommonPlugin.INSTANCE.getString("_UI_CommandWrapper_label") : 247 command.getLabel() : 248 label; 249 } 250 251 255 public String getDescription() 256 { 257 return 258 description == null ? 259 command == null ? 260 CommonPlugin.INSTANCE.getString("_UI_CommandWrapper_description") : 261 command.getDescription() : 262 description; 263 } 264 265 268 public void dispose() 269 { 270 if (command != null) 271 { 272 command.dispose(); 273 } 274 } 275 276 279 public String toString() 280 { 281 StringBuffer result = new StringBuffer (super.toString()); 282 result.append(" (command: " + command + ")"); 283 284 return result.toString(); 285 } 286 } 287 | Popular Tags |