use of org.eclipse.core.expressions.IEvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testAdaptExpressionWithNull.
/**
* Bug 484325
*/
public void testAdaptExpressionWithNull() throws Exception {
// it's surprisingly difficult to craft an EvaluationContext that
// provides
// a defaultVariable == null
IEvaluationContext testContext = new EvaluationContext(null, new Adaptee());
testContext.addVariable("nullCarrier", Arrays.asList((Object) null, (Object) null, (Object) null));
WithExpression withExpression = new WithExpression("nullCarrier");
IterateExpression iterateExpression = new IterateExpression("and");
iterateExpression.add(new AdaptExpression("org.eclipse.core.internal.expressions.tests.NotExisting"));
withExpression.add(iterateExpression);
EvaluationResult result = withExpression.evaluate(testContext);
assertTrue(result == EvaluationResult.FALSE);
}
use of org.eclipse.core.expressions.IEvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionWithAdapterManager.
public void testIterateExpressionWithAdapterManager() throws Exception {
final List<Object> result = new ArrayList<>();
Expression myExpression = new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
result.add(context.getDefaultVariable());
return EvaluationResult.FALSE;
}
};
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("or");
exp.add(myExpression);
final List<String> input = new ArrayList<>();
// $NON-NLS-1$
input.add("one");
// $NON-NLS-1$
input.add("two");
CollectionWrapper wrapper = new CollectionWrapper();
wrapper.collection = input;
EvaluationContext context = new EvaluationContext(null, wrapper);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
assertTrue(result.equals(input));
}
use of org.eclipse.core.expressions.IEvaluationContext in project polymap4-core by Polymap4.
the class CommonWizardDescriptor method isEnabledFor.
/**
* Determine if this content extension is enabled for the given selection.
* The content extension 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;
}
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.FALSE) {
return false;
}
}
return true;
}
use of org.eclipse.core.expressions.IEvaluationContext in project polymap4-core by Polymap4.
the class NavigatorPlugin method getEmptyEvalContext.
/**
* @return an evaluation context
*/
public static IEvaluationContext getEmptyEvalContext() {
IEvaluationContext c = new EvaluationContext(getApplicationContext(), Collections.EMPTY_LIST);
c.setAllowPluginActivation(true);
return c;
}
use of org.eclipse.core.expressions.IEvaluationContext in project netxms by netxms.
the class ToggleAlarmFilterHandler method execute.
/* (non-Javadoc)
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Object object = event.getApplicationContext();
if (object instanceof IEvaluationContext) {
// $NON-NLS-1$
Object tab = ((IEvaluationContext) object).getVariable("org.netxms.ui.eclipse.objectview.ActiveTab");
if ((tab != null) && (tab instanceof AlarmTab)) {
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
// $NON-NLS-1$
Command command = service.getCommand("org.netxms.ui.eclipse.alarmviewer.commands.show_filter_alarm_list");
// $NON-NLS-1$
State state = command.getState("org.netxms.ui.eclipse.alarmviewer.commands.show_filter_alarm_list.state");
boolean isChecked = !(Boolean) state.getValue();
state.setValue(isChecked);
((AlarmTab) tab).setFilterEnabled(isChecked);
service.refreshElements(event.getCommand().getId(), null);
}
}
return null;
}
Aggregations