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;
}
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;
}
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()));
}
}
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;
}
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;
}
Aggregations