Search in sources :

Example 51 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class EditForeignKeyPage method handleRefTableSelect.

private void handleRefTableSelect(ISelection selection) {
    DBNDatabaseNode refTableNode = null;
    if (!selection.isEmpty() && selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
        final Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof DBNDatabaseNode && ((DBNDatabaseNode) element).getObject() instanceof DBSTable && ((DBNDatabaseNode) element).getObject().isPersisted()) {
            refTableNode = (DBNDatabaseNode) element;
        }
    }
    if (refTableNode != null) {
        if (refTableNode.getObject() == curRefTable) {
            // The same selection
            return;
        } else {
            curRefTable = (DBSTable) refTableNode.getObject();
        }
    }
    uniqueKeyCombo.removeAll();
    try {
        curConstraints = new ArrayList<>();
        curConstraint = null;
        if (refTableNode != null) {
            final DBSTable refTable = (DBSTable) refTableNode.getObject();
            DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        // Cache own table columns
                        ownTable.getAttributes(monitor);
                        // Cache ref table columns
                        refTable.getAttributes(monitor);
                        // Get constraints
                        final Collection<? extends DBSTableConstraint> constraints = refTable.getConstraints(monitor);
                        if (!CommonUtils.isEmpty(constraints)) {
                            for (DBSTableConstraint constraint : constraints) {
                                if (constraint.getConstraintType().isUnique()) {
                                    curConstraints.add(constraint);
                                }
                            }
                        }
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            });
        }
        for (DBSTableConstraint constraint : curConstraints) {
            uniqueKeyCombo.add(constraint.getName());
        }
        uniqueKeyCombo.select(0);
        uniqueKeyCombo.setEnabled(curConstraints.size() > 1);
        if (curConstraints.size() == 1) {
            curConstraint = curConstraints.get(0);
        }
    } catch (InvocationTargetException e) {
        DBUserInterface.getInstance().showError(CoreMessages.dialog_struct_edit_fk_error_load_constraints_title, CoreMessages.dialog_struct_edit_fk_error_load_constraints_message, e.getTargetException());
    } catch (InterruptedException e) {
    // do nothing
    }
    handleUniqueKeySelect();
    updatePageState();
}
Also used : DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 52 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class SQLEditor method explainPlanFromQuery.

private void explainPlanFromQuery(final DBCQueryPlanner planner, final SQLQuery sqlQuery) {
    final String[] planQueryString = new String[1];
    DBRRunnableWithProgress queryObtainTask = monitor -> {
        try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Prepare plan query")) {
            DBCPlan plan = planner.planQueryExecution(session, sqlQuery.getText());
            planQueryString[0] = plan.getPlanQueryString();
        } catch (Exception e) {
            log.error(e);
        }
    };
    if (RuntimeUtils.runTask(queryObtainTask, "Retrieve plan query", 5000) && !CommonUtils.isEmpty(planQueryString[0])) {
        SQLQuery planQuery = new SQLQuery(getDataSource(), planQueryString[0]);
        processQueries(Collections.singletonList(planQuery), true, false, true, null);
    }
}
Also used : StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) IResultSetListener(org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) SashForm(org.eclipse.swt.custom.SashForm) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) StyledText(org.eclipse.swt.custom.StyledText) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SQLQueryListener(org.jkiss.dbeaver.runtime.sql.SQLQueryListener) SQLQueryJob(org.jkiss.dbeaver.runtime.sql.SQLQueryJob) SQLResultsView(org.jkiss.dbeaver.ui.views.SQLResultsView) org.eclipse.jface.text(org.eclipse.jface.text) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) Point(org.eclipse.swt.graphics.Point) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) IOUtils(org.jkiss.utils.IOUtils) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) URI(java.net.URI) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) EFS(org.eclipse.core.filesystem.EFS) ExplainPlanViewer(org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) IFileState(org.eclipse.core.resources.IFileState) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBeaverPreferences(org.jkiss.dbeaver.DBeaverPreferences) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) DBUserInterface(org.jkiss.dbeaver.runtime.ui.DBUserInterface) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) DataSourceHandler(org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler) IProject(org.eclipse.core.resources.IProject) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IResultSetContainer(org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) IFileStore(org.eclipse.core.filesystem.IFileStore) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) org.eclipse.swt.widgets(org.eclipse.swt.widgets) ArrayUtils(org.jkiss.utils.ArrayUtils) CTabItem(org.eclipse.swt.custom.CTabItem) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.jkiss.dbeaver.core(org.jkiss.dbeaver.core) org.eclipse.core.runtime(org.eclipse.core.runtime) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBException(org.jkiss.dbeaver.DBException)

Example 53 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress 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)

Example 54 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class ResultSetFilterPanel method getProposals.

@Override
public IContentProposal[] getProposals(String contents, int position) {
    SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
    if (viewer.getDataContainer() != null) {
        syntaxManager.init(viewer.getDataContainer().getDataSource());
    }
    SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
    final String word = wordDetector.getFullWord().toLowerCase(Locale.ENGLISH);
    final List<IContentProposal> proposals = new ArrayList<>();
    final DBRRunnableWithProgress reader = new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            for (DBDAttributeBinding attribute : viewer.getModel().getAttributes()) {
                final String name = DBUtils.getUnQuotedIdentifier(attribute.getDataSource(), attribute.getName());
                if (CommonUtils.isEmpty(word) || name.toLowerCase(Locale.ENGLISH).startsWith(word)) {
                    final String content = DBUtils.getQuotedIdentifier(attribute) + " ";
                    proposals.add(new ContentProposal(content, attribute.getName(), SQLContextInformer.makeObjectDescription(monitor, attribute.getAttribute(), false), content.length()));
                }
            }
        }
    };
    SystemJob searchJob = new SystemJob("Extract attribute proposals", reader);
    searchJob.schedule();
    UIUtils.waitJobCompletion(searchJob);
    return proposals.toArray(new IContentProposal[proposals.size()]);
}
Also used : ContentProposal(org.eclipse.jface.fieldassist.ContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SQLWordPartDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLWordPartDetector) SQLSyntaxManager(org.jkiss.dbeaver.model.sql.SQLSyntaxManager) ArrayList(java.util.ArrayList) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Document(org.eclipse.jface.text.Document) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 55 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.

the class SQLObjectResolver method resolveAll.

@Override
protected String[] resolveAll(final TemplateContext context) {
    final List<T> entities = new ArrayList<>();
    if (context instanceof DBPContextProvider) {
        final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
        if (executionContext != null) {
            RuntimeUtils.runTask(new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        resolveObjects(monitor, executionContext, context, entities);
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            }, "Resolve object references", 1000);
        }
    }
    if (!CommonUtils.isEmpty(entities)) {
        String[] result = new String[entities.size()];
        for (int i = 0; i < entities.size(); i++) {
            T entity = entities.get(i);
            result[i] = entity.getName();
        }
        return result;
    }
    return super.resolveAll(context);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)64 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)58 DBException (org.jkiss.dbeaver.DBException)36 ArrayList (java.util.ArrayList)11 IFile (org.eclipse.core.resources.IFile)11 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)11 CoreException (org.eclipse.core.runtime.CoreException)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)10 List (java.util.List)9 NotNull (org.jkiss.code.NotNull)9 Nullable (org.jkiss.code.Nullable)9 CommonUtils (org.jkiss.utils.CommonUtils)8 File (java.io.File)7 Collection (java.util.Collection)7 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)7 Log (org.jkiss.dbeaver.Log)6 InputStream (java.io.InputStream)5 IResource (org.eclipse.core.resources.IResource)5 SWT (org.eclipse.swt.SWT)5