Search in sources :

Example 41 with EvaluationContext

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;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 42 with EvaluationContext

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);
}
Also used : TextZoomInHandler(org.eclipse.ui.texteditor.TextZoomInHandler) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 43 with EvaluationContext

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;
}
Also used : EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 44 with 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;
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 45 with EvaluationContext

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.
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) HashMap(java.util.HashMap) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ICommandService(org.eclipse.ui.commands.ICommandService) IWorkbench(org.eclipse.ui.IWorkbench) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IHandler(org.eclipse.core.commands.IHandler) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) ExecutionException(org.eclipse.core.commands.ExecutionException)

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