protected boolean optimizedCanExecute() { // We'll assume that the copy command can execute and that adding a copy of the clipboard // is the same test as adding the clipboard contents itself. // Command addCommand = AddCommand.create(domain, owner, null, collection); boolean result = addCommand.canExecute() && !analyzeForNonContainment(addCommand); addCommand.dispose(); return result; }
/** * This attempts to prepare a drop link insert operation. */ protected boolean prepareDropLinkInsert(Object parent, Collection<?> children, int index) { boolean result; // We don't want to insert an object before or after itself... // if (collection.contains(owner)) { dragCommand = IdentityCommand.INSTANCE; dropCommand = UnexecutableCommand.INSTANCE; result = false; } else { dragCommand = IdentityCommand.INSTANCE; // Add the collection // dropCommand = AddCommand.create(domain, parent, null, collection, index); if (!analyzeForNonContainment(dropCommand)) { dropCommand.dispose(); dropCommand = UnexecutableCommand.INSTANCE; } result = dropCommand.canExecute(); } return result; }
protected boolean analyzeForNonContainment(Command command) { if (command instanceof AddCommand) { return isNonContainment(((AddCommand)command).getFeature()); } else if (command instanceof SetCommand) { return isNonContainment(((SetCommand)command).getFeature()); } else if (command instanceof CommandWrapper) { return analyzeForNonContainment(((CommandWrapper)command).getCommand()); } else if (command instanceof CompoundCommand) { for (Command childCommand : ((CompoundCommand)command).getCommandList()) { if (analyzeForNonContainment(childCommand)) { return true; } } } return false; }
/** * This attempts to prepare a drop link on operation. */ protected boolean prepareDropLinkOn() { dragCommand = IdentityCommand.INSTANCE; dropCommand = SetCommand.create(domain, owner, null, collection); // If we can't set the collection, try setting use the single value of the collection. // if (!dropCommand.canExecute() && collection.size() == 1) { dropCommand.dispose(); dropCommand = SetCommand.create(domain, owner, null, collection.iterator().next()); } if (!dropCommand.canExecute() || !analyzeForNonContainment(dropCommand)) { dropCommand.dispose(); dropCommand = AddCommand.create(domain, owner, null, collection); if (!analyzeForNonContainment(dropCommand)) { dropCommand.dispose(); dropCommand = UnexecutableCommand.INSTANCE; } } boolean result = dropCommand.canExecute(); return result; }
if (analyzeForNonContainment(dropCommand))
/** * This attempts to prepare a drop move on operation. */ protected boolean prepareDropMoveOn() { if (isCrossDomain()) { dragCommand = IdentityCommand.INSTANCE; dropCommand = UnexecutableCommand.INSTANCE; } else { dropCommand = AddCommand.create(domain, owner, null, collection); if (analyzeForNonContainment(dropCommand)) { dropCommand.dispose(); dropCommand = UnexecutableCommand.INSTANCE; dragCommand = IdentityCommand.INSTANCE; } else { dragCommand = RemoveCommand.create(domain, collection); } } boolean result = dragCommand.canExecute() && dropCommand.canExecute(); return result; }
if (analyzeForNonContainment(dropCommand))
isDragCommandExecuted = true; dropCommand = AddCommand.create(domain, owner, null, dragCommand.getResult()); if (analyzeForNonContainment(dropCommand))