Search in sources :

Example 1 with ToolGroupDescriptor

use of org.jkiss.dbeaver.registry.tools.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 = DBeaverUI.getActiveWorkbenchWindow();
        if (workbenchWindow.getActivePage() != null) {
            IWorkbenchPart activePart = workbenchWindow.getActivePage().getActivePart();
            if (activePart != null) {
                Map<ToolGroupDescriptor, IMenuManager> groupsMap = new HashMap<>();
                for (ToolDescriptor tool : tools) {
                    hasTools = true;
                    IMenuManager parentMenu = null;
                    if (tool.getGroup() != null) {
                        parentMenu = getGroupMenu(menuItems, groupsMap, tool.getGroup());
                    }
                    IAction action = ActionUtils.makeAction(new NavigatorActionExecuteTool(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 : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) HashMap(java.util.HashMap) ToolDescriptor(org.jkiss.dbeaver.registry.tools.ToolDescriptor) ToolGroupDescriptor(org.jkiss.dbeaver.registry.tools.ToolGroupDescriptor) EmptyListAction(org.jkiss.dbeaver.ui.actions.common.EmptyListAction) NavigatorActionExecuteTool(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionExecuteTool)

Example 2 with ToolGroupDescriptor

use of org.jkiss.dbeaver.registry.tools.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 = DBeaverUI.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 NavigatorActionExecuteTool(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 : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ToolDescriptor(org.jkiss.dbeaver.registry.tools.ToolDescriptor) ToolGroupDescriptor(org.jkiss.dbeaver.registry.tools.ToolGroupDescriptor) EmptyListAction(org.jkiss.dbeaver.ui.actions.common.EmptyListAction) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) NavigatorActionExecuteTool(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionExecuteTool)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 ToolDescriptor (org.jkiss.dbeaver.registry.tools.ToolDescriptor)2 ToolGroupDescriptor (org.jkiss.dbeaver.registry.tools.ToolGroupDescriptor)2 EmptyListAction (org.jkiss.dbeaver.ui.actions.common.EmptyListAction)2 NavigatorActionExecuteTool (org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionExecuteTool)2 HashMap (java.util.HashMap)1