@Override
 public boolean canExecute() {
   boolean canExecute = true;
   if (getCreationTool() != null) {
     if (getCreationTool().getFirstModelOperation() == null) {
       canExecute = false;
     } else {
       if (getCreationTool().getPrecondition() != null
           && !StringUtil.isEmpty(getCreationTool().getPrecondition().trim())) {
         IInterpreter interpreter = null;
         try {
           if (getTreeItem() != null) {
             interpreter = InterpreterUtil.getInterpreter(getTreeItem().getTarget());
             interpreter.setVariable(
                 IInterpreterSiriusVariables.ROOT, TreeHelper.getTree(getTreeItem()).getTarget());
             interpreter.setVariable(
                 IInterpreterSiriusVariables.ELEMENT, getTreeItem().getTarget());
             interpreter.setVariable(
                 IInterpreterSiriusVariables.CONTAINER,
                 ((DTreeItemContainer) getTreeItem().eContainer()).getTarget());
             canExecute =
                 interpreter.evaluateBoolean(
                     getTreeItem().getTarget(), getCreationTool().getPrecondition());
           } else {
             interpreter = InterpreterUtil.getInterpreter(getTable().getTarget());
             interpreter.setVariable(IInterpreterSiriusVariables.ROOT, getTable().getTarget());
             interpreter.setVariable(IInterpreterSiriusVariables.ELEMENT, getTable().getTarget());
             interpreter.setVariable(IInterpreterSiriusVariables.CONTAINER, null);
             canExecute =
                 interpreter.evaluateBoolean(
                     getTable().getTarget(), getCreationTool().getPrecondition());
           }
         } catch (final EvaluationException e) {
           RuntimeLoggerManager.INSTANCE.error(
               getCreationTool(),
               ToolPackage.eINSTANCE.getAbstractToolDescription_Precondition(),
               e);
         }
         interpreter.unSetVariable(IInterpreterSiriusVariables.ROOT);
         interpreter.unSetVariable(IInterpreterSiriusVariables.ELEMENT);
         interpreter.unSetVariable(IInterpreterSiriusVariables.CONTAINER);
       }
     }
   }
   return canExecute;
 }
 private static InitInterpreterVariablesTask buildVariablesInitializationTask(
     ReorderTool reorderTool,
     EObject event,
     EventEnd startingEndPredecessor,
     EventEnd finishingEndPredecessor) {
   Map<AbstractVariable, Object> variables = Maps.newHashMap();
   variables.put(reorderTool.getStartingEndPredecessorAfter(), startingEndPredecessor);
   variables.put(reorderTool.getFinishingEndPredecessorAfter(), finishingEndPredecessor);
   return new InitInterpreterVariablesTask(variables, InterpreterUtil.getInterpreter(event), null);
 }
 private static InitInterpreterVariablesTask buildVariablesInitializationTask(
     InstanceRoleReorderTool reorderTool,
     EObject element,
     EObject predecessorBefore,
     EObject predecessorAfter) {
   Map<AbstractVariable, Object> variables = Maps.newHashMap();
   variables.put(reorderTool.getPredecessorBefore(), predecessorBefore);
   variables.put(reorderTool.getPredecessorAfter(), predecessorAfter);
   return new InitInterpreterVariablesTask(
       variables, InterpreterUtil.getInterpreter(element), null);
 }
 /**
  * @param semantic The semantic root of the diagram
  * @return The new diagram name
  * @throws InterruptedException If the user pressed cancel
  */
 private String askDiagramName(final EObject semantic) throws InterruptedException {
   final IInterpreter interpreter = InterpreterUtil.getInterpreter(semantic);
   String theName = new IdentifiedElementQuery(this.description).getLabel();
   if (!StringUtil.isEmpty(this.description.getTitleExpression())) {
     try {
       theName = interpreter.evaluateString(semantic, this.description.getTitleExpression());
     } catch (final EvaluationException e) {
       RuntimeLoggerManager.INSTANCE.error(
           this.description,
           DescriptionPackage.eINSTANCE.getRepresentationDescription_TitleExpression(),
           e);
     }
   }
   if (uiCallBack != null) {
     theName = uiCallBack.askForDetailName(theName, this.description.getEndUserDocumentation());
   }
   return theName;
 }
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.sirius.tools.internal.command.builders.CommandBuilder#buildCommand()
   */
  @Override
  public Command buildCommand() {

    Command result = UnexecutableCommand.INSTANCE;

    if (permissionAuthority.canEditInstance(reconnectionSource)
        && permissionAuthority.canEditInstance(reconnectionTarget)
        && permissionAuthority.canEditInstance(edge)
        // Layouting mode on diagrams
        // if the ddiagram is in LayoutingMode, we do not allow reconnection
        && !isInLayoutingModeDiagram(edge)) {

      final EObject semanticSource =
          SiriusUtil.getNearestDecorateSemanticElement(reconnectionSource).getTarget();
      final EObject semanticTarget =
          SiriusUtil.getNearestDecorateSemanticElement(reconnectionTarget).getTarget();

      final Map<AbstractVariable, Object> variables = new HashMap<AbstractVariable, Object>();
      variables.put(tool.getElement(), edge.getTarget());
      variables.put(tool.getSource(), semanticSource);
      variables.put(tool.getSourceView(), reconnectionSource);
      variables.put(tool.getTarget(), semanticTarget);
      variables.put(tool.getTargetView(), reconnectionTarget);
      variables.put(tool.getEdgeView(), edge);

      // we create an hidden variable that will be used to
      // correct reconnection issues
      ICommandTask createOtherEndVariableTask = getOtherEndVariableCreationTask(variables);

      final DCommand cmd = createEnclosingCommand();
      cmd.getTasks().add(createOtherEndVariableTask);
      cmd.getTasks()
          .add(
              new InitInterpreterVariablesTask(
                  variables, InterpreterUtil.getInterpreter(reconnectionSource), uiCallback));
      Option<DDiagram> parentDiagram = getDDiagram();
      if (tool.getInitialOperation() != null
          && tool.getInitialOperation().getFirstModelOperations() != null) {
        cmd.getTasks()
            .add(
                taskHelper.buildTaskFromModelOperation(
                    parentDiagram.get(),
                    edge.getTarget(),
                    tool.getInitialOperation().getFirstModelOperations()));
      }
      final SetObject setObject = ToolFactory.eINSTANCE.createSetObject();
      final String featureName = getReconnectionKindFeatureName();
      setObject.setFeatureName(featureName);
      setObject.setObject(reconnectionTarget);

      Option<DRepresentation> representation = new EObjectQuery(edge).getRepresentation();
      final CommandContext edgeContext = new CommandContext(edge, representation.get());
      cmd.getTasks()
          .add(
              new SetValueTask(
                  edgeContext,
                  this.modelAccessor,
                  setObject,
                  new EObjectQuery(edge).getSession().getInterpreter()));

      final EdgeMapping newEdgeMapping = getEdgeMappingReconnector();
      addRefreshTask(edge, cmd, tool);
      final CompoundCommand cc = new CompoundCommand();
      if (newEdgeMapping != null && !newEdgeMapping.equals(edge.getActualMapping())) {
        cc.append(new SetEdgeActualMappingCommand(editingDomain, edge, newEdgeMapping));
      }
      if (reconnectionSource.equals(oldSource)
          && (newEdgeMapping != null && !newEdgeMapping.isUseDomainElement()
              || isEdgeActualMappingUsingDomainElement())) {
        cc.append(
            new ReconnectSourceNodeCommand(
                editingDomain, edge, reconnectionTarget, semanticTarget));
      }
      cc.append(cmd);
      result = cc;
    }
    return result;
  }
 public EObject debugContext(EObject context) {
   IInterpreter interpreter = InterpreterUtil.getInterpreter(context);
   System.out.println(interpreter.getVariables().keySet());
   return context;
 }