Search in sources :

Example 6 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project linuxtools by eclipse.

the class VagrantToolBarContributionItem method execute.

private void execute(String id, IStructuredSelection selection) {
    ICommandService service = PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = service != null ? service.getCommand(id) : null;
    if (command != null && command.isDefined()) {
        try {
            ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(command, null);
            IHandlerService handlerSvc = PlatformUI.getWorkbench().getService(IHandlerService.class);
            IEvaluationContext ctx = handlerSvc.getCurrentState();
            ctx = new EvaluationContext(ctx, selection);
            ctx.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
            handlerSvc.executeCommandInContext(pCmd, null, ctx);
        } catch (Exception e) {
            Activator.log(e);
        }
    }
}
Also used : 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) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 7 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project linuxtools by eclipse.

the class CommandUtils method execute.

/**
 * Executes the command identified by the given {@code id} on a context
 * based on the given selection
 *
 * @param id
 *            the id of the command to execute
 * @param selection
 *            the selection to use as a context to run the command
 */
public static void execute(final String id, final IStructuredSelection selection) {
    final ICommandService service = PlatformUI.getWorkbench().getService(ICommandService.class);
    final Command command = service != null ? service.getCommand(id) : null;
    if (command != null && command.isDefined()) {
        try {
            ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(command, null);
            IHandlerService handlerSvc = PlatformUI.getWorkbench().getService(IHandlerService.class);
            IEvaluationContext ctx = handlerSvc.getCurrentState();
            ctx = new EvaluationContext(ctx, selection);
            ctx.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
            handlerSvc.executeCommandInContext(pCmd, null, ctx);
        } catch (Exception e) {
            Activator.log(e);
        }
    }
}
Also used : 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) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 8 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project tmdm-studio-se by Talend.

the class JumpToSourceLineHandler method setEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
     */
@Override
public void setEnabled(Object evaluationContext) {
    if (evaluationContext != null) {
        Object defaultVariable = null;
        if (evaluationContext instanceof ExpressionContext) {
            ExpressionContext exc = (ExpressionContext) evaluationContext;
            defaultVariable = exc.getDefaultVariable();
        } else if (evaluationContext instanceof EvaluationContext) {
            EvaluationContext context = (EvaluationContext) evaluationContext;
            defaultVariable = context.getDefaultVariable();
        }
        if (defaultVariable instanceof List) {
            selectedObjs = (List) defaultVariable;
        } else {
            selectedObjs = null;
        }
    }
}
Also used : ExpressionContext(org.eclipse.e4.core.commands.ExpressionContext) List(java.util.List) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 9 with EvaluationContext

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

the class MigrateProjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    EvaluationContext applicationContext = (EvaluationContext) event.getApplicationContext();
    _combineExistedProblem = (Boolean) applicationContext.getVariable("CombineExistedProblem");
    if (selection instanceof IStructuredSelection) {
        Object element = null;
        if (((IStructuredSelection) selection).size() > 1) {
            element = ((IStructuredSelection) selection).toArray();
        } else {
            element = ((IStructuredSelection) selection).getFirstElement();
        }
        IProject project = null;
        IProject[] projects = null;
        if (element instanceof IProject) {
            project = (IProject) element;
        } else if (element instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) element;
            project = adaptable.getAdapter(IProject.class);
        } else if (element instanceof Object[]) {
            projects = Arrays.copyOf((Object[]) element, ((Object[]) element).length, IProject[].class);
        }
        if (project != null) {
            MarkerUtil.clearMarkers(project, MigrationConstants.MARKER_TYPE, null);
            _setButtonState(false);
            final IPath location = project.getLocation();
            findMigrationProblems(new IPath[] { location }, new String[] { project.getName() });
        } else if (projects != null) {
            final List<IPath> locations = new ArrayList<>();
            final List<String> projectNames = new ArrayList<>();
            for (IProject iProject : projects) {
                MarkerUtil.clearMarkers(iProject, MigrationConstants.MARKER_TYPE, null);
                locations.add(iProject.getLocation());
                projectNames.add(iProject.getName());
            }
            _setButtonState(false);
            findMigrationProblems(locations.toArray(new IPath[0]), projectNames.toArray(new String[0]));
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IPath(org.eclipse.core.runtime.IPath) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 10 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project egit by eclipse.

the class CommonUtils method runCommand.

/**
 * Programatically run command based on it id and given selection
 *
 * @param commandId
 *            id of command that should be run
 * @param selection
 *            given selection
 * @return {@code true} when command was successfully executed,
 *         {@code false} otherwise
 */
public static boolean runCommand(String commandId, IStructuredSelection selection) {
    ICommandService commandService = CommonUtils.getService(PlatformUI.getWorkbench(), ICommandService.class);
    Command cmd = commandService.getCommand(commandId);
    if (!cmd.isDefined())
        return false;
    IHandlerService handlerService = CommonUtils.getService(PlatformUI.getWorkbench(), IHandlerService.class);
    EvaluationContext c = null;
    if (selection != null) {
        c = new EvaluationContext(handlerService.createContextSnapshot(false), selection.toList());
        c.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
        c.removeVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    }
    try {
        if (c != null)
            handlerService.executeCommandInContext(new ParameterizedCommand(cmd, null), null, c);
        else
            handlerService.executeCommand(commandId, null);
        return true;
    } catch (CommandException ignored) {
    // Ignored
    }
    return false;
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) CommandException(org.eclipse.core.commands.common.CommandException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService)

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