use of org.eclipse.core.expressions.EvaluationContext in project polymap4-core by Polymap4.
the class NavigatorPlugin method getEmptyEvalContext.
/**
* @return an evaluation context
*/
public static IEvaluationContext getEmptyEvalContext() {
IEvaluationContext c = new EvaluationContext(getApplicationContext(), Collections.EMPTY_LIST);
c.setAllowPluginActivation(true);
return c;
}
use of org.eclipse.core.expressions.EvaluationContext in project dbeaver by dbeaver.
the class ActionUtils method runCommand.
public static void runCommand(String commandId, ISelection selection, Map<String, Object> parameters, IServiceLocator serviceLocator) {
if (commandId != null) {
try {
ICommandService commandService = serviceLocator.getService(ICommandService.class);
IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
boolean needContextPatch = false;
if (selection != null) {
needContextPatch = true;
if (serviceLocator instanceof IWorkbenchSite) {
final ISelection curSelection = ((IWorkbenchSite) serviceLocator).getSelectionProvider().getSelection();
if (curSelection instanceof IStructuredSelection && selection instanceof IStructuredSelection) {
if (((IStructuredSelection) curSelection).size() == ((IStructuredSelection) selection).size() && ((IStructuredSelection) curSelection).getFirstElement() == ((IStructuredSelection) selection).getFirstElement()) {
// The same selection
needContextPatch = false;
}
}
}
}
Parameterization[] parametrization = null;
if (!CommonUtils.isEmpty(parameters)) {
parametrization = new Parameterization[parameters.size()];
int paramIndex = 0;
for (Map.Entry<String, Object> param : parameters.entrySet()) {
IParameter parameter = command.getParameter(param.getKey());
if (parameter != null) {
parametrization[paramIndex] = new Parameterization(parameter, CommonUtils.toString(param.getValue()));
} else {
log.debug("Parameter '" + param.getKey() + "' not found in command '" + commandId + "'");
parametrization[paramIndex] = null;
}
paramIndex++;
}
}
if (selection != null && needContextPatch) {
// Create new eval context
IEvaluationContext context = new EvaluationContext(handlerService.createContextSnapshot(false), selection);
if (serviceLocator instanceof IWorkbenchPartSite) {
context.addVariable(ISources.ACTIVE_PART_NAME, ((IWorkbenchPartSite) serviceLocator).getPart());
}
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
ParameterizedCommand pc = new ParameterizedCommand(command, parametrization);
handlerService.executeCommandInContext(pc, null, context);
} else if (command != null) {
if (command.isEnabled()) {
ParameterizedCommand pc = new ParameterizedCommand(command, parametrization);
handlerService.executeCommand(pc, null);
} else {
log.warn("Command '" + commandId + "' is disabled");
}
} else {
log.warn("Command '" + commandId + "' not found");
}
}
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Error running command", "Can't execute command '" + commandId + "'", e);
}
}
}
use of org.eclipse.core.expressions.EvaluationContext in project xtext-eclipse by eclipse.
the class ToSaveOrNotToSaveTest method renameFooToFooBar.
protected void renameFooToFooBar(final XtextEditor contextEditor) throws Exception {
contextEditor.getEditorSite().getPage().activate(contextEditor);
waitForDisplay();
IXtextDocument document = contextEditor.getDocument();
final int offset = document.get().indexOf("foo");
contextEditor.selectAndReveal(offset, 3);
EvaluationContext evaluationContext = new EvaluationContext(null, new Object());
evaluationContext.addVariable(ISources.ACTIVE_EDITOR_NAME, contextEditor);
ExecutionEvent executionEvent = new ExecutionEvent(null, newHashMap(), null, evaluationContext);
renameElementHandler.execute(executionEvent);
// syncUtil.totalSync(refactoringPreferences.isSaveAllBeforeRefactoring());
// IRenameElementContext context = document.readOnly(new IUnitOfWork<IRenameElementContext, XtextResource>() {
// public IRenameElementContext exec(XtextResource state) throws Exception {
// EObject target = eObjectAtOffsetHelper.resolveElementAt(state, offset);
// return renameContextFactory.createRenameElementContext(target, contextEditor, new TextSelection(offset,
// 3), state);
// }
// });
// controller.initialize(context);
// waitForDisplay();
// controller.startRefactoring(RefactoringType.LINKED_EDITING);
// waitForDisplay();
pressKeys(contextEditor, "fooBar\n");
waitForDisplay();
waitForReconciler(fooEditor);
waitForReconciler(barEditor);
waitForDisplay();
}
use of org.eclipse.core.expressions.EvaluationContext in project tdi-studio-se by Talend.
the class TalendLaunchShortcutAction method updateEnablement.
/**
* Since these actions are re-created each time the run/debug as menu is filled, the enablement of this action is
* static.
*/
private void updateEnablement() {
// IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
IWorkbenchWindow wb = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
boolean enabled = false;
if (wb != null) {
IWorkbenchPage page = wb.getActivePage();
if (page != null) {
ISelection selection = page.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
try {
// check enablement logic, if any
Expression expression = fShortcut.getShortcutEnablementExpression();
if (expression == null) {
enabled = !structuredSelection.isEmpty();
} else {
List list = structuredSelection.toList();
IEvaluationContext context = new EvaluationContext(null, list);
//$NON-NLS-1$
context.addVariable("selection", list);
enabled = fShortcut.evalEnablementExpression(context, expression);
}
} catch (CoreException e) {
}
} else {
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
enabled = true;
}
}
}
}
setEnabled(enabled);
}
use of org.eclipse.core.expressions.EvaluationContext in project dbeaver by dbeaver.
the class ActionUtils method runCommand.
public static void runCommand(String commandId, ISelection selection, IServiceLocator serviceLocator) {
if (commandId != null) {
try {
ICommandService commandService = serviceLocator.getService(ICommandService.class);
IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
boolean needContextPatch = false;
if (selection != null) {
needContextPatch = true;
if (serviceLocator instanceof IWorkbenchSite) {
final ISelection curSelection = ((IWorkbenchSite) serviceLocator).getSelectionProvider().getSelection();
if (curSelection instanceof IStructuredSelection && selection instanceof IStructuredSelection) {
if (((IStructuredSelection) curSelection).size() == ((IStructuredSelection) selection).size() && ((IStructuredSelection) curSelection).getFirstElement() == ((IStructuredSelection) selection).getFirstElement()) {
// The same selection
needContextPatch = false;
}
}
}
}
if (selection != null && needContextPatch) {
// Create new eval context
IEvaluationContext context = new EvaluationContext(handlerService.createContextSnapshot(false), selection);
if (serviceLocator instanceof IWorkbenchPartSite) {
context.addVariable(ISources.ACTIVE_PART_NAME, ((IWorkbenchPartSite) serviceLocator).getPart());
}
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
ParameterizedCommand pc = new ParameterizedCommand(command, null);
handlerService.executeCommandInContext(pc, null, context);
} else if (command != null) {
if (command.isEnabled()) {
handlerService.executeCommand(commandId, null);
} else {
log.warn("Command '" + commandId + "' is disabled");
}
} else {
log.warn("Command '" + commandId + "' not found");
}
}
} catch (Exception e) {
log.error("Can't execute command '" + commandId + "'", e);
}
}
}
Aggregations