Search in sources :

Example 11 with IEvaluationContext

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

the class RepositoryAction method createExecutionEvent.

/**
 * Creates {@link ExecutionEvent} based on current selection
 *
 * @return {@link ExecutionEvent} with current selection
 */
protected ExecutionEvent createExecutionEvent() {
    IServiceLocator locator = getServiceLocator();
    ICommandService srv = CommonUtils.getService(locator, ICommandService.class);
    IHandlerService hsrv = CommonUtils.getService(locator, IHandlerService.class);
    Command command = srv.getCommand(commandId);
    ExecutionEvent event = hsrv.createExecutionEvent(command, null);
    if (event.getApplicationContext() instanceof IEvaluationContext)
        ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
    return event;
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IServiceLocator(org.eclipse.ui.services.IServiceLocator) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 12 with IEvaluationContext

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

the class StashesMenu method getRepository.

private Repository getRepository() {
    if (serviceLocator == null)
        return null;
    IHandlerService handlerService = CommonUtils.getService(serviceLocator, IHandlerService.class);
    if (handlerService == null)
        return null;
    IEvaluationContext evaluationContext = handlerService.getCurrentState();
    return SelectionUtils.getRepository(evaluationContext);
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext)

Example 13 with IEvaluationContext

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

the class RebaseCurrentRefCommand method setRef.

private void setRef(ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = getCurrentSelectionChecked(event);
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) currentSelection;
        Object selected = selection.getFirstElement();
        ref = getRef(selected);
    } else
        ref = null;
    Object context = event.getApplicationContext();
    if (!(context instanceof IEvaluationContext))
        return;
    final Repository repository = SelectionUtils.getRepository((IEvaluationContext) context);
    if (repository == null)
        return;
    BasicConfigurationDialog.show(repository);
    String currentFullBranch = getFullBranch(repository);
    if (ref != null && ref.getName().equals(currentFullBranch))
        ref = null;
    if (ref == null) {
        RebaseTargetSelectionDialog rebaseTargetSelectionDialog = new RebaseTargetSelectionDialog(getShell(event), repository);
        if (rebaseTargetSelectionDialog.open() == IDialogConstants.OK_ID) {
            String refName = rebaseTargetSelectionDialog.getRefName();
            try {
                ref = repository.findRef(refName);
            } catch (IOException e) {
                throw new ExecutionException(e.getMessage(), e);
            }
            interactive = rebaseTargetSelectionDialog.isInteractive();
            preserveMerges = rebaseTargetSelectionDialog.isPreserveMerges();
        } else {
            return;
        }
    } else {
        String branchName = Repository.shortenRefName(currentFullBranch);
        Config cfg = repository.getConfig();
        BranchRebaseMode rebase = cfg.getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
        preserveMerges = rebase == BranchRebaseMode.PRESERVE;
        interactive = rebase == BranchRebaseMode.INTERACTIVE;
    }
    jobname = NLS.bind(UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, Repository.shortenRefName(currentFullBranch), ref.getName());
}
Also used : RebaseTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.RebaseTargetSelectionDialog) BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) Repository(org.eclipse.jgit.lib.Repository) Config(org.eclipse.jgit.lib.Config) ISelection(org.eclipse.jface.viewers.ISelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 14 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testIterateExpressionOrFalse.

public void testIterateExpressionOrFalse() 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);
    List<String> input = new ArrayList<>();
    // $NON-NLS-1$
    input.add("one");
    // $NON-NLS-1$
    input.add("two");
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    assertTrue(result.equals(input));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 15 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testIterateExpressionOrTrue.

public void testIterateExpressionOrTrue() 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.TRUE;
        }
    };
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("or");
    exp.add(myExpression);
    List<String> input = new ArrayList<>();
    // $NON-NLS-1$
    input.add("one");
    // $NON-NLS-1$
    input.add("two");
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    // $NON-NLS-1$
    assertTrue(result.size() == 1 && result.get(0).equals("one"));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Aggregations

IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)49 ICommandService (org.eclipse.ui.commands.ICommandService)22 Command (org.eclipse.core.commands.Command)21 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)19 IHandlerService (org.eclipse.ui.handlers.IHandlerService)19 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 ISelection (org.eclipse.jface.viewers.ISelection)10 ExecutionException (org.eclipse.core.commands.ExecutionException)9 Expression (org.eclipse.core.expressions.Expression)9 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)7 CoreException (org.eclipse.core.runtime.CoreException)7 ArrayList (java.util.ArrayList)6 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)6 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)6 WithExpression (org.eclipse.core.internal.expressions.WithExpression)6 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)5 AndExpression (org.eclipse.core.internal.expressions.AndExpression)5 CountExpression (org.eclipse.core.internal.expressions.CountExpression)5 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)5