Search in sources :

Example 1 with DBPEditorContribution

use of org.jkiss.dbeaver.model.connection.DBPEditorContribution in project dbeaver by serge-rider.

the class DBXTreeFolder method getChildren.

@NotNull
@Override
public List<DBXTreeNode> getChildren(DBNNode context) {
    List<DBXTreeNode> children = super.getChildren(context);
    if (!CommonUtils.isEmpty(contributedCategories) && context instanceof DBNDatabaseNode) {
        // Add contributed editors
        List<DBXTreeNode> childrenWithContributions = new ArrayList<>(children);
        DBPDataSourceProviderRegistry dspRegistry = DBWorkbench.getPlatform().getDataSourceProviderRegistry();
        DBPDataSourceContainer dataSource = ((DBNDatabaseNode) context).getDataSourceContainer();
        for (String category : contributedCategories) {
            DBPEditorContribution[] editors = dspRegistry.getContributedEditors(category, dataSource);
            for (DBPEditorContribution editor : editors) {
                DBXTreeObject editorNode = new DBXTreeObject(getSource(), // No parent - otherwise we'll have dups after each call
                null, null, null, editor.getLabel(), editor.getDescription(), editor.getEditorId());
                editorNode.setDefaultIcon(editor.getIcon());
                childrenWithContributions.add(editorNode);
            }
        }
        return childrenWithContributions;
    }
    return children;
}
Also used : DBPDataSourceProviderRegistry(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderRegistry) DBPEditorContribution(org.jkiss.dbeaver.model.connection.DBPEditorContribution) ArrayList(java.util.ArrayList) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) NotNull(org.jkiss.code.NotNull)

Example 2 with DBPEditorContribution

use of org.jkiss.dbeaver.model.connection.DBPEditorContribution 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 DBPEditorContribution

use of org.jkiss.dbeaver.model.connection.DBPEditorContribution in project dbeaver by dbeaver.

the class DBXTreeFolder method getChildren.

@NotNull
@Override
public List<DBXTreeNode> getChildren(DBNNode context) {
    List<DBXTreeNode> children = super.getChildren(context);
    if (!CommonUtils.isEmpty(contributedCategories) && context instanceof DBNDatabaseNode) {
        // Add contributed editors
        List<DBXTreeNode> childrenWithContributions = new ArrayList<>(children);
        DBPDataSourceProviderRegistry dspRegistry = DBWorkbench.getPlatform().getDataSourceProviderRegistry();
        DBPDataSourceContainer dataSource = ((DBNDatabaseNode) context).getDataSourceContainer();
        for (String category : contributedCategories) {
            DBPEditorContribution[] editors = dspRegistry.getContributedEditors(category, dataSource);
            for (DBPEditorContribution editor : editors) {
                DBXTreeObject editorNode = new DBXTreeObject(getSource(), // No parent - otherwise we'll have dups after each call
                null, null, null, editor.getLabel(), editor.getDescription(), editor.getEditorId());
                editorNode.setDefaultIcon(editor.getIcon());
                childrenWithContributions.add(editorNode);
            }
        }
        return childrenWithContributions;
    }
    return children;
}
Also used : DBPDataSourceProviderRegistry(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderRegistry) DBPEditorContribution(org.jkiss.dbeaver.model.connection.DBPEditorContribution) ArrayList(java.util.ArrayList) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) NotNull(org.jkiss.code.NotNull)

Example 4 with DBPEditorContribution

use of org.jkiss.dbeaver.model.connection.DBPEditorContribution 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

DBPEditorContribution (org.jkiss.dbeaver.model.connection.DBPEditorContribution)4 ArrayList (java.util.ArrayList)2 ISelection (org.eclipse.jface.viewers.ISelection)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 NotNull (org.jkiss.code.NotNull)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPDataSourceProviderRegistry (org.jkiss.dbeaver.model.connection.DBPDataSourceProviderRegistry)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 ToolDescriptor (org.jkiss.dbeaver.tools.registry.ToolDescriptor)2 IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)2 INavigatorModelView (org.jkiss.dbeaver.ui.navigator.INavigatorModelView)2