Search in sources :

Example 1 with ToolDescriptor

use of org.jkiss.dbeaver.registry.tools.ToolDescriptor 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 ToolDescriptor

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

the class DataSourceToolsContributor method fillContributionItems.

@Override
protected void fillContributionItems(List<IContributionItem> menuItems) {
    IWorkbenchPart activePart = DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart();
    if (activePart == null) {
        return;
    }
    final ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return;
    }
    ISelection selection = selectionProvider.getSelection();
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    DBSObject selectedObject = NavigatorUtils.getSelectedObject((IStructuredSelection) selection);
    if (selectedObject != null) {
        List<ToolDescriptor> tools = ToolsRegistry.getInstance().getTools((IStructuredSelection) selection);
        fillToolsMenu(menuItems, tools, selection);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ToolDescriptor(org.jkiss.dbeaver.registry.tools.ToolDescriptor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 ToolDescriptor (org.jkiss.dbeaver.registry.tools.ToolDescriptor)2 HashMap (java.util.HashMap)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 ToolGroupDescriptor (org.jkiss.dbeaver.registry.tools.ToolGroupDescriptor)1 EmptyListAction (org.jkiss.dbeaver.ui.actions.common.EmptyListAction)1 NavigatorActionExecuteTool (org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionExecuteTool)1