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 38 public abstract class AbstractCommand implements Command 39 { 40 44 protected boolean isPrepared; 45 46 50 protected boolean isExecutable; 51 52 56 protected String description; 57 58 61 protected String label; 62 63 66 protected AbstractCommand() 67 { 68 } 69 70 74 protected AbstractCommand(String label) 75 { 76 this.label = label; 77 } 78 79 84 protected AbstractCommand(String label, String description) 85 { 86 this.label = label; 87 this.description = description; 88 } 89 90 97 protected boolean prepare() 98 { 99 return false; 100 } 101 102 109 public boolean canExecute() 110 { 111 if (!isPrepared) 112 { 113 isExecutable = prepare(); 114 isPrepared = true; 115 } 116 117 return isExecutable; 118 } 119 120 124 public boolean canUndo() 125 { 126 return true; 127 } 128 129 133 public void undo() 134 { 135 throw 136 new UnsupportedOperationException 137 (CommonPlugin.INSTANCE.getString 138 ("_EXC_Method_not_implemented", new String [] { this.getClass().getName() + ".undo()" })); 139 } 140 141 145 public Collection getResult() 146 { 147 return Collections.EMPTY_LIST; 148 } 149 150 154 public Collection getAffectedObjects() 155 { 156 return Collections.EMPTY_LIST; 157 } 158 159 162 public String getLabel() 163 { 164 return label == null ? CommonPlugin.INSTANCE.getString("_UI_AbstractCommand_label") : label; 165 } 166 167 171 public void setLabel(String label) 172 { 173 this.label = label; 174 } 175 176 179 public String getDescription() 180 { 181 return description == null ? CommonPlugin.INSTANCE.getString("_UI_AbstractCommand_description") : description; 182 } 183 184 188 public void setDescription(String description) 189 { 190 this.description = description; 191 } 192 193 199 public Command chain(Command command) 200 { 201 class ChainedCompoundCommand extends CompoundCommand 202 { 203 public ChainedCompoundCommand() 204 { 205 } 206 207 public Command chain(Command c) 208 { 209 append(c); 210 return this; 211 } 212 } 213 214 CompoundCommand result = new ChainedCompoundCommand(); 215 result.append(this); 216 result.append(command); 217 return result; 218 } 219 220 223 public void dispose() 224 { 225 } 226 227 232 public String toString() 233 { 234 String className = getClass().getName(); 235 int lastDotIndex = className.lastIndexOf('.'); 236 StringBuffer result = new StringBuffer (lastDotIndex == -1 ? className : className.substring(lastDotIndex + 1)); 237 result.append(" (label: " + label + ")"); 238 result.append(" (description: " + description + ")"); 239 result.append(" (isPrepared: " + isPrepared + ")"); 240 result.append(" (isExecutable: " + isExecutable + ")"); 241 242 return result.toString(); 243 } 244 245 248 public static interface NonDirtying 249 { 250 } 251 } 252 | Popular Tags |