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