Search in sources :

Example 1 with LaunchShortcutExtension

use of org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension 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 LaunchShortcutExtension

use of org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension in project webtools.sourceediting by eclipse.

the class LaunchShortcutTest method testShortcutExtensionPointConfigured.

/**
 * Tests that the short cut is defined via the extension point.
 */
@Test
public void testShortcutExtensionPointConfigured() {
    LaunchShortcutExtension ext = getLaunchShortcutExtension(XSL_LAUNCH_SHORTCUT_ID);
    // $NON-NLS-1$
    assertNotNull("XSLT stylesheet shortcut not found", ext);
}
Also used : LaunchShortcutExtension(org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension) AbstractLaunchingTest(org.eclipse.wst.xsl.launching.tests.AbstractLaunchingTest) Test(org.junit.Test)

Example 3 with LaunchShortcutExtension

use of org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension in project webtools.sourceediting by eclipse.

the class LaunchShortcutTest method getApplicableLaunchShortcuts.

/**
 * Returns a listing of all applicable <code>LaunchShortcutExtension</code>s for the given
 * launch configuration type id.
 * @param typeid the id of the launch configuration
 * @return a listing of <code>LaunchShortcutExtension</code>s that are associated with the specified launch configuration
 * type id or an empty list, never <code>null</code>
 *
 * @since 1.0
 */
public List getApplicableLaunchShortcuts(String typeid) {
    List list = new ArrayList();
    LaunchShortcutExtension ext = null;
    List shortcuts = getLaunchConfigurationManager().getLaunchShortcuts();
    for (int i = 0; i < shortcuts.size(); i++) {
        ext = (LaunchShortcutExtension) shortcuts.get(i);
        if (ext.getAssociatedConfigurationTypes().contains(typeid) && !WorkbenchActivityHelper.filterItem(ext)) {
            list.add(ext);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LaunchShortcutExtension(org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension)

Example 4 with LaunchShortcutExtension

use of org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension in project webtools.sourceediting by eclipse.

the class AbstractLaunchingTest method getLaunchShortcutExtension.

/**
 * Returns the launch shortcut with the given id
 *
 * @param id
 * @return the <code>LaunchShortcutExtension</code> with the given id, or
 *         <code>null</code> if none
 *
 * @since 1.0
 */
protected LaunchShortcutExtension getLaunchShortcutExtension(String id) {
    List exts = getLaunchConfigurationManager().getLaunchShortcuts();
    LaunchShortcutExtension ext = null;
    for (int i = 0; i < exts.size(); i++) {
        ext = (LaunchShortcutExtension) exts.get(i);
        if (ext.getId().equals(id)) {
            return ext;
        }
    }
    return null;
}
Also used : List(java.util.List) LaunchShortcutExtension(org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension)

Example 5 with LaunchShortcutExtension

use of org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension in project webtools.sourceediting by eclipse.

the class LaunchShortcutTest method testAssociatedConfigurationTypeNotSupported.

/**
 * Tests that the local java app shortcut does not support some fake type id 'foo'
 */
@Test
public void testAssociatedConfigurationTypeNotSupported() {
    LaunchShortcutExtension ext = getLaunchShortcutExtension(XSL_LAUNCH_SHORTCUT_ID);
    // $NON-NLS-1$
    assertNotNull("XSLT shortcut not found", ext);
    // $NON-NLS-1$
    String typeid = "org.eclipse.jdt.launching.foo";
    // $NON-NLS-1$
    assertTrue("local xslt app shortcut should not support foo", !ext.getAssociatedConfigurationTypes().contains(typeid));
}
Also used : LaunchShortcutExtension(org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension) AbstractLaunchingTest(org.eclipse.wst.xsl.launching.tests.AbstractLaunchingTest) Test(org.junit.Test)

Aggregations

LaunchShortcutExtension (org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension)7 Expression (org.eclipse.core.expressions.Expression)3 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 LaunchShortcutAction (org.eclipse.debug.internal.ui.actions.LaunchShortcutAction)3 IAction (org.eclipse.jface.action.IAction)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractLaunchingTest (org.eclipse.wst.xsl.launching.tests.AbstractLaunchingTest)2 Test (org.junit.Test)2 LinkedHashMap (java.util.LinkedHashMap)1