Search in sources :

Example 46 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project liferay-ide by liferay.

the class UIUtil method executeCommand.

public static void executeCommand(String commandId, ISelection selection, Map<String, Object> parameters) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
    IEvaluationContext evaluationContext = new EvaluationContext(null, Collections.emptyList());
    evaluationContext.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
    IWorkbench workbench = PlatformUI.getWorkbench();
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    Command migrate = commandService.getCommand(commandId);
    IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
    if (parameters != null) {
        parameters.keySet().stream().forEach(parma -> evaluationContext.addVariable(parma, parameters.get(parma)));
    }
    handlerService.executeCommandInContext(ParameterizedCommand.generateCommand(migrate, null), null, evaluationContext);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 47 with EvaluationContext

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

the class NavigatorPlugin method getEvalContext.

/**
 * @param selection
 * @return an evaluation context
 */
public static IEvaluationContext getEvalContext(Object selection) {
    IEvaluationContext c = new EvaluationContext(getApplicationContext(), selection);
    c.setAllowPluginActivation(true);
    return c;
}
Also used : IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 48 with EvaluationContext

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

the class CommonActionProviderDescriptor method isEnabledFor.

/**
 * Determine if this action provider descriptor is enabled for the given selection.
 * The action provider descriptor is enabled for the selection if and only if it is
 * enabled for each element in the selection.
 *
 * @param aStructuredSelection
 *            The selection from the viewer
 * @return True if and only if the extension is enabled for each element in
 *         the selection.
 */
public boolean isEnabledFor(IStructuredSelection aStructuredSelection) {
    if (enablement == null) {
        return false;
    }
    if (aStructuredSelection.isEmpty()) {
        IEvaluationContext context = null;
        context = NavigatorPlugin.getEmptyEvalContext();
        if (NavigatorPlugin.safeEvaluate(enablement, context) != EvaluationResult.TRUE) {
            return false;
        }
    } else {
        IEvaluationContext context = null;
        IEvaluationContext parentContext = NavigatorPlugin.getApplicationContext();
        Iterator elements = aStructuredSelection.iterator();
        while (elements.hasNext()) {
            context = new EvaluationContext(parentContext, elements.next());
            context.setAllowPluginActivation(true);
            if (NavigatorPlugin.safeEvaluate(enablement, context) != EvaluationResult.TRUE) {
                return false;
            }
        }
    }
    return true;
}
Also used : IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) Iterator(java.util.Iterator) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 49 with EvaluationContext

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

the class ExpressionTests method testCountExpressionNone.

public void testCountExpressionNone() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("!");
    List<String> list = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    // $NON-NLS-1$
    list.add("two");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) CountExpression(org.eclipse.core.internal.expressions.CountExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 50 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext 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)

Aggregations

EvaluationContext (org.eclipse.core.expressions.EvaluationContext)71 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)56 ArrayList (java.util.ArrayList)26 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)22 CountExpression (org.eclipse.core.internal.expressions.CountExpression)14 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)13 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)12 Command (org.eclipse.core.commands.Command)11 WithExpression (org.eclipse.core.internal.expressions.WithExpression)11 ICommandService (org.eclipse.ui.commands.ICommandService)11 EvaluationResult (org.eclipse.core.expressions.EvaluationResult)10 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)10 CoreException (org.eclipse.core.runtime.CoreException)10 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)9 TestExpression (org.eclipse.core.internal.expressions.TestExpression)9 IHandlerService (org.eclipse.ui.handlers.IHandlerService)9 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)8 Expression (org.eclipse.core.expressions.Expression)8 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)8 AndExpression (org.eclipse.core.internal.expressions.AndExpression)7