/** * This creates a command to insert particular value at a particular index in the specified feature of the owner. * The feature will often be null because the domain will deduce it. */ public static Command create(EditingDomain domain, Object owner, Object feature, Object value, int index) { return create(domain, owner, feature, Collections.singleton(value), index); }
/** * This creates a command to add a particular value to the specified feature of the owner. * The feature will often be null because the domain will deduce it. */ public static Command create(EditingDomain domain, Object owner, Object feature, Object value) { return create(domain, owner, feature, Collections.singleton(value), CommandParameter.NO_INDEX); }
@Override protected void doAdd(EObject container, EStructuralFeature feature, Collection<? extends Object> elements) throws ModelManipulationException { Command addCommand = AddCommand.create(domain, container, feature, elements); executeCommand(addCommand); }
@Override protected void doAdd(EObject container, EStructuralFeature feature, Object element, int index) throws ModelManipulationException { Command addCommand = AddCommand.create(domain, container, feature, element, index); executeCommand(addCommand); }
@Override protected void doAdd(EObject container, EStructuralFeature feature, Collection<? extends Object> elements) throws ModelManipulationException { Command createCommand = AddCommand.create(domain, container, feature, elements); executeCommand(createCommand); }
@Override protected Command createCommand() { original = domain.getClipboard(); copy = new ArrayList<Object>(copyCommand.getResult()); // Use the original to do the add, but only if it's of the same type as the copy. // This ensures that if there is conversion being done as part of the copy, // as would be the case for a cross domain copy in the mapping framework, // that we do actually use the converted instance. // if (original.size() == copy.size()) { for (Iterator<Object> i = original.iterator(), j = copy.iterator(); i.hasNext(); ) { Object originalObject = i.next(); Object copyObject = j.next(); if (originalObject.getClass() != copyObject.getClass()) { original = null; break; } } } Command addCommand = AddCommand.create(domain, owner, feature, original == null ? copy : original, index); return addCommand; }
@Override protected Command doCreateCommand(GenBase selectedObject) { return AddCommand.create(getEditingDomain(), selectedObject, GenModelPackage.Literals.GEN_ANNOTATION__DETAILS, EcoreUtil.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY)); } };
@Override protected EObject doCreate(EObject container, EReference reference, EClass clazz) throws ModelManipulationException { EObject obj = EcoreUtil.create(clazz); Command createCommand = AddCommand.create(domain, container, reference, obj); executeCommand(createCommand); return obj; }
@Override protected EObject doCreate(Resource res, EClass clazz) throws ModelManipulationException { EObject obj = EcoreUtil.create(clazz); Command createCommand = AddCommand.create(domain, res, null, res.getContents()); executeCommand(createCommand); return obj; }
/** * This creates the add command that will implement this action and specifies the collection by * delegating to {@link CreateChildCommand.Helper#getCreateChildImage}. */ protected Command createCommand() { if (feature == null) { return AddCommand.create(domain, owner, null, helper.createChild(owner)); } return new AddCommand(domain, owner, feature, helper.createChild(owner)); }
@Override protected Command doCreateCommand(GenBase selectedObject) { return AddCommand.create(getEditingDomain(), selectedObject, GenModelPackage.Literals.GEN_BASE__GEN_ANNOTATIONS, selectedObject.getGenModel().createGenAnnotation()); } };
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, feature, domain.getClipboard()); boolean result = addCommand.canExecute(); addCommand.dispose(); return result; }
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; }
@Override protected EObject doCreate(EObject container, EReference reference, EClass clazz) throws ModelManipulationException { EObject obj = EcoreUtil.create(clazz); Command command; if(reference.isMany()) { command = AddCommand.create(domain, container, reference, obj); } else { command = SetCommand.create(domain, container, reference, obj); } executeCommand(command); return obj; }
/** * This creates the wrapped {@link AddCommand} or {@link SetCommand} that * adds the child object to the model. If the owner, feature, or child * is <code>null</code>, or if the feature is single-valued and has * already been set to an object, {@link UnexecutableCommand#INSTANCE} * will be returned. */ @Override protected Command createCommand() { if (owner == null || feature == null || child == null) { return UnexecutableCommand.INSTANCE; } if (feature.isMany()) { return AddCommand.create(domain, owner, feature, child, index); } else if (owner.eGet(feature) == null) { return SetCommand.create(domain, owner, feature, child); } else { return UnexecutableCommand.INSTANCE; } }
protected Command createCommand() { Command addCommand = AddCommand.create(getDomain(), getOwner(), getFeature(), copyCommand.getResult(), getIndex()); return addCommand; } });
/** * 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; }
@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; }
/** * Return an AddCommand that will be executed by a CommandStack. */ protected Command createAddCommand(ModifierHelper aHelper) { Object value = getValue(aHelper); Command command = null; if (valueChanged(aHelper.getOwner(), aHelper.getFeature(), value, false)) { command = AddCommand.create(getEditingDomain(), aHelper.getOwner(), aHelper.getFeature(), value); ((AbstractCommand) command).setLabel(createCommandLabel(ADD_PATTERN, aHelper.getFeature())); setStatus(VALUE_CHANGE); } else { setStatus(NO_VALUE_CHANGE); } return command; }
@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; }