Search in sources :

Example 26 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project dbeaver by serge-rider.

the class ResultSetHandlerCopyAs method fillCopyAsMenu.

public static void fillCopyAsMenu(ResultSetViewer viewer, IContributionManager copyAsMenu) {
    IWorkbenchPartSite site = viewer.getSite();
    copyAsMenu.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerCopySpecial.CMD_COPY_SPECIAL));
    copyAsMenu.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerCopySpecial.CMD_COPY_COLUMN_NAMES));
    copyAsMenu.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_COPY_ROW_NAMES));
    // Add copy commands for different formats
    copyAsMenu.add(new Separator());
    ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
    ResultSetDataContainer dataContainer = new ResultSetDataContainer(viewer, options);
    List<DataTransferProcessorDescriptor> appProcessors = new ArrayList<>();
    for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getAvailableConsumers(Collections.singleton(dataContainer))) {
        for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
            if (processor.isBinaryFormat()) {
                continue;
            }
            appProcessors.add(processor);
        }
    }
    appProcessors.sort(Comparator.comparing(DataTransferProcessorDescriptor::getName));
    for (DataTransferProcessorDescriptor processor : appProcessors) {
        CommandContributionItemParameter params = new CommandContributionItemParameter(site, processor.getId(), ResultSetHandlerCopyAs.CMD_COPY_AS, CommandContributionItem.STYLE_PUSH);
        params.label = processor.getName();
        if (processor.getIcon() != null) {
            params.icon = DBeaverIcons.getImageDescriptor(processor.getIcon());
        }
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(ResultSetHandlerCopyAs.PARAM_PROCESSOR_ID, processor.getFullId());
        params.parameters = parameters;
        copyAsMenu.add(new CommandContributionItem(params));
    }
}
Also used : DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 27 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project dbeaver by serge-rider.

the class ResultSetHandlerOpenWith method fillOpenWithMenu.

public static void fillOpenWithMenu(ResultSetViewer viewer, IContributionManager openWithMenu) {
    ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
    ResultSetDataContainer dataContainer = new ResultSetDataContainer(viewer, options);
    List<DataTransferProcessorDescriptor> appProcessors = new ArrayList<>();
    for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getAvailableConsumers(Collections.singleton(dataContainer))) {
        for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
            if (processor.getAppFileExtension() != null) {
                appProcessors.add(processor);
            }
        }
    }
    appProcessors.sort(Comparator.comparingInt(DataTransferProcessorDescriptor::getOrder));
    for (DataTransferProcessorDescriptor processor : appProcessors) {
        CommandContributionItemParameter params = new CommandContributionItemParameter(viewer.getSite(), processor.getId(), ResultSetHandlerOpenWith.CMD_OPEN_WITH, CommandContributionItem.STYLE_RADIO);
        params.label = processor.getAppName();
        if (processor.getIcon() != null) {
            params.icon = DBeaverIcons.getImageDescriptor(processor.getIcon());
        }
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(ResultSetHandlerOpenWith.PARAM_PROCESSOR_ID, processor.getFullId());
        params.parameters = parameters;
        openWithMenu.add(new CommandContributionItem(params));
    }
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 28 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project dbeaver by serge-rider.

the class ResultSetViewer method fillPanelsMenu.

private List<IContributionItem> fillPanelsMenu() {
    List<IContributionItem> items = new ArrayList<>();
    for (final ResultSetPanelDescriptor panel : availablePanels) {
        CommandContributionItemParameter params = new CommandContributionItemParameter(site, panel.getId(), ResultSetHandlerTogglePanel.CMD_TOGGLE_PANEL, CommandContributionItem.STYLE_CHECK);
        Map<String, String> parameters = new HashMap<>();
        parameters.put(ResultSetHandlerTogglePanel.PARAM_PANEL_ID, panel.getId());
        params.parameters = parameters;
        items.add(new CommandContributionItem(params));
    }
    items.add(new Separator());
    // if (viewerSash.getMaximizedControl() == null) {
    // items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_TOGGLE_LAYOUT));
    // }
    items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_TOGGLE_MAXIMIZE));
    // items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_TOGGLE_PANELS));
    items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ACTIVATE_PANELS));
    return items;
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem) ResultSetPanelDescriptor(org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor)

Example 29 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project dbeaver by serge-rider.

the class ActionUtils method makeCommandContribution.

public static CommandContributionItem makeCommandContribution(@NotNull IServiceLocator serviceLocator, @NotNull String commandId, int style, @Nullable String name, @Nullable DBPImage image, @Nullable String toolTip, boolean showText, @Nullable Map<String, Object> parameters) {
    final CommandContributionItemParameter contributionParameters = new CommandContributionItemParameter(serviceLocator, null, commandId, null, image == null ? null : DBeaverIcons.getImageDescriptor(image), null, null, name, null, toolTip, style, null, false);
    contributionParameters.parameters = parameters;
    if (showText) {
        contributionParameters.mode = CommandContributionItem.MODE_FORCE_TEXT;
    }
    return new CommandContributionItem(contributionParameters);
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 30 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateNew method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String objectType = event.getParameter(NavigatorCommands.PARAM_OBJECT_TYPE);
    boolean isFolder = CommonUtils.toBoolean(event.getParameter(NavigatorCommands.PARAM_OBJECT_TYPE_FOLDER));
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node != null) {
        Class<?> newObjectType = null;
        if (objectType != null) {
            if (node instanceof DBNDatabaseNode) {
                newObjectType = ((DBNDatabaseNode) node).getMeta().getSource().getObjectClass(objectType);
            } else {
                try {
                    newObjectType = Class.forName(objectType);
                } catch (ClassNotFoundException e) {
                    log.error("Error detecting new object type " + objectType, e);
                }
            }
        } else {
            // No explicit object type. Try to detect from selection
            IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
            if (activePart != null) {
                List<IContributionItem> actions = fillCreateMenuItems(activePart.getSite(), node);
                for (IContributionItem item : actions) {
                    if (item instanceof CommandContributionItem) {
                        ParameterizedCommand command = ((CommandContributionItem) item).getCommand();
                        if (command != null) {
                            ActionUtils.runCommand(command.getId(), selection, command.getParameterMap(), activePart.getSite());
                            return null;
                        }
                    }
                }
            }
        }
        createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), node, newObjectType, null, isFolder);
    }
    return null;
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) ISelection(org.eclipse.jface.viewers.ISelection) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Aggregations

CommandContributionItem (org.eclipse.ui.menus.CommandContributionItem)31 CommandContributionItemParameter (org.eclipse.ui.menus.CommandContributionItemParameter)25 IContributionItem (org.eclipse.jface.action.IContributionItem)10 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)4 Separator (org.eclipse.jface.action.Separator)3 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)2 MenuManager (org.eclipse.jface.action.MenuManager)2 IMenuService (org.eclipse.ui.menus.IMenuService)2 UserRefactoringInfo (org.erlide.wrangler.refactoring.backend.UserRefactoringInfo)2 DBException (org.jkiss.dbeaver.DBException)2 DatabaseLoadService (org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService)2 DataTransferNodeDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)2 DataTransferProcessorDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 List (java.util.List)1