Search in sources :

Example 51 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project dbeaver by dbeaver.

the class OpenHandler method getDataSourceContainers.

private static List<DBPDataSourceContainer> getDataSourceContainers(ExecutionEvent event) {
    List<DBPDataSourceContainer> containers = new ArrayList<>();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        for (Object obj : ((IStructuredSelection) selection).toArray()) {
            if (obj instanceof DBNLocalFolder) {
                for (DBNDataSource ds : ((DBNLocalFolder) obj).getDataSources()) {
                    containers.add(ds.getDataSourceContainer());
                }
            } else {
                DBSObject selectedObject = DBUtils.getFromObject(obj);
                if (selectedObject != null) {
                    if (selectedObject instanceof DBPDataSourceContainer) {
                        containers.add((DBPDataSourceContainer) selectedObject);
                    } else {
                        containers.add(selectedObject.getDataSource().getContainer());
                    }
                }
            }
        }
    }
    if (containers.isEmpty()) {
        IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
        DBPDataSourceContainer partContainer = getDataSourceContainers(activePart);
        if (partContainer != null) {
            containers.add(partContainer);
        }
    }
    return containers;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 52 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project dbeaver by dbeaver.

the class AbstractDataSourceHandler method getDataSourceContainer.

protected static DBPDataSourceContainer getDataSourceContainer(ExecutionEvent event, boolean useEditor) {
    if (useEditor) {
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        if (editor != null) {
            DBPDataSourceContainer container = getDataSourceContainer(editor);
            if (container != null) {
                return container;
            }
        }
        return null;
    }
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    DBPDataSourceContainer container = getDataSourceContainer(activePart);
    if (container != null) {
        return container;
    }
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
    if (selectedObject instanceof DBPDataSourceContainer) {
        return (DBPDataSourceContainer) selectedObject;
    } else if (selectedObject != null) {
        DBPDataSource dataSource = selectedObject.getDataSource();
        return dataSource == null ? null : dataSource.getContainer();
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 53 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart 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)

Example 54 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project dbeaver by dbeaver.

the class NavigatorHandlerExpandAll method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof NavigatorViewBase) {
        TreeViewer navigatorViewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
        ISelection selection = navigatorViewer.getSelection();
        if (selection.isEmpty()) {
            navigatorViewer.expandAll();
        } else if (selection instanceof IStructuredSelection) {
            for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                navigatorViewer.expandToLevel(iter.next(), TreeViewer.ALL_LEVELS);
            }
        }
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 55 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project dbeaver by dbeaver.

the class NavigatorHandlerLocalFolderCreate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNDataSource> dataSources = new ArrayList<>();
        DBNProjectDatabases databasesNode = null;
        DBNLocalFolder parentFolder = null;
        for (Iterator iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            if (element instanceof DBNDataSource) {
                dataSources.add((DBNDataSource) element);
                element = ((DBNDataSource) element).getParentNode();
            }
            if (element instanceof DBNLocalFolder) {
                parentFolder = (DBNLocalFolder) element;
                databasesNode = parentFolder.getParentNode();
            } else if (element instanceof DBNProjectDatabases) {
                databasesNode = (DBNProjectDatabases) element;
            }
        }
        if (databasesNode != null) {
            createFolder(HandlerUtil.getActiveWorkbenchWindow(event), activePart, databasesNode, parentFolder, dataSources, null);
        }
    }
    return null;
}
Also used : DBNProjectDatabases(org.jkiss.dbeaver.model.navigator.DBNProjectDatabases) DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)289 ISelection (org.eclipse.jface.viewers.ISelection)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)112 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)72 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)69 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)59 IEditorPart (org.eclipse.ui.IEditorPart)57 IFile (org.eclipse.core.resources.IFile)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)44 IResource (org.eclipse.core.resources.IResource)42 PartInitException (org.eclipse.ui.PartInitException)41 ArrayList (java.util.ArrayList)36 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)35 FileEditorInput (org.eclipse.ui.part.FileEditorInput)33 HashMap (java.util.HashMap)32 EObject (org.eclipse.emf.ecore.EObject)31 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)31 URI (org.eclipse.emf.common.util.URI)30 MissingResourceException (java.util.MissingResourceException)29 Resource (org.eclipse.emf.ecore.resource.Resource)29