Search in sources :

Example 1 with Expression

use of org.eclipse.core.expressions.Expression in project dbeaver by dbeaver.

the class DebugUIInternals method createShortcutActions.

public static Map<IAction, String> createShortcutActions(Object[] selected, String mode, int accelerator) {
    Map<IAction, String> result = new LinkedHashMap<IAction, String>();
    if (selected == null) {
        return result;
    }
    List<Object> selection = Arrays.asList(selected);
    IEvaluationContext context = DebugUIPlugin.createEvaluationContext(selection);
    context.setAllowPluginActivation(true);
    // $NON-NLS-1$
    context.addVariable("selection", selection);
    List<LaunchShortcutExtension> allShortCuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
    List<LaunchShortcutExtension> filteredShortCuts = new ArrayList<LaunchShortcutExtension>();
    Iterator<LaunchShortcutExtension> iter = allShortCuts.iterator();
    while (iter.hasNext()) {
        LaunchShortcutExtension ext = iter.next();
        if (WorkbenchActivityHelper.filterItem(ext)) {
            continue;
        }
        try {
            Expression expr = ext.getContextualLaunchEnablementExpression();
            if (ext.evalEnablementExpression(context, expr)) {
                filteredShortCuts.add(ext);
            }
        } catch (CoreException e) {
            IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), // $NON-NLS-1$
            "Launch shortcut '" + ext.getId() + "' enablement expression caused exception. Shortcut was removed.", // $NON-NLS-1$
            e);
            DebugUIPlugin.log(status);
            iter.remove();
        }
    }
    for (LaunchShortcutExtension ext : filteredShortCuts) {
        for (String supported : ext.getModes()) {
            if (supported.equals(mode)) {
                LaunchShortcutAction action = new LaunchShortcutAction(supported, ext);
                // $NON-NLS-1$
                action.setActionDefinitionId(ext.getId() + "." + supported);
                String helpContextId = ext.getHelpContextId();
                if (helpContextId != null) {
                    PlatformUI.getWorkbench().getHelpSystem().setHelp(action, helpContextId);
                }
                StringBuffer label = new StringBuffer();
                if (accelerator >= 0 && accelerator < 10) {
                    // add the numerical accelerator
                    label.append('&');
                    label.append(accelerator);
                    label.append(' ');
                }
                String contextLabel = ext.getContextLabel(supported);
                // replace default action label with context label if
                // specified.
                label.append((contextLabel != null) ? contextLabel : action.getText());
                action.setText(label.toString());
                String category = ext.getCategory();
                result.put(action, category);
                accelerator++;
            }
        }
    }
    return result;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IAction(org.eclipse.jface.action.IAction) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) LaunchShortcutExtension(org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension) LaunchShortcutAction(org.eclipse.debug.internal.ui.actions.LaunchShortcutAction) CoreException(org.eclipse.core.runtime.CoreException) Expression(org.eclipse.core.expressions.Expression)

Example 2 with Expression

use of org.eclipse.core.expressions.Expression 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));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 3 with Expression

use of org.eclipse.core.expressions.Expression 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"));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 4 with Expression

use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testPlatformPropertyTester.

public void testPlatformPropertyTester() throws Exception {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    // $NON-NLS-1$ //$NON-NLS-2$
    IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
    // $NON-NLS-1$ //$NON-NLS-2$
    IConfigurationElement enable = findExtension(ces, "test3").getChildren("enablement")[0];
    Expression exp = ExpressionConverter.getDefault().perform(enable);
    EvaluationContext context = new EvaluationContext(null, Platform.class);
    assertEquals(EvaluationResult.TRUE, exp.evaluate(context));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 5 with Expression

use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testIterateExpressionWithAdapterManager.

public void testIterateExpressionWithAdapterManager() 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);
    final List<String> input = new ArrayList<>();
    // $NON-NLS-1$
    input.add("one");
    // $NON-NLS-1$
    input.add("two");
    CollectionWrapper wrapper = new CollectionWrapper();
    wrapper.collection = input;
    EvaluationContext context = new EvaluationContext(null, wrapper);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    assertTrue(result.equals(input));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Aggregations

Expression (org.eclipse.core.expressions.Expression)16 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)10 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)9 AndExpression (org.eclipse.core.internal.expressions.AndExpression)9 CountExpression (org.eclipse.core.internal.expressions.CountExpression)9 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)9 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)9 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)9 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)9 NotExpression (org.eclipse.core.internal.expressions.NotExpression)9 OrExpression (org.eclipse.core.internal.expressions.OrExpression)9 ResolveExpression (org.eclipse.core.internal.expressions.ResolveExpression)9 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)9 TestExpression (org.eclipse.core.internal.expressions.TestExpression)9 WithExpression (org.eclipse.core.internal.expressions.WithExpression)9 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)8 CoreException (org.eclipse.core.runtime.CoreException)7 ArrayList (java.util.ArrayList)6 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)5 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)5