use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.text by eclipse.
the class GenericContentTypeRelatedExtension method matches.
/**
* Returns true if the given viewer, editor matches the enabledWhen expression
* and false otherwise.
*
* @param viewer the viewer
* @param editor the editor
* @return true if the given viewer, editor matches the enabledWhen expression
* and false otherwise.
*/
public boolean matches(ISourceViewer viewer, ITextEditor editor) {
if (enabledWhen == null) {
return true;
}
EvaluationContext context = new EvaluationContext(null, editor);
context.setAllowPluginActivation(true);
// $NON-NLS-1$
context.addVariable("viewer", viewer);
// $NON-NLS-1$
context.addVariable("editor", editor);
// $NON-NLS-1$
context.addVariable("editorInput", editor.getEditorInput());
try {
return enabledWhen.evaluate(context) == EvaluationResult.TRUE;
} catch (CoreException e) {
GenericEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, "Error while 'enabledWhen' evaluation", // $NON-NLS-1$
e));
return false;
}
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.text by eclipse.
the class AbstractTextZoomHandlerTest method assertZoomSupported.
private void assertZoomSupported(Object receiver, boolean expectedEnabled) {
TextZoomInHandler textZoomHandler = new TextZoomInHandler();
EvaluationContext evaluationContext = new EvaluationContext(null, new Object());
evaluationContext.addVariable(ISources.ACTIVE_EDITOR_NAME, receiver);
textZoomHandler.setEnabled(evaluationContext);
boolean actualEnabled = textZoomHandler.isEnabled();
assertEquals(expectedEnabled, actualEnabled);
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse-integration-commons by spring-projects.
the class MultiPageDashboardEditor method createDiscoveryWizardEvaluationContext.
/**
* Copied from TasksUiInternal to avoid initialization of
* org.eclipse.mylyn.tasks.ui.
*/
private static EvaluationContext createDiscoveryWizardEvaluationContext(IHandlerService handlerService) {
EvaluationContext evaluationContext = new EvaluationContext(handlerService.getCurrentState(), Platform.class);
// must specify this variable otherwise the PlatformPropertyTester won't
// work
// $NON-NLS-1$
evaluationContext.addVariable("platform", Platform.class);
return evaluationContext;
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse-integration-commons by spring-projects.
the class MultiPageDashboardEditor method getConfiguredDiscoveryWizardCommand.
/**
* Copied from TasksUiInternal to avoid initialization of
* org.eclipse.mylyn.tasks.ui.
*/
private static Command getConfiguredDiscoveryWizardCommand() {
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
final Command discoveryWizardCommand = service.getCommand(// $NON-NLS-1$
"org.eclipse.mylyn.discovery.ui.discoveryWizardCommand");
if (discoveryWizardCommand != null) {
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
EvaluationContext evaluationContext = createDiscoveryWizardEvaluationContext(handlerService);
// update enabled state in case something has changed (ProxyHandler
// caches state)
discoveryWizardCommand.setEnabled(evaluationContext);
}
return discoveryWizardCommand;
}
use of org.eclipse.core.expressions.EvaluationContext in project liferay-ide by liferay.
the class ProjectExplorerLayoutUtil method setNested.
public static void setNested(boolean nested) {
String commandId = "org.eclipse.ui.navigator.resources.nested.changeProjectPresentation";
try {
IWorkbench workbench = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
Command command = commandService.getCommand(commandId);
IHandler hanlder = command.getHandler();
IViewPart projectExplorer = workbench.getWorkbenchWindows()[0].getActivePage().findView(IPageLayout.ID_PROJECT_EXPLORER);
if ((hanlder != null) && (projectExplorer != null)) {
Map<String, String> map = new HashMap<>();
map.put(_nestParameter, Boolean.toString(nested));
IEvaluationContext applicationContext = new EvaluationContext(null, new Object());
applicationContext.addVariable(ISources.ACTIVE_PART_NAME, projectExplorer);
ExecutionEvent event = new ExecutionEvent(command, map, null, applicationContext);
_execute(event);
}
} catch (ExecutionException ee) {
// ignore errors this is best effort.
}
}
Aggregations