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);
}
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;
}
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;
}
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));
}
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());
}
}
Aggregations