Search in sources :

Example 1 with OpenLaunchDialogAction

use of org.eclipse.debug.ui.actions.OpenLaunchDialogAction in project dbeaver by dbeaver.

the class DatabaseLaunchContributionItem method fill.

@Override
public void fill(Menu menu, int index) {
    Object[] selected = extractSelectedObjects();
    int accelerator = 1;
    List<ILaunchConfiguration> configurations = extractSharedConfigurations(selected);
    for (ILaunchConfiguration configuration : configurations) {
        IAction action = DebugUIInternals.createConfigurationAction(configuration, mode, accelerator);
        if (action != null) {
            accelerator++;
            ActionContributionItem item = new ActionContributionItem(action);
            item.fill(menu, -1);
        }
    }
    Map<IAction, String> shortcutActions = DebugUIInternals.createShortcutActions(selected, mode, accelerator);
    // and there are following shortcuts
    if (menu.getItemCount() > 0 && shortcutActions.size() > 0) {
        new MenuItem(menu, SWT.SEPARATOR);
    }
    List<String> categories = new ArrayList<String>();
    Set<IAction> actions = shortcutActions.keySet();
    for (IAction action : actions) {
        String category = shortcutActions.get(action);
        // NOTE: category can be null
        if (category != null && !categories.contains(category)) {
            categories.add(category);
        }
        ActionContributionItem item = new ActionContributionItem(action);
        item.fill(menu, -1);
    }
    // add in the open ... dialog shortcut(s)
    if (categories.isEmpty()) {
        if (defaultGroup != null) {
            if (accelerator > 1) {
                new MenuItem(menu, SWT.SEPARATOR);
            }
            IAction action = new OpenLaunchDialogAction(defaultGroup.getIdentifier());
            ActionContributionItem item = new ActionContributionItem(action);
            item.fill(menu, -1);
        }
    } else {
        boolean addedSep = false;
        for (String category : categories) {
            ILaunchGroup group = defaultGroup;
            if (category != null) {
                group = groupsByCategory.get(category);
            }
            if (group != null) {
                if (accelerator > 1 && !addedSep) {
                    new MenuItem(menu, SWT.SEPARATOR);
                    addedSep = true;
                }
                IAction action = new OpenLaunchDialogAction(group.getIdentifier());
                ActionContributionItem item = new ActionContributionItem(action);
                item.fill(menu, -1);
            }
        }
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IAction(org.eclipse.jface.action.IAction) ArrayList(java.util.ArrayList) MenuItem(org.eclipse.swt.widgets.MenuItem) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) OpenLaunchDialogAction(org.eclipse.debug.ui.actions.OpenLaunchDialogAction)

Example 2 with OpenLaunchDialogAction

use of org.eclipse.debug.ui.actions.OpenLaunchDialogAction in project dbeaver by serge-rider.

the class DatabaseLaunchContributionItem method fill.

@Override
public void fill(Menu menu, int index) {
    Object[] selected = extractSelectedObjects();
    int accelerator = 1;
    List<ILaunchConfiguration> configurations = extractSharedConfigurations(selected);
    for (ILaunchConfiguration configuration : configurations) {
        IAction action = DebugUIInternals.createConfigurationAction(configuration, mode, accelerator);
        if (action != null) {
            accelerator++;
            ActionContributionItem item = new ActionContributionItem(action);
            item.fill(menu, -1);
        }
    }
    Map<IAction, String> shortcutActions = DebugUIInternals.createShortcutActions(selected, mode, accelerator);
    // and there are following shortcuts
    if (menu.getItemCount() > 0 && shortcutActions.size() > 0) {
        new MenuItem(menu, SWT.SEPARATOR);
    }
    List<String> categories = new ArrayList<String>();
    Set<IAction> actions = shortcutActions.keySet();
    for (IAction action : actions) {
        String category = shortcutActions.get(action);
        // NOTE: category can be null
        if (category != null && !categories.contains(category)) {
            categories.add(category);
        }
        ActionContributionItem item = new ActionContributionItem(action);
        item.fill(menu, -1);
    }
    // add in the open ... dialog shortcut(s)
    if (categories.isEmpty()) {
        if (defaultGroup != null) {
            if (accelerator > 1) {
                new MenuItem(menu, SWT.SEPARATOR);
            }
            IAction action = new OpenLaunchDialogAction(defaultGroup.getIdentifier());
            ActionContributionItem item = new ActionContributionItem(action);
            item.fill(menu, -1);
        }
    } else {
        boolean addedSep = false;
        for (String category : categories) {
            ILaunchGroup group = defaultGroup;
            if (category != null) {
                group = groupsByCategory.get(category);
            }
            if (group != null) {
                if (accelerator > 1 && !addedSep) {
                    new MenuItem(menu, SWT.SEPARATOR);
                    addedSep = true;
                }
                IAction action = new OpenLaunchDialogAction(group.getIdentifier());
                ActionContributionItem item = new ActionContributionItem(action);
                item.fill(menu, -1);
            }
        }
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IAction(org.eclipse.jface.action.IAction) MenuItem(org.eclipse.swt.widgets.MenuItem) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) OpenLaunchDialogAction(org.eclipse.debug.ui.actions.OpenLaunchDialogAction)

Aggregations

ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 ILaunchGroup (org.eclipse.debug.ui.ILaunchGroup)2 OpenLaunchDialogAction (org.eclipse.debug.ui.actions.OpenLaunchDialogAction)2 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)2 IAction (org.eclipse.jface.action.IAction)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 ArrayList (java.util.ArrayList)1