Search in sources :

Example 1 with ToolDescriptor

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

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

the class DataSourceToolsContributor method fillContributionItems.

@Override
protected void fillContributionItems(List<IContributionItem> menuItems) {
    IWorkbenchPage activePage = UIUtils.getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart activePart = activePage.getActivePart();
    if (activePart == null) {
        return;
    }
    DBSObject selectedObject = null;
    INavigatorModelView navigatorModelView = GeneralUtils.adapt(activePart, INavigatorModelView.class);
    if (navigatorModelView != null) {
        final ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
        if (selectionProvider != null) {
            ISelection selection = selectionProvider.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                selectedObject = RuntimeUtils.getObjectAdapter(((IStructuredSelection) selection).getFirstElement(), DBSObject.class);
                List<ToolDescriptor> tools = getAvailableTools((IStructuredSelection) selection);
                fillToolsMenu(menuItems, tools, selection);
            }
        }
    } else if (activePart instanceof IEditorPart) {
        IEditorInput editorInput = ((IEditorPart) activePart).getEditorInput();
        if (editorInput instanceof IDatabaseEditorInput) {
            selectedObject = ((IDatabaseEditorInput) editorInput).getDatabaseObject();
        } else if (activePart instanceof IDataSourceContainerProvider) {
            selectedObject = ((IDataSourceContainerProvider) activePart).getDataSourceContainer();
        }
    }
    if (selectedObject != null) {
        // Contribute standard tools like session manager
        DBPDataSource dataSource = selectedObject.getDataSource();
        if (dataSource != null) {
            DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
            DBPEditorContribution[] contributedEditors = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getContributedEditors(DBPEditorContribution.MB_CONNECTION_EDITOR, dataSourceContainer);
            if (contributedEditors.length > 0) {
                menuItems.add(new Separator());
                for (DBPEditorContribution ec : contributedEditors) {
                    menuItems.add(new ActionContributionItem(new OpenToolsEditorAction(activePage, dataSource, ec)));
                }
            }
        }
    }
    // Tasks management
    {
        menuItems.add(new Separator());
        menuItems.add(ActionUtils.makeCommandContribution(activePart.getSite(), DatabaseTasksView.CREATE_TASK_CMD_ID));
    }
}
Also used : ToolDescriptor(org.jkiss.dbeaver.tools.registry.ToolDescriptor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBPEditorContribution(org.jkiss.dbeaver.model.connection.DBPEditorContribution) ISelection(org.eclipse.jface.viewers.ISelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView)

Example 3 with ToolDescriptor

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

the class DataSourceToolsContributor method getAvailableTools.

private List<ToolDescriptor> getAvailableTools(IStructuredSelection selection) {
    List<DBSObject> objects = NavigatorUtils.getSelectedObjects(selection);
    List<ToolDescriptor> result = new ArrayList<>();
    if (!objects.isEmpty()) {
        for (ToolDescriptor descriptor : ToolsRegistry.getInstance().getTools()) {
            if (descriptor.isSingleton() && objects.size() > 1) {
                continue;
            }
            boolean applies = true;
            for (DBSObject object : objects) {
                if (!descriptor.appliesTo(object)) {
                    applies = false;
                    break;
                }
            }
            if (applies) {
                result.add(descriptor);
            }
        }
    }
    return result;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ToolDescriptor(org.jkiss.dbeaver.tools.registry.ToolDescriptor)

Example 4 with ToolDescriptor

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

Example 5 with ToolDescriptor

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

the class DataSourceToolsContributor method fillContributionItems.

@Override
protected void fillContributionItems(List<IContributionItem> menuItems) {
    IWorkbenchPage activePage = UIUtils.getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart activePart = activePage.getActivePart();
    if (activePart == null) {
        return;
    }
    DBSObject selectedObject = null;
    INavigatorModelView navigatorModelView = GeneralUtils.adapt(activePart, INavigatorModelView.class);
    if (navigatorModelView != null) {
        final ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
        if (selectionProvider != null) {
            ISelection selection = selectionProvider.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                selectedObject = RuntimeUtils.getObjectAdapter(((IStructuredSelection) selection).getFirstElement(), DBSObject.class);
                List<ToolDescriptor> tools = getAvailableTools((IStructuredSelection) selection);
                fillToolsMenu(menuItems, tools, selection);
            }
        }
    } else if (activePart instanceof IEditorPart) {
        IEditorInput editorInput = ((IEditorPart) activePart).getEditorInput();
        if (editorInput instanceof IDatabaseEditorInput) {
            selectedObject = ((IDatabaseEditorInput) editorInput).getDatabaseObject();
        } else if (activePart instanceof IDataSourceContainerProvider) {
            selectedObject = ((IDataSourceContainerProvider) activePart).getDataSourceContainer();
        }
    }
    if (selectedObject != null) {
        // Contribute standard tools like session manager
        DBPDataSource dataSource = selectedObject.getDataSource();
        if (dataSource != null) {
            DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
            DBPEditorContribution[] contributedEditors = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getContributedEditors(DBPEditorContribution.MB_CONNECTION_EDITOR, dataSourceContainer);
            if (contributedEditors.length > 0) {
                menuItems.add(new Separator());
                for (DBPEditorContribution ec : contributedEditors) {
                    menuItems.add(new ActionContributionItem(new OpenToolsEditorAction(activePage, dataSource, ec)));
                }
            }
        }
    }
    // Tasks management
    {
        menuItems.add(new Separator());
        menuItems.add(ActionUtils.makeCommandContribution(activePart.getSite(), DatabaseTasksView.CREATE_TASK_CMD_ID));
    }
}
Also used : ToolDescriptor(org.jkiss.dbeaver.tools.registry.ToolDescriptor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBPEditorContribution(org.jkiss.dbeaver.model.connection.DBPEditorContribution) ISelection(org.eclipse.jface.viewers.ISelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView)

Aggregations

ToolDescriptor (org.jkiss.dbeaver.tools.registry.ToolDescriptor)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 ISelection (org.eclipse.jface.viewers.ISelection)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 DBPEditorContribution (org.jkiss.dbeaver.model.connection.DBPEditorContribution)2 ToolGroupDescriptor (org.jkiss.dbeaver.tools.registry.ToolGroupDescriptor)2 EmptyListAction (org.jkiss.dbeaver.ui.actions.EmptyListAction)2 IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)2 INavigatorModelView (org.jkiss.dbeaver.ui.navigator.INavigatorModelView)2