Search in sources :

Example 1 with DataTransferWizard

use of org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard in project dbeaver by serge-rider.

the class DataTransferHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection ss = (IStructuredSelection) selection;
    final List<IDataTransferProducer> producers = new ArrayList<>();
    final List<IDataTransferConsumer> consumers = new ArrayList<>();
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        IDataTransferNode node = adaptTransferNode(object);
        if (node instanceof IDataTransferProducer) {
            producers.add((IDataTransferProducer) node);
        } else if (node instanceof IDataTransferConsumer) {
            consumers.add((IDataTransferConsumer) node);
        }
    }
    if (!consumers.isEmpty()) {
        // We need to choose producer for consumers
        for (IDataTransferConsumer consumer : consumers) {
            IDataTransferProducer producer = chooseProducer(event, consumer);
            if (producer == null) {
                return null;
            }
            producers.add(producer);
        }
    }
    // Run transfer wizard
    if (!producers.isEmpty() || !consumers.isEmpty()) {
        ActiveWizardDialog dialog = new ActiveWizardDialog(workbenchWindow, new DataTransferWizard(producers.toArray(new IDataTransferProducer[producers.size()]), consumers.toArray(new IDataTransferConsumer[consumers.size()])));
        dialog.open();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferNode(org.jkiss.dbeaver.tools.transfer.IDataTransferNode) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 2 with DataTransferWizard

use of org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard in project dbeaver by serge-rider.

the class ResultSetViewer method fillContextMenu.

@Override
public void fillContextMenu(@NotNull IMenuManager manager, @Nullable final DBDAttributeBinding attr, @Nullable final ResultSetRow row) {
    final DBPDataSource dataSource = getDataSource();
    // Custom oldValue items
    final ResultSetValueController valueController;
    final Object value;
    if (attr != null && row != null) {
        valueController = new ResultSetValueController(this, attr, row, IValueController.EditType.NONE, null);
        value = valueController.getValue();
    } else {
        valueController = null;
        value = null;
    }
    {
        {
            // Standard items
            manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_CUT));
            manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_COPY));
            MenuManager extCopyMenu = new MenuManager(ActionUtils.findCommandName(ResultSetCopySpecialHandler.CMD_COPY_SPECIAL));
            extCopyMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCopySpecialHandler.CMD_COPY_SPECIAL));
            extCopyMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_COPY_COLUMN_NAMES));
            if (row != null) {
                extCopyMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_COPY_ROW_NAMES));
            }
            manager.add(extCopyMenu);
            if (valueController != null) {
                manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_PASTE));
                manager.add(ActionUtils.makeCommandContribution(site, CoreCommands.CMD_PASTE_SPECIAL));
                manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_DELETE));
                // Edit items
                manager.add(new Separator());
                manager.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_EDIT));
                manager.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_EDIT_INLINE));
                if (!valueController.isReadOnly() && !DBUtils.isNullValue(value)) /* && !attr.isRequired()*/
                {
                    manager.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_CELL_SET_NULL));
                }
            }
            manager.add(new GroupMarker(MENU_GROUP_EDIT));
        }
        if (valueController != null) {
            // Menus from value handler
            try {
                manager.add(new Separator());
                valueController.getValueManager().contributeActions(manager, valueController, null);
            } catch (Exception e) {
                log.error(e);
            }
            if (row.getState() == ResultSetRow.STATE_REMOVED || (row.changes != null && row.changes.containsKey(attr))) {
                manager.insertAfter(IResultSetController.MENU_GROUP_EDIT, ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_CELL_RESET));
            }
        }
    }
    if (dataSource != null && attr != null && model.getVisibleAttributeCount() > 0 && !model.isUpdateInProgress()) {
        // Filters and View
        manager.add(new Separator());
        {
            String filtersShortcut = ActionUtils.findCommandDescription(ResultSetCommandHandler.CMD_FILTER_MENU, getSite(), true);
            String menuName = CoreMessages.controls_resultset_viewer_action_order_filter;
            if (!CommonUtils.isEmpty(filtersShortcut)) {
                menuName += " (" + filtersShortcut + ")";
            }
            MenuManager filtersMenu = new MenuManager(menuName, DBeaverIcons.getImageDescriptor(UIIcon.FILTER), //$NON-NLS-1$
            "filters");
            filtersMenu.setRemoveAllWhenShown(true);
            filtersMenu.addMenuListener(new IMenuListener() {

                @Override
                public void menuAboutToShow(IMenuManager manager) {
                    fillFiltersMenu(attr, manager);
                }
            });
            manager.add(filtersMenu);
        }
        {
            MenuManager viewMenu = new MenuManager("View/Format", null, //$NON-NLS-1$
            "view");
            List<? extends DBDAttributeTransformerDescriptor> transformers = dataSource.getContainer().getPlatform().getValueHandlerRegistry().findTransformers(dataSource, attr, null);
            if (!CommonUtils.isEmpty(transformers)) {
                MenuManager transformersMenu = new MenuManager("View as");
                transformersMenu.setRemoveAllWhenShown(true);
                transformersMenu.addMenuListener(new IMenuListener() {

                    @Override
                    public void menuAboutToShow(IMenuManager manager) {
                        fillAttributeTransformersMenu(manager, attr);
                    }
                });
                viewMenu.add(transformersMenu);
            } else {
                final Action customizeAction = new Action("View as") {
                };
                customizeAction.setEnabled(false);
                viewMenu.add(customizeAction);
            }
            if (getModel().isSingleSource()) {
                if (valueController != null) {
                    viewMenu.add(new SetRowColorAction(attr, valueController.getValue()));
                    if (getModel().hasColorMapping(attr)) {
                        viewMenu.add(new ResetRowColorAction(attr, valueController.getValue()));
                    }
                }
                viewMenu.add(new CustomizeColorsAction(attr, row));
                viewMenu.add(new Separator());
            }
            viewMenu.add(new Action("Data formats ...") {

                @Override
                public void run() {
                    UIUtils.showPreferencesFor(getControl().getShell(), null, PrefPageDataFormat.PAGE_ID);
                }
            });
            manager.add(viewMenu);
        }
        {
            // Navigate
            MenuManager navigateMenu = new MenuManager("Navigate", null, //$NON-NLS-1$
            "navigate");
            if (ActionUtils.isCommandEnabled(ResultSetCommandHandler.CMD_NAVIGATE_LINK, site)) {
                navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_NAVIGATE_LINK));
                navigateMenu.add(new Separator());
            }
            navigateMenu.add(new Separator());
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ITextEditorActionDefinitionIds.LINE_GOTO));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_FIRST));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_NEXT));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_PREVIOUS));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_LAST));
            navigateMenu.add(new Separator());
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_FETCH_PAGE));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_FETCH_ALL));
            if (isHasMoreData() && getDataContainer() != null && (getDataContainer().getSupportedFeatures() & DBSDataContainer.DATA_COUNT) != 0) {
                navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_COUNT));
            }
            manager.add(navigateMenu);
        }
        {
            // Layout
            MenuManager layoutMenu = new MenuManager("Layout", null, //$NON-NLS-1$
            "layout");
            layoutMenu.add(new ToggleModeAction());
            layoutMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_TOGGLE_PANELS));
            layoutMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_SWITCH_PRESENTATION));
            {
                layoutMenu.add(new Separator());
                for (IContributionItem item : fillPanelsMenu()) {
                    layoutMenu.add(item);
                }
            }
            manager.add(layoutMenu);
        }
        manager.add(new Separator());
    }
    // Fill general menu
    final DBSDataContainer dataContainer = getDataContainer();
    if (dataContainer != null && model.hasData()) {
        manager.add(new Action(CoreMessages.controls_resultset_viewer_action_export, DBeaverIcons.getImageDescriptor(UIIcon.EXPORT)) {

            @Override
            public void run() {
                ActiveWizardDialog dialog = new ActiveWizardDialog(site.getWorkbenchWindow(), new DataTransferWizard(new IDataTransferProducer[] { new DatabaseTransferProducer(dataContainer, model.getDataFilter()) }, null), getSelection());
                dialog.open();
            }
        });
    }
    manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
    if (dataContainer != null && model.hasData()) {
        manager.add(new Separator());
        manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.FILE_REFRESH));
    }
    manager.add(new Separator());
    manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
Also used : DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) List(java.util.List)

Example 3 with DataTransferWizard

use of org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard in project dbeaver by dbeaver.

the class DataTransferHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection ss = (IStructuredSelection) selection;
    final List<IDataTransferProducer> producers = new ArrayList<>();
    final List<IDataTransferConsumer> consumers = new ArrayList<>();
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        IDataTransferNode node = adaptTransferNode(object);
        if (node instanceof IDataTransferProducer) {
            producers.add((IDataTransferProducer) node);
        } else if (node instanceof IDataTransferConsumer) {
            consumers.add((IDataTransferConsumer) node);
        }
    }
    if (!consumers.isEmpty()) {
        // We need to choose producer for consumers
        for (IDataTransferConsumer consumer : consumers) {
            IDataTransferProducer producer = chooseProducer(event, consumer);
            if (producer == null) {
                return null;
            }
            producers.add(producer);
        }
    }
    // Run transfer wizard
    if (!producers.isEmpty() || !consumers.isEmpty()) {
        ActiveWizardDialog dialog = new ActiveWizardDialog(workbenchWindow, new DataTransferWizard(producers.toArray(new IDataTransferProducer[producers.size()]), consumers.toArray(new IDataTransferConsumer[consumers.size()])));
        dialog.open();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferNode(org.jkiss.dbeaver.tools.transfer.IDataTransferNode) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 4 with DataTransferWizard

use of org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard in project dbeaver by dbeaver.

the class ResultSetCommandHandler method execute.

@Nullable
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ResultSetViewer rsv = (ResultSetViewer) getActiveResultSet(HandlerUtil.getActivePart(event));
    if (rsv == null) {
        return null;
    }
    String actionId = event.getCommand().getId();
    IResultSetPresentation presentation = rsv.getActivePresentation();
    switch(actionId) {
        case IWorkbenchCommandConstants.FILE_REFRESH:
            rsv.refreshData(null);
            break;
        case CMD_TOGGLE_MODE:
            rsv.toggleMode();
            break;
        case CMD_TOGGLE_PANELS:
            rsv.showPanels(!rsv.isPanelsVisible());
            break;
        case CMD_FOCUS_FILTER:
            rsv.switchFilterFocus();
            break;
        case CMD_SWITCH_PRESENTATION:
            rsv.switchPresentation();
            break;
        case CMD_ROW_PREVIOUS:
        case ITextEditorActionDefinitionIds.WORD_PREVIOUS:
            presentation.scrollToRow(IResultSetPresentation.RowPosition.PREVIOUS);
            break;
        case CMD_ROW_NEXT:
        case ITextEditorActionDefinitionIds.WORD_NEXT:
            presentation.scrollToRow(IResultSetPresentation.RowPosition.NEXT);
            break;
        case CMD_ROW_FIRST:
        case ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS:
            presentation.scrollToRow(IResultSetPresentation.RowPosition.FIRST);
            break;
        case CMD_ROW_LAST:
        case ITextEditorActionDefinitionIds.SELECT_WORD_NEXT:
            presentation.scrollToRow(IResultSetPresentation.RowPosition.LAST);
            break;
        case CMD_FETCH_PAGE:
            rsv.readNextSegment();
            break;
        case CMD_FETCH_ALL:
            rsv.readAllData();
            break;
        case CMD_ROW_EDIT:
            if (presentation instanceof IResultSetEditor) {
                ((IResultSetEditor) presentation).openValueEditor(false);
            }
            break;
        case CMD_ROW_EDIT_INLINE:
            if (presentation instanceof IResultSetEditor) {
                ((IResultSetEditor) presentation).openValueEditor(true);
            }
            break;
        case CMD_ROW_ADD:
        case CMD_ROW_COPY:
            {
                boolean copy = actionId.equals(CMD_ROW_COPY);
                boolean shiftPressed = event.getTrigger() instanceof Event && ((((Event) event.getTrigger()).stateMask & SWT.SHIFT) == SWT.SHIFT);
                boolean insertAfter = rsv.getPreferenceStore().getBoolean(DBeaverPreferences.RS_EDIT_NEW_ROWS_AFTER);
                if (shiftPressed)
                    insertAfter = !insertAfter;
                rsv.addNewRow(copy, insertAfter, true);
                if (insertAfter) {
                    presentation.scrollToRow(IResultSetPresentation.RowPosition.NEXT);
                }
                break;
            }
        case CMD_ROW_DELETE:
        case IWorkbenchCommandConstants.EDIT_DELETE:
            rsv.deleteSelectedRows();
            break;
        case CMD_CELL_SET_NULL:
        case CMD_CELL_RESET:
            {
                IResultSetSelection selection = rsv.getSelection();
                for (Object cell : selection.toArray()) {
                    DBDAttributeBinding attr = selection.getElementAttribute(cell);
                    ResultSetRow row = selection.getElementRow(cell);
                    if (row != null && attr != null) {
                        ResultSetValueController valueController = new ResultSetValueController(rsv, attr, row, IValueController.EditType.NONE, null);
                        if (actionId.equals(CMD_CELL_SET_NULL)) {
                            valueController.updateValue(BaseValueManager.makeNullValue(valueController), false);
                        } else {
                            rsv.getModel().resetCellValue(attr, row);
                        }
                    }
                }
                rsv.redrawData(false, false);
                rsv.updatePanelsContent(false);
                break;
            }
        case CMD_APPLY_CHANGES:
            rsv.applyChanges(null);
            break;
        case CMD_REJECT_CHANGES:
            rsv.rejectChanges();
            break;
        case CMD_GENERATE_SCRIPT:
            {
                try {
                    final List<DBEPersistAction> sqlScript = new ArrayList<>();
                    try {
                        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                            @Override
                            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                List<DBEPersistAction> script = rsv.generateChangesScript(monitor);
                                if (script != null) {
                                    sqlScript.addAll(script);
                                }
                            }
                        });
                    } catch (InterruptedException e) {
                    // ignore
                    }
                    if (!sqlScript.isEmpty()) {
                        String scriptText = SQLUtils.generateScript(rsv.getDataContainer() == null ? null : rsv.getDataContainer().getDataSource(), sqlScript.toArray(new DBEPersistAction[sqlScript.size()]), false);
                        scriptText = SQLUtils.generateCommentLine(rsv.getExecutionContext() == null ? null : rsv.getExecutionContext().getDataSource(), "Actual parameter values may differ, what you see is a default string representation of values") + scriptText;
                        ViewSQLDialog dialog = new ViewSQLDialog(HandlerUtil.getActivePart(event).getSite(), rsv.getExecutionContext(), CoreMessages.editors_entity_dialog_preview_title, UIIcon.SQL_PREVIEW, scriptText);
                        dialog.open();
                    }
                } catch (InvocationTargetException e) {
                    DBUserInterface.getInstance().showError("Script generation", "Can't generate changes script", e.getTargetException());
                }
                break;
            }
        case CMD_COPY_COLUMN_NAMES:
            {
                ResultSetCopySpecialHandler.CopyConfigDialog configDialog = new ResultSetCopySpecialHandler.CopyConfigDialog(HandlerUtil.getActiveShell(event), "CopyGridNamesOptionsDialog");
                if (configDialog.open() != IDialogConstants.OK_ID) {
                    return null;
                }
                StringBuilder buffer = new StringBuilder();
                IResultSetSelection selection = rsv.getSelection();
                Collection<DBDAttributeBinding> attrs = selection.isEmpty() ? rsv.getModel().getVisibleAttributes() : selection.getSelectedAttributes();
                for (DBDAttributeBinding attr : attrs) {
                    if (buffer.length() > 0) {
                        buffer.append(configDialog.copySettings.getColumnDelimiter());
                    }
                    String colName = attr.getLabel();
                    if (CommonUtils.isEmpty(colName)) {
                        colName = attr.getName();
                    }
                    buffer.append(colName);
                }
                ResultSetUtils.copyToClipboard(buffer.toString());
                break;
            }
        case CMD_COPY_ROW_NAMES:
            {
                ResultSetCopySpecialHandler.CopyConfigDialog configDialog = new ResultSetCopySpecialHandler.CopyConfigDialog(HandlerUtil.getActiveShell(event), "CopyGridNamesOptionsDialog");
                if (configDialog.open() != IDialogConstants.OK_ID) {
                    return null;
                }
                StringBuilder buffer = new StringBuilder();
                IResultSetSelection selection = rsv.getSelection();
                for (ResultSetRow row : selection.getSelectedRows()) {
                    if (buffer.length() > 0) {
                        buffer.append(configDialog.copySettings.getRowDelimiter());
                    }
                    buffer.append(row.getVisualNumber() + 1);
                }
                ResultSetUtils.copyToClipboard(buffer.toString());
                break;
            }
        case IWorkbenchCommandConstants.EDIT_COPY:
            ResultSetUtils.copyToClipboard(presentation.copySelectionToString(new ResultSetCopySettings(false, false, false, true, false, null, null, null, DBDDisplayFormat.EDIT)));
            break;
        case IWorkbenchCommandConstants.EDIT_PASTE:
        case CoreCommands.CMD_PASTE_SPECIAL:
            if (presentation instanceof IResultSetEditor) {
                ((IResultSetEditor) presentation).pasteFromClipboard(actionId.equals(CoreCommands.CMD_PASTE_SPECIAL));
            }
            break;
        case IWorkbenchCommandConstants.EDIT_CUT:
            ResultSetUtils.copyToClipboard(presentation.copySelectionToString(new ResultSetCopySettings(false, false, true, true, false, null, null, null, DBDDisplayFormat.EDIT)));
            break;
        case IWorkbenchCommandConstants.FILE_PRINT:
            presentation.printResultSet();
            break;
        case ITextEditorActionDefinitionIds.SMART_ENTER:
            if (presentation instanceof IResultSetEditor) {
                ((IResultSetEditor) presentation).openValueEditor(false);
            }
            break;
        case IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE:
            FindReplaceAction action = new FindReplaceAction(DBeaverActivator.getCoreResourceBundle(), "Editor.FindReplace.", HandlerUtil.getActiveShell(event), rsv.getAdapter(IFindReplaceTarget.class));
            action.run();
            break;
        case CMD_NAVIGATE_LINK:
            {
                final ResultSetRow row = rsv.getCurrentRow();
                final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
                if (row != null && attr != null) {
                    new AbstractJob("Navigate association") {

                        @Override
                        protected IStatus run(DBRProgressMonitor monitor) {
                            try {
                                rsv.navigateAssociation(monitor, attr, row, false);
                            } catch (DBException e) {
                                return GeneralUtils.makeExceptionStatus(e);
                            }
                            return Status.OK_STATUS;
                        }
                    }.schedule();
                }
                break;
            }
        case CMD_COUNT:
            rsv.updateRowCount();
            break;
        case IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY:
            {
                final int hp = rsv.getHistoryPosition();
                if (hp > 0) {
                    rsv.navigateHistory(hp - 1);
                }
                break;
            }
        case IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY:
            {
                final int hp = rsv.getHistoryPosition();
                if (hp < rsv.getHistorySize() - 1) {
                    rsv.navigateHistory(hp + 1);
                }
                break;
            }
        case ITextEditorActionDefinitionIds.LINE_GOTO:
            {
                ResultSetRow currentRow = rsv.getCurrentRow();
                final int rowCount = rsv.getModel().getRowCount();
                if (rowCount <= 0) {
                    break;
                }
                GotoLineDialog d = new GotoLineDialog(HandlerUtil.getActiveShell(event), "Go to Row", "Enter row number (1.." + rowCount + ")", String.valueOf(currentRow == null ? 1 : currentRow.getVisualNumber() + 1), new IInputValidator() {

                    @Override
                    public String isValid(String input) {
                        try {
                            int i = Integer.parseInt(input);
                            if (i <= 0 || rowCount < i) {
                                return "Row number is out of range";
                            }
                        } catch (NumberFormatException x) {
                            return "Not a number";
                        }
                        return null;
                    }
                });
                if (d.open() == Window.OK) {
                    int line = Integer.parseInt(d.getValue());
                    rsv.setCurrentRow(rsv.getModel().getRow(line - 1));
                    rsv.getActivePresentation().scrollToRow(IResultSetPresentation.RowPosition.CURRENT);
                }
                break;
            }
        case CMD_FILTER_MENU:
            {
                rsv.showFiltersMenu();
                break;
            }
        case CMD_FILTER_MENU_DISTINCT:
            {
                DBDAttributeBinding curAttribute = rsv.getActivePresentation().getCurrentAttribute();
                if (curAttribute != null) {
                    rsv.showFiltersDistinctMenu(curAttribute, true);
                }
                break;
            }
        case CMD_REFERENCES_MENU:
            {
                rsv.showReferencesMenu();
                break;
            }
        case CMD_EXPORT:
            {
                List<Long> selectedRows = new ArrayList<>();
                for (ResultSetRow selectedRow : rsv.getSelection().getSelectedRows()) {
                    selectedRows.add(Long.valueOf(selectedRow.getRowNumber()));
                }
                List<String> selectedAttributes = new ArrayList<>();
                for (DBDAttributeBinding attributeBinding : rsv.getSelection().getSelectedAttributes()) {
                    selectedAttributes.add(attributeBinding.getName());
                }
                ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
                options.setSelectedRows(selectedRows);
                options.setSelectedColumns(selectedAttributes);
                ResultSetDataContainer dataContainer = new ResultSetDataContainer(rsv.getDataContainer(), rsv.getModel(), options);
                ActiveWizardDialog dialog = new ActiveWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event), new DataTransferWizard(new IDataTransferProducer[] { new DatabaseTransferProducer(dataContainer, rsv.getModel().getDataFilter()) }, null), rsv.getSelection());
                dialog.open();
                break;
            }
        case CMD_ZOOM_IN:
        case CMD_ZOOM_OUT:
            {
                FontRegistry fontRegistry = rsv.getSite().getWorkbenchWindow().getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
                Font font = fontRegistry.get(ThemeConstants.FONT_SQL_RESULT_SET);
                if (font != null) {
                    FontData[] fondData = font.getFontData();
                    if (fondData != null) {
                        int zoomFactor = actionId.equals(CMD_ZOOM_IN) ? 1 : -1;
                        FontDescriptor fd = createFontDescriptor(fondData, zoomFactor);
                        fontRegistry.put(ThemeConstants.FONT_SQL_RESULT_SET, fd.getFontData());
                    }
                }
                break;
            }
        case CMD_TOGGLE_ORDER:
            {
                final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
                if (attr != null) {
                    rsv.toggleSortOrder(attr, false, false);
                }
                break;
            }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) FindReplaceAction(org.eclipse.ui.texteditor.FindReplaceAction) FontRegistry(org.eclipse.jface.resource.FontRegistry) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) Font(org.eclipse.swt.graphics.Font) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) List(java.util.List) ArrayList(java.util.ArrayList) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ViewSQLDialog(org.jkiss.dbeaver.ui.dialogs.sql.ViewSQLDialog) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.eclipse.swt.widgets.Event) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) Collection(java.util.Collection) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) Nullable(org.jkiss.code.Nullable)

Aggregations

DataTransferWizard (org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard)4 ActiveWizardDialog (org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog)4 ArrayList (java.util.ArrayList)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 DBException (org.jkiss.dbeaver.DBException)2 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)2 IDataTransferConsumer (org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer)2 IDataTransferNode (org.jkiss.dbeaver.tools.transfer.IDataTransferNode)2 IDataTransferProducer (org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)2 DatabaseTransferProducer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer)2 Collection (java.util.Collection)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 FontDescriptor (org.eclipse.jface.resource.FontDescriptor)1 FontRegistry (org.eclipse.jface.resource.FontRegistry)1 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)1