/** * This creates a command that copies the given collection of objects. If the collection contains more than one object, * then a compound command will be created containing individual copy commands for each object. */ public static Command create(final EditingDomain domain, final Collection<?> collection) { if (collection == null || collection.isEmpty()) { return UnexecutableCommand.INSTANCE; } Helper copyHelper = new Helper(); CompoundCommand copyCommand = new CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL); for (Object object : collection) { copyCommand.append(domain.createCommand(CopyCommand.class, new CommandParameter(object, null, copyHelper))); } return copyCommand.unwrap(); }
@Override protected boolean optimizedCanExecute() { if (collection == null) { return false; } // We'll try adding a shallow copy of the clipboard contents, instead of a full copy. // Note: we can't just try adding the clipboard contents itself, because the copy may be a // different type then what's on the clipboard (e.g. EJB Field -> RDB Column). // CopyCommand.Helper copyHelper = new CopyCommand.Helper(); CompoundCommand shallowCopyCommand = new CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL); for (Object object : collection) { if (!shallowCopyCommand.appendAndExecute(CreateCopyCommand.create(domain, object, copyHelper))) { shallowCopyCommand.dispose(); return false; } } Command addCommand = AddCommand.create(domain, owner, null, shallowCopyCommand.getResult()); boolean result = addCommand.canExecute(); shallowCopyCommand.dispose(); addCommand.dispose(); return result; }
@Override protected boolean prepare() { prepareCommand(); return super.prepare(); }
protected Command createCopyCommand() { CompoundCommand cmd = new J2EECompoundCommand(CompoundCommand.MERGE_COMMAND_ALL); Iterator it = extendedSourceObjects.iterator(); EtoolsCopyUtility copyUtil = new EtoolsCopyUtility(); while (it.hasNext()) { Object o = it.next(); if (!(o instanceof EObject)) { cmd.append(UnexecutableCommand.INSTANCE); } else { EObject r = (EObject) o; cmd.append(new J2EECopyCommand(r, extendedSourceObjects.getBinding(r), extendedSourceObjects.getExtension(r), copyUtil)); } } return cmd.unwrap(); }
final List<Object> list = new ArrayList<Object>(commandParameter.getCollection()); CompoundCommand removeCommand = new CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL); removeCommand.append(createRemoveCommand(domain, eObject, feature, childrenOfThisFeature)); removeCommand.append (new CommandWrapper(setCommand) return removeCommand.unwrap(); removeCommand.dispose(); return UnexecutableCommand.INSTANCE;
public void execute() { // This will deal with all the subcommands to modifying the root mapping tree. // CompoundCommand subcommands = new CompoundCommand(); // For each mapping being removed... // for (Object object : collection) { Mapping mapping = (Mapping)object; Mapping parentMapping = mapping.getNestedIn(); // Make sure the back pointers to this mapping from the mapped objects is set. // domain.getMappingRoot().deregister(mapping); // Create a command to do parentMapping.getNested().remove(mapping). // //subcommands.appendAndExecute(new RemoveCommand(domain, parentMapping, parentMapping.ePackageMapping().getMapping_Nested(), mapping)); subcommands.appendAndExecute(new RemoveCommand(domain, parentMapping, MappingPackage.eINSTANCE.getMapping_Nested(), mapping)); Collection<Mapping> nestedMappings = new ArrayList<Mapping>(mapping.getNested()); if (!nestedMappings.isEmpty()) { //subcommands.appendAndExecute(new RemoveCommand(domain, mapping, mapping.ePackageMapping().getMapping_Nested(), nestedMappings)); //subcommands.appendAndExecute(new AddCommand(domain, parentMapping, parentMapping.ePackageMapping().getMapping_Nested(), nestedMappings)); subcommands.appendAndExecute(new RemoveCommand(domain, mapping, MappingPackage.eINSTANCE.getMapping_Nested(), nestedMappings)); subcommands.appendAndExecute(new AddCommand(domain, parentMapping, MappingPackage.eINSTANCE.getMapping_Nested(), nestedMappings)); } } subcommand = subcommands.unwrap(); }
public void execute() CompoundCommand subcommands = new CompoundCommand(); for (Object removal : removeCommand.getCollection()) subcommands.appendAndExecute(commands.previous()); mapCommand = !subcommands.isEmpty() ? subcommands.unwrap() : null; removeCommand.doExecute();
commands = new CompoundCommand(); Collection<Object> collectionOfDescendants = new HashSet<Object>(); for (Object object : mappedObjectsCollection) commands.appendIfCanExecute(command); commands.appendIfCanExecute(removeInputsCommand); commands.appendIfCanExecute(removeOutputsCommand); commands.execute();
CompoundCommand compoundCommand = new CompoundCommand(); List<Object> before = new ArrayList<Object>(); List<Object> after = new ArrayList<Object>(); compoundCommand.append(MoveCommand.create(domain, parent, null, object, index - 1)); compoundCommand.append(MoveCommand.create(domain, parent, null, object, index)); dropCommand = compoundCommand.getCommandList().size() == 0 ? (Command)IdentityCommand.INSTANCE : compoundCommand;
public void execute() { addCommand.doExecute(); MappingRoot mappingRoot = mappingDomain.getMappingRoot(); CompoundCommand subcommands = new CompoundCommand(); for (Object addition : addCommand.getCollection()) { for (Iterator<?> objects = mappingDomain.treeIterator(addition); objects.hasNext(); ) { Object object = objects.next(); MappedObjectState mappedObjectState = mappingRoot.getMappedObjectState(object); Object originatingInput = mappedObjectState.getOriginatingInput(); // This is tricky and is done for each object here rather than once for the owner of the addCommnd. // We want to make sure the object is really part of the conceptual tree induced by the domain. // if (originatingInput == null) { mappedObjectState.setOutput(); } else if (mappingRoot.isAttachedObject(object)) { mapOutputObject(object, originatingInput, subcommands); } } } mapCommand = !subcommands.isEmpty() ? subcommands.unwrap() : null; }
command.appendIfCanExecute (SetCommand.create(editingDomain, object, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS, Collections.EMPTY_LIST)); command.appendIfCanExecute (SetCommand.create(editingDomain, object, EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, null)); command.appendIfCanExecute (SetCommand.create(editingDomain, object, EcorePackage.Literals.EGENERIC_TYPE__EUPPER_BOUND, null)); command.appendIfCanExecute (SetCommand.create(editingDomain, object, EcorePackage.Literals.EGENERIC_TYPE__ELOWER_BOUND, null)); command.append (SetCommand.create(editingDomain, object, EcorePackage.Literals.EGENERIC_TYPE__ETYPE_PARAMETER, value)); editingDomain.getCommandStack().execute(command);
CompoundCommand compoundCommand = new CompoundCommand(CompoundCommand.LAST_COMMAND_ALL); EReference oldReferenceOpposite = eReference.getEOpposite(); if (oldReferenceOpposite != null) compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(oldReferenceOpposite), feature, null)); if (oldOppositeOpposite != null) compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(oldOppositeOpposite), feature, null)); compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(eOpposite), feature, eReference)); compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(eReference), feature, eOpposite)); editingDomain.getCommandStack().execute(compoundCommand);
/** * Creates a new compound command, containing this command and the given command, * that delegates chain to {@link CompoundCommand#append}. * @param command the command to chain with this one. * @return a new chained compound command. */ public Command chain(Command command) { class ChainedCompoundCommand extends CompoundCommand { public ChainedCompoundCommand() { super(); } @Override public Command chain(Command c) { append(c); return this; } } CompoundCommand result = new ChainedCompoundCommand(); result.append(this); result.append(command); return result; }
CompoundCommand createCommand = new CompoundCommand(0); append(createCommand.unwrap());
if (!oldValues.isEmpty()) CompoundCommand compoundCommand = new CompoundCommand(); for (EObject oldValueObject : oldValues) compoundCommand.appendIfCanExecute(new RemoveCommand(domain, oldValueObject, eOtherEnd, owner)); if (!newValues.isEmpty()) CompoundCommand compoundCommand = new CompoundCommand(); for (EObject newValueObject : newValues) compoundCommand.appendIfCanExecute(new SetCommand(domain, newValueObject, eOtherEnd, UNSET_VALUE)); EObject otherEObject = (EObject)newValueObject.eGet(eOtherEnd); if (otherEObject != null) compoundCommand.appendIfCanExecute (eOtherEnd.isChangeable() ? new SetCommand(domain, newValueObject, eOtherEnd, UNSET_VALUE) :
@Override public String toString() { StringBuffer result = new StringBuffer(super.toString()); result.append(" (isUndoable: " + isUndoable + ")"); result.append(" (isPessimistic: " + isPessimistic + ")"); result.append(" (rightMostExecutedCommandIndex: " + rightMostExecutedCommandIndex + ")"); return result.toString(); } }
/** * Calls {@link Command#redo} for each command in the list. * In the case that {@link #isPessimistic} is false, only the last command will be redone * since the others will have been executed and not undo during {@link #prepare}. */ @Override public void redo() { if (isPessimistic) { super.redo(); } else if (!commandList.isEmpty()) { Command command = commandList.get(commandList.size() - 1); command.redo(); } }
/** * Calls {@link Command#undo} for each command in the list. * In the case that {@link #isPessimistic} is false, only the last command will be undone * since the others will have been executed and not undo during {@link #prepare}. */ @Override public void undo() { if (isPessimistic) { super.undo(); } else if (!commandList.isEmpty()) { Command command = commandList.get(commandList.size() - 1); command.undo(); } }