/** * 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(); }
EObject copyChild = copyHelper.getCopy((EObject)copyChildObject); if (copyChild != null)
public void execute() { // Get the corresponding type. // EClass outputType = (EClass)mappingDomain.getOutputMetaObject(owner.eClass()); if (outputType != null) { // Create the copy from this corresponding type. // copy = outputType.getEPackage().getEFactoryInstance().create(outputType); copyHelper.put(owner, copy); MappingRoot mappingRoot = mappingDomain.getMappingRoot(); if (mappingRoot.isInputObject(owner)) { // This is done to ensure that this new copy is treated as an output by the domain. // The CreateMappingCommand will rely on this setting. // MappedObjectState mappedObjectState = mappingRoot.getMappedObjectState(copy); if (mappedObjectState != null) { mappedObjectState.setOriginatingInput(owner); } } } }
for (EObject item : valueList) EObject target = copyHelper.getCopyTarget(item, copiedTargetRequired); if (target == null) break; // if one is null, they'll all be null if (reverseReference != null) EObject target = copyHelper.getCopyTarget((EObject) value, copiedTargetRequired); if (target != null)
EObject copyChild = copyHelper.getCopy((EObject)copyChildObject); if (copyChild != null)
Object entryValue = entry.getValue(); boolean copiedTargetRequired = reverseReference != null || reference.isContainment(); EObject target = copyHelper.getCopyTarget((EObject)entryValue, copiedTargetRequired); if (target != null)
if (copyHelper.decrementDeferredInitializationCount() == 0)
@Override protected boolean optimizedCanExecute() { Collection<?> collection = domain.getClipboard(); 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, feature, shallowCopyCommand.getResult()); boolean result = addCommand.canExecute(); shallowCopyCommand.dispose(); addCommand.dispose(); return result; }
@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 optimizedCanExecute() { Collection<?> collection = domain.getClipboard(); 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, feature, shallowCopyCommand.getResult()); boolean result = addCommand.canExecute(); shallowCopyCommand.dispose(); addCommand.dispose(); return result; }
@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; }
public void execute() { // Get the corresponding type. // EClass outputType = (EClass)mappingDomain.getOutputMetaObject(owner.eClass()); if (outputType != null) { // Create the copy from this corresponding type. // copy = outputType.getEPackage().getEFactoryInstance().create(outputType); copyHelper.put(owner, copy); MappingRoot mappingRoot = mappingDomain.getMappingRoot(); if (mappingRoot.isInputObject(owner)) { // This is done to ensure that this new copy is treated as an output by the domain. // The CreateMappingCommand will rely on this setting. // MappedObjectState mappedObjectState = mappingRoot.getMappedObjectState(copy); if (mappedObjectState != null) { mappedObjectState.setOriginatingInput(owner); } } } }
@Override public boolean prepare() { for (Iterator<EObject> copiedObjects = copyHelper.initializationIterator(); copiedObjects.hasNext(); ) { EObject object = copiedObjects.next(); Command initializeCopyCommand = InitializeCopyCommand.create(domain, object, copyHelper); // Record it for execution. // if (!this.appendIfCanExecute(initializeCopyCommand)) { return false; } copiedObjects.remove(); } return true; } };
@Override protected void copyReferences() { super.copyReferences(); EReference reference = EcorePackage.Literals.EREFERENCE__EOPPOSITE; EObject value = (EObject)owner.eGet(reference); if (value != null) { EObject target = copyHelper.getCopyTarget(value, true); if (target != null) { copy.eSet(reference, target); } } } };
public void redo() { copyHelper.put(owner, copy); }
/** * This creates and instance in the given domain and for the given owner */ public CopyCommand(EditingDomain domain, EObject owner, Helper copyHelper, boolean optimize) { super(LABEL, DESCRIPTION); this.resultIndex = 0; this.domain = domain; this.owner = owner; this.copyHelper = copyHelper; this.optimize = optimize; copyHelper.incrementDeferredInitializationCount(); }
public void redo() { copyHelper.put(owner, copy); }
@Override public void undo() { copyHelper.remove(owner); }
/** * Return the copy of the specified object if it has one. */ public EObject getCopy(EObject object) { return get(object); }
/** * This constructs an instance that will copy the attribute values of value to those of owner. */ public InitializeCopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper copyHelper) { super(domain, LABEL, DESCRIPTION); this.owner = owner; this.copy = copyHelper.getCopy(owner); this.copyHelper = copyHelper; }