/** * Execute this modifier using the recording mechanism of the StructedTextUndoManager. If this * modifier cannot record, try to execute using the CommandStack (if it can execute commands). * Return true if the execution was attempted. * * @see canExecuteCommand() * @see canRecord() * @see run() */ public boolean execute(ModifierHelper aHelper) { addHelper(aHelper); return execute(); }
/** * Return a Command that will be executed by a CommandStack. The default is to return null. * Subclasses should override this method. */ public Command createCommand() { Command chainedCommand = createCommand(null, getHelpers()); if (null == chainedCommand && additionalCommands != null && additionalCommands.isEmpty()) { setStatus(ERROR); return null; } chainedCommand = appendAdditionalCommands(chainedCommand); return chainedCommand; }
/** * Execute this modifier by creating a Command that is executed on the CommandStack. If this * modifier cannot execute commands, the execution will not take place. Return true if the * execution was attempted. * * @see canExecuteCommand() */ public boolean execute() { boolean result = false; if (canExecuteCommand()) { try { Command command = createCommand(); result = command != null; if (result) { getCommandStack().execute(command); } } finally { release(); } } else { setStatus(ERROR); } return result; }
protected Object createValueFromHelper(ModifierHelper aHelper) { EObject newObject = createObjectFromHelper(aHelper); setNewObjectAttributes(newObject, aHelper); return newObject; }
/** * Return a Remove Command that will be executed by a CommandStack. */ protected Command createRemoveCommand(ModifierHelper aHelper) { Object value = getValue(aHelper); Command command = null; EStructuralFeature feature = aHelper.getFeature(); if (valueChanged(aHelper.getOwner(), feature, value, true)) { if (isValueEqual(aHelper, value)) { command = RemoveCommand.create(getEditingDomain(), aHelper.getOwner(), feature, (Collection) value); } else { command = RemoveCommand.create(getEditingDomain(), aHelper.getOwner(), feature, value); } ((AbstractCommand) command).setLabel(createCommandLabel(REMOVE_PATTERN, feature)); setStatus(VALUE_CHANGE); } else { setStatus(NO_VALUE_CHANGE); } return command; }
protected Command doCreateCommand(ModifierHelper aHelper) { if (!aHelper.isComplete()) { setStatus(ERROR); return null; } Command command = null; if (aHelper.getFeature().isMany()) command = createManyCommand(aHelper); else command = createSingleCommand(aHelper); if (null != command) { List localHelpers = ModifierHelperRegistry.getInstance().getHelpers(aHelper); if (null != localHelpers) { extendedHelpers.addAll(localHelpers); } } return command; }
/** * Return a Command that will be executed by a CommandStack. The default is to return null. * Subclasses should override this method. */ protected Command createManyCommand(ModifierHelper aHelper) { if (aHelper.shouldUnsetValue()) return createRemoveCommand(aHelper); return createAddCommand(aHelper); }
/** * Return a Command that will be executed by a CommandStack. */ protected Command createCommand(ModifierHelper aHelper) { if (aHelper == null) return null; Command command1, command2; ModifierHelper ownerHelper = aHelper.getOwnerHelper(); if (aHelper.shouldUnsetValue() && ownerHelper != null) return null; //we are unsetting a value on an owner that does not exist so do not // create the owner command1 = createCommand(ownerHelper); command2 = primCreateCommand(aHelper); if (command1 != null) { if (command2 == null) command2 = command1; else command2 = command2.chain(command1); } return command2; }
protected Command createCommand(Command chainedCommand, List helpersArg) { if (null == extendedHelpers) { extendedHelpers = new ArrayList(); } if (!helpersArg.isEmpty()) { Iterator it = helpersArg.iterator(); Command nextCommand = null; while (it.hasNext()) { nextCommand = createCommand((ModifierHelper) it.next()); if (chainedCommand == null) chainedCommand = nextCommand; else if (nextCommand != null) chainedCommand = chainedCommand.chain(nextCommand); } } if (!extendedHelpers.isEmpty()) { List copy = new ArrayList(); copy.addAll(extendedHelpers); extendedHelpers.clear(); chainedCommand = createCommand(chainedCommand, copy); } return chainedCommand; }
/** * 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; }
/** * Return a SetCommand that will be executed by a CommandStack. */ protected Command createSingleCommand(ModifierHelper aHelper) { Object value = getValue(aHelper); Command command = null; if (valueChanged(aHelper.getOwner(), aHelper.getFeature(), value, aHelper.shouldUnsetValue())) { command = SetCommand.create(getEditingDomain(), aHelper.getOwner(), aHelper.getFeature(), value); ((AbstractCommand) command).setLabel(createCommandLabel(SET_PATTERN, aHelper.getFeature())); setStatus(VALUE_CHANGE); } else { setStatus(NO_VALUE_CHANGE); } return command; }