Search in sources :

Example 6 with EvaluationResult

use of org.eclipse.core.expressions.EvaluationResult in project polymap4-core by Polymap4.

the class CustomAndExpression method evaluate.

public EvaluationResult evaluate(IEvaluationContext scope) {
    if (fExpressions == null) {
        return EvaluationResult.TRUE;
    }
    NavigatorPlugin.Evaluator evaluator = new NavigatorPlugin.Evaluator();
    EvaluationResult result = EvaluationResult.TRUE;
    for (Iterator iter = fExpressions.iterator(); iter.hasNext(); ) {
        Expression expression = (Expression) iter.next();
        evaluator.expression = expression;
        evaluator.scope = scope;
        SafeRunner.run(evaluator);
        result = result.and(evaluator.result);
        // that we find a false which will result in a better result.
        if (result == EvaluationResult.FALSE) {
            return result;
        }
    }
    return result;
}
Also used : Expression(org.eclipse.core.expressions.Expression) Iterator(java.util.Iterator) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 7 with EvaluationResult

use of org.eclipse.core.expressions.EvaluationResult in project hale by halestudio.

the class ActionUIWizardPage method acceptWizard.

/**
 * @see ViewerWizardSelectionPage#acceptWizard(IWizardNode)
 */
@Override
protected String acceptWizard(IWizardNode wizardNode) {
    if (wizardNode instanceof ActionUIWizardNode) {
        ActionUI actionUI = ((ActionUIWizardNode) wizardNode).getActionUI();
        Expression enabledWhen = actionUI.getEnabledWhen();
        if (enabledWhen == null) {
            return null;
        }
        IEvaluationService ies = PlatformUI.getWorkbench().getService(IEvaluationService.class);
        try {
            EvaluationResult evalResult = enabledWhen.evaluate(ies.getCurrentState());
            if (evalResult == EvaluationResult.FALSE) {
                // disabled
                return actionUI.getDisabledReason();
            }
            // enabled
            return null;
        } catch (CoreException e) {
            String message = "Could not evaluate enabledWhen expression";
            log.error(message, e);
            return message;
        }
    }
    return super.acceptWizard(wizardNode);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) Expression(org.eclipse.core.expressions.Expression) ActionUI(eu.esdihumboldt.hale.ui.io.action.ActionUI) IEvaluationService(org.eclipse.ui.services.IEvaluationService) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 8 with EvaluationResult

use of org.eclipse.core.expressions.EvaluationResult in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionFailure.

public void testCountExpressionFailure() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("!");
    EvaluationContext context = new EvaluationContext(null, new Object());
    try {
        EvaluationResult result = exp.evaluate(context);
        fail("Count should've failed for non-Collection variable.  Result = " + result.toString());
    } catch (CoreException e) {
        assertEquals(ExpressionStatus.VARIABLE_IS_NOT_A_COLLECTION, e.getStatus().getCode());
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CountExpression(org.eclipse.core.internal.expressions.CountExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 9 with EvaluationResult

use of org.eclipse.core.expressions.EvaluationResult in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testAdaptExpressionFail2.

public void testAdaptExpressionFail2() throws Exception {
    // $NON-NLS-1$
    AdaptExpression expression = new AdaptExpression("org.eclipse.core.internal.expressions.tests.Adapter");
    // $NON-NLS-1$
    expression.add(new InstanceofExpression("org.eclipse.core.internal.expressions.tests.NotExisting"));
    EvaluationResult result = expression.evaluate(new EvaluationContext(null, new Adaptee()));
    assertTrue(result == EvaluationResult.FALSE);
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 10 with EvaluationResult

use of org.eclipse.core.expressions.EvaluationResult in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testSystemProperty.

public void testSystemProperty() throws Exception {
    // $NON-NLS-1$ //$NON-NLS-2$
    SystemTestExpression expression = new SystemTestExpression("os.name", System.getProperty("os.name"));
    EvaluationResult result = expression.evaluate(new EvaluationContext(null, new Object()));
    assertTrue(result == EvaluationResult.TRUE);
}
Also used : SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Aggregations

EvaluationResult (org.eclipse.core.expressions.EvaluationResult)14 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)10 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)8 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)5 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)3 CoreException (org.eclipse.core.runtime.CoreException)3 Expression (org.eclipse.core.expressions.Expression)2 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)2 TestExpression (org.eclipse.core.internal.expressions.TestExpression)2 ActionUI (eu.esdihumboldt.hale.ui.io.action.ActionUI)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CountExpression (org.eclipse.core.internal.expressions.CountExpression)1 Property (org.eclipse.core.internal.expressions.Property)1 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)1 WithExpression (org.eclipse.core.internal.expressions.WithExpression)1 IEvaluationService (org.eclipse.ui.services.IEvaluationService)1 Bundle (org.osgi.framework.Bundle)1