Search in sources :

Example 1 with ToolGroupDescriptor

use of org.jkiss.dbeaver.tools.registry.ToolGroupDescriptor in project dbeaver by serge-rider.

the class DataSourceToolsContributor method fillToolsMenu.

private static void fillToolsMenu(List<IContributionItem> menuItems, List<ToolDescriptor> tools, ISelection selection) {
    boolean hasTools = false;
    if (!CommonUtils.isEmpty(tools)) {
        IWorkbenchWindow workbenchWindow = UIUtils.getActiveWorkbenchWindow();
        if (workbenchWindow.getActivePage() != null) {
            IWorkbenchPart activePart = workbenchWindow.getActivePage().getActivePart();
            if (activePart != null) {
                Map<ToolGroupDescriptor, IMenuManager> groupsMap = new HashMap<>();
                Set<ToolGroupDescriptor> groupSet = new HashSet<>();
                for (ToolDescriptor tool : tools) {
                    hasTools = true;
                    IMenuManager parentMenu = null;
                    if (tool.getGroup() != null) {
                        if (SHOW_GROUPS_AS_SUBMENU) {
                            parentMenu = getGroupMenu(menuItems, groupsMap, tool.getGroup());
                        } else {
                            if (!groupSet.contains(tool.getGroup())) {
                                groupSet.add(tool.getGroup());
                                menuItems.add(new Separator(tool.getGroup().getId()));
                            }
                        }
                    }
                    IAction action = ActionUtils.makeAction(new ExecuteToolHandler(workbenchWindow, tool), activePart.getSite(), selection, tool.getLabel(), tool.getIcon() == null ? null : DBeaverIcons.getImageDescriptor(tool.getIcon()), tool.getDescription());
                    if (parentMenu == null) {
                        menuItems.add(new ActionContributionItem(action));
                    } else {
                        parentMenu.add(new ActionContributionItem(action));
                    }
                }
            }
        }
    }
    if (!hasTools) {
        menuItems.add(new ActionContributionItem(new EmptyListAction()));
    }
}
Also used : ToolDescriptor(org.jkiss.dbeaver.tools.registry.ToolDescriptor) ToolGroupDescriptor(org.jkiss.dbeaver.tools.registry.ToolGroupDescriptor) EmptyListAction(org.jkiss.dbeaver.ui.actions.EmptyListAction)

Example 2 with ToolGroupDescriptor

use of org.jkiss.dbeaver.tools.registry.ToolGroupDescriptor in project dbeaver by dbeaver.

the class DataSourceToolsContributor method fillToolsMenu.

private static void fillToolsMenu(List<IContributionItem> menuItems, List<ToolDescriptor> tools, ISelection selection) {
    boolean hasTools = false;
    if (!CommonUtils.isEmpty(tools)) {
        IWorkbenchWindow workbenchWindow = UIUtils.getActiveWorkbenchWindow();
        if (workbenchWindow.getActivePage() != null) {
            IWorkbenchPart activePart = workbenchWindow.getActivePage().getActivePart();
            if (activePart != null) {
                Map<ToolGroupDescriptor, IMenuManager> groupsMap = new HashMap<>();
                Set<ToolGroupDescriptor> groupSet = new HashSet<>();
                for (ToolDescriptor tool : tools) {
                    hasTools = true;
                    IMenuManager parentMenu = null;
                    if (tool.getGroup() != null) {
                        if (SHOW_GROUPS_AS_SUBMENU) {
                            parentMenu = getGroupMenu(menuItems, groupsMap, tool.getGroup());
                        } else {
                            if (!groupSet.contains(tool.getGroup())) {
                                groupSet.add(tool.getGroup());
                                menuItems.add(new Separator(tool.getGroup().getId()));
                            }
                        }
                    }
                    IAction action = ActionUtils.makeAction(new ExecuteToolHandler(workbenchWindow, tool), activePart.getSite(), selection, tool.getLabel(), tool.getIcon() == null ? null : DBeaverIcons.getImageDescriptor(tool.getIcon()), tool.getDescription());
                    if (parentMenu == null) {
                        menuItems.add(new ActionContributionItem(action));
                    } else {
                        parentMenu.add(new ActionContributionItem(action));
                    }
                }
            }
        }
    }
    if (!hasTools) {
        menuItems.add(new ActionContributionItem(new EmptyListAction()));
    }
}
Also used : ToolDescriptor(org.jkiss.dbeaver.tools.registry.ToolDescriptor) ToolGroupDescriptor(org.jkiss.dbeaver.tools.registry.ToolGroupDescriptor) EmptyListAction(org.jkiss.dbeaver.ui.actions.EmptyListAction)

Aggregations

ToolDescriptor (org.jkiss.dbeaver.tools.registry.ToolDescriptor)2 ToolGroupDescriptor (org.jkiss.dbeaver.tools.registry.ToolGroupDescriptor)2 EmptyListAction (org.jkiss.dbeaver.ui.actions.EmptyListAction)2