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