@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; }
/** * {@inheritDoc} * * <p>Overridden to have END_BEFORE_VARIABLE in tool precondition expression. */ @Override protected boolean evaluatePrecondition( IInterpreter interpreter, EObject semanticContainer, String precondition) { interpreter.setVariable(END_BEFORE_VARIABLE, endBefore); boolean result = super.evaluatePrecondition(interpreter, semanticContainer, precondition); interpreter.unSetVariable(END_BEFORE_VARIABLE); return result; }