/** * 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() { 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; }
/** * This creates a command that copies the given object. */ public static Command create(EditingDomain domain, Object owner) { return domain.createCommand(CopyCommand.class, new CommandParameter(owner, null, new Helper())); }