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;
}
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);
}
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());
}
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));
}
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"));
}
Aggregations