use of org.eclipse.core.expressions.IEvaluationContext in project translationstudio8 by heartsome.
the class NewHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
String parameter = event.getParameter("wizardParameter");
Command command = null;
ICommandService commandService = (ICommandService) HandlerUtil.getActiveSite(event).getService(ICommandService.class);
if (parameter == null || parameter.equalsIgnoreCase("project")) {
command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newProject");
} else if (parameter.equalsIgnoreCase("folder")) {
command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newFolder");
} else if (parameter.equalsIgnoreCase("tm")) {
command = commandService.getCommand("net.heartsome.cat.database.ui.tm.command.newTM");
} else if (parameter.equalsIgnoreCase("tb")) {
command = commandService.getCommand("net.heartsome.cat.database.ui.tb.command.newTB");
}
if (command == null) {
return null;
}
IEvaluationService evalService = (IEvaluationService) HandlerUtil.getActiveSite(event).getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (NotDefinedException e) {
LOGGER.error("", e);
} catch (NotEnabledException e) {
LOGGER.error("", e);
} catch (NotHandledException e) {
LOGGER.error("", e);
}
return null;
}
use of org.eclipse.core.expressions.IEvaluationContext 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);
}
Aggregations