use of org.eclipse.core.expressions.IEvaluationContext in project liferay-ide by liferay.
the class UIUtil method executeCommand.
public static void executeCommand(String commandId, ISelection selection, Map<String, Object> parameters) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
IEvaluationContext evaluationContext = new EvaluationContext(null, Collections.emptyList());
evaluationContext.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
IWorkbench workbench = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
Command migrate = commandService.getCommand(commandId);
IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
if (parameters != null) {
parameters.keySet().stream().forEach(parma -> evaluationContext.addVariable(parma, parameters.get(parma)));
}
handlerService.executeCommandInContext(ParameterizedCommand.generateCommand(migrate, null), null, evaluationContext);
}
use of org.eclipse.core.expressions.IEvaluationContext in project core by jcryptool.
the class ShowEditorsPulldownMenuAction method createEditorsMenu.
/**
* Creates the menu.
*
* @param parent
* @param menu
* @return
*/
private static Menu createEditorsMenu(Control parent, Menu menu) {
if (menu == null) {
menu = new Menu(parent);
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(// $NON-NLS-1$
"org.jcryptool.core.operations.editorServices");
Comparator<IConfigurationElement> comp = new Comparator<IConfigurationElement>() {
public int compare(IConfigurationElement o1, IConfigurationElement o2) {
// $NON-NLS-1$
String l1 = o1.getAttribute("label");
// $NON-NLS-1$
String l2 = o2.getAttribute("label");
// $NON-NLS-1$
String c1 = o1.getAttribute("category");
// $NON-NLS-1$
String c2 = o2.getAttribute("category");
int cat = c1.compareTo(c2);
int label = l1.compareTo(l2);
if (cat != 0) {
return cat;
} else {
if (// $NON-NLS-1$ //$NON-NLS-2$
o1.getAttribute("id").contains("org.jcryptool.editor.text") && !o2.getAttribute("id").contains("org.jcryptool.editor.text")) {
return -1;
}
if (// $NON-NLS-1$ //$NON-NLS-2$
!o1.getAttribute("id").contains("org.jcryptool.editor.text") && o2.getAttribute("id").contains("org.jcryptool.editor.text")) {
return 1;
}
if (label != 0) {
return label;
} else {
return o2.hashCode() - o1.hashCode();
}
}
}
};
Set<IConfigurationElement> entries = new TreeSet<IConfigurationElement>(comp);
for (IExtension extension : point.getExtensions()) {
for (IConfigurationElement element : extension.getConfigurationElements()) {
entries.add(element);
}
}
// $NON-NLS-1$
String currentCat = entries.size() > 0 ? entries.iterator().next().getAttribute("category") : null;
for (IConfigurationElement element : entries) {
if (!currentCat.equals(element.getAttribute("category"))) {
// $NON-NLS-1$
new MenuItem(menu, SWT.SEPARATOR);
// $NON-NLS-1$
currentCat = element.getAttribute("category");
}
final MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
// Set the Labels to the entries
// $NON-NLS-1$
menuItem.setText(element.getAttribute("label"));
// set the actions to the entries
try {
// $NON-NLS-1$
Object o = element.createExecutableExtension("pushAction");
menuItem.setData(o);
} catch (CoreException e) {
LogUtil.logError(CorePlugin.PLUGIN_ID, e);
}
// subpath of the icon within the plugin //$NON-NLS-1$
String iconPath = element.getAttribute("icon");
if ((iconPath != null) && (!iconPath.equals(""))) {
// $NON-NLS-1$
try {
// id of the plugin for path resolution //$NON-NLS-1$
Object o = element.getAttribute("id");
if (o != null) {
Bundle bundle = Platform.getBundle(o.toString());
// $NON-NLS-1$
URL fileUrl = FileLocator.find(bundle, new Path("/"), null);
fileUrl = FileLocator.toFileURL(fileUrl);
iconPath = fileUrl.getFile() + iconPath;
menuItem.setImage(new Image(null, iconPath));
}
} catch (IOException ex) {
LogUtil.logError(CorePlugin.PLUGIN_ID, ex);
}
}
// Handle selection
menuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
// execute the actions
Object o = ((MenuItem) e.getSource()).getData();
try {
IHandler handler = (IHandler) o;
handler.execute(event);
} catch (Exception ex) {
LogUtil.logError(CorePlugin.PLUGIN_ID, ex);
}
}
});
}
}
return menu;
}
use of org.eclipse.core.expressions.IEvaluationContext in project polymap4-core by Polymap4.
the class NavigatorPlugin method getEvalContext.
/**
* @param selection
* @return an evaluation context
*/
public static IEvaluationContext getEvalContext(Object selection) {
IEvaluationContext c = new EvaluationContext(getApplicationContext(), selection);
c.setAllowPluginActivation(true);
return c;
}
use of org.eclipse.core.expressions.IEvaluationContext in project polymap4-core by Polymap4.
the class CommonActionProviderDescriptor method isEnabledFor.
/**
* Determine if this action provider descriptor is enabled for the given selection.
* The action provider descriptor is enabled for the selection if and only if it is
* enabled for each element in the selection.
*
* @param aStructuredSelection
* The selection from the viewer
* @return True if and only if the extension is enabled for each element in
* the selection.
*/
public boolean isEnabledFor(IStructuredSelection aStructuredSelection) {
if (enablement == null) {
return false;
}
if (aStructuredSelection.isEmpty()) {
IEvaluationContext context = null;
context = NavigatorPlugin.getEmptyEvalContext();
if (NavigatorPlugin.safeEvaluate(enablement, context) != EvaluationResult.TRUE) {
return false;
}
} else {
IEvaluationContext context = null;
IEvaluationContext parentContext = NavigatorPlugin.getApplicationContext();
Iterator elements = aStructuredSelection.iterator();
while (elements.hasNext()) {
context = new EvaluationContext(parentContext, elements.next());
context.setAllowPluginActivation(true);
if (NavigatorPlugin.safeEvaluate(enablement, context) != EvaluationResult.TRUE) {
return false;
}
}
}
return true;
}
use of org.eclipse.core.expressions.IEvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionAndFalse.
public void testIterateExpressionAndFalse() 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("and");
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));
// $NON-NLS-1$
assertTrue(result.size() == 1 && result.get(0).equals("one"));
}
Aggregations