Search in sources :

Example 1 with ResultSetViewer

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.

the class CursorViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final IValueController valueController = getValueController();
    value = (DBDCursor) valueController.getValue();
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    if (value != null) {
        DBPPreferenceStore globalPreferenceStore = DBeaverCore.getGlobalPreferenceStore();
        if (!globalPreferenceStore.getBoolean(DBeaverPreferences.KEEP_STATEMENT_OPEN)) {
            if (ConfirmationDialog.showConfirmDialog(getShell(), DBeaverPreferences.CONFIRM_KEEP_STATEMENT_OPEN, ConfirmationDialog.QUESTION) == IDialogConstants.YES_ID) {
                globalPreferenceStore.setValue(DBeaverPreferences.KEEP_STATEMENT_OPEN, true);
                if (valueController.getValueSite().getPart() instanceof IResultSetContainer) {
                    IResultSetController rsv = ((IResultSetContainer) valueController.getValueSite().getPart()).getResultSetController();
                    if (rsv != null) {
                        rsv.refresh();
                    }
                }
            }
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    close();
                }
            });
        }
    }
    resultSetViewer = new ResultSetViewer(dialogGroup, valueController.getValueSite(), this);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.grabExcessVerticalSpace = true;
    resultSetViewer.getControl().setLayoutData(gd);
    resultSetViewer.refresh();
    return dialogGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IResultSetContainer(org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer) GridData(org.eclipse.swt.layout.GridData) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) IValueController(org.jkiss.dbeaver.ui.data.IValueController) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 2 with ResultSetViewer

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.

the class SQLEditor method processQueries.

private void processQueries(@NotNull final List<SQLQuery> queries, final boolean newTab, final boolean export, final boolean checkSession) {
    if (queries.isEmpty()) {
        // Nothing to process
        return;
    }
    final DBPDataSourceContainer container = getDataSourceContainer();
    if (checkSession) {
        try {
            DBRProgressListener connectListener = new DBRProgressListener() {

                @Override
                public void onTaskFinished(IStatus status) {
                    if (!status.isOK() || container == null || !container.isConnected()) {
                        UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, null, status);
                        return;
                    }
                    // Make a small pause to let all UI connection listeners to finish
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    // it's ok
                    }
                    DBeaverUI.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            processQueries(queries, newTab, export, false);
                        }
                    });
                }
            };
            if (!checkSession(connectListener)) {
                return;
            }
        } catch (DBException ex) {
            ResultSetViewer viewer = getActiveResultSetViewer();
            if (viewer != null) {
                viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
            }
            UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
            return;
        }
    }
    if (sashForm.getMaximizedControl() != null) {
        sashForm.setMaximizedControl(null);
    }
    // Save editor
    if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
        doSave(new NullProgressMonitor());
    }
    final boolean isSingleQuery = (queries.size() == 1);
    if (!newTab || !isSingleQuery) {
        // We don't need new tab or we are executing a script - so close all extra tabs
        closeExtraResultTabs(null);
    }
    if (newTab) {
        // Execute each query in a new tab
        for (int i = 0; i < queries.size(); i++) {
            SQLQuery query = queries.get(i);
            QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
            queryProcessor.processQueries(Collections.singletonList(query), true, export);
        }
    } else {
        // Use current tab.
        // If current tab was pinned then use first tab
        final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
        if (firstResults.isPinned()) {
            curQueryProcessor = queryProcessors.get(0);
        }
        closeExtraResultTabs(curQueryProcessor);
        if (firstResults.tabItem != null) {
            resultTabs.setSelection(firstResults.tabItem);
        }
        curQueryProcessor.processQueries(queries, false, export);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) Point(org.eclipse.swt.graphics.Point) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 3 with ResultSetViewer

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.

the class SQLEditor method onDataSourceChange.

private void onDataSourceChange() {
    updateExecutionContext();
    if (sashForm == null || sashForm.isDisposed()) {
        reloadSyntaxRules();
        return;
    }
    DatabaseEditorUtils.setPartBackground(this, sashForm);
    DBCExecutionContext executionContext = getExecutionContext();
    if (syntaxLoaded && lastExecutionContext == executionContext) {
        return;
    }
    for (QueryProcessor queryProcessor : queryProcessors) {
        for (QueryResultsContainer resultsProvider : queryProcessor.getResultContainers()) {
            ResultSetViewer rsv = resultsProvider.getResultSetController();
            if (rsv != null) {
                if (executionContext == null) {
                    rsv.setStatus(CoreMessages.editors_sql_status_not_connected_to_database);
                } else {
                    //$NON-NLS-2$
                    rsv.setStatus(CoreMessages.editors_sql_staus_connected_to + executionContext.getDataSource().getContainer().getName() + "'");
                }
            }
        }
    }
    // Update command states
    SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXECUTE);
    SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXPLAIN);
    reloadSyntaxRules();
    if (getDataSourceContainer() == null) {
        sashForm.setMaximizedControl(editorControl);
    } else {
        sashForm.setMaximizedControl(null);
    }
    lastExecutionContext = executionContext;
    syntaxLoaded = true;
}
Also used : ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 4 with ResultSetViewer

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.

the class ValueViewCommandHandler method execute.

@Nullable
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ResultSetViewer rsv = (ResultSetViewer) ResultSetCommandHandler.getActiveResultSet(HandlerUtil.getActivePart(event));
    if (rsv == null) {
        return null;
    }
    String actionId = event.getCommand().getId();
    IResultSetPanel visiblePanel = rsv.getVisiblePanel();
    if (visiblePanel instanceof ViewValuePanel) {
        switch(actionId) {
            case ITextEditorActionDefinitionIds.SMART_ENTER:
            case CoreCommands.CMD_EXECUTE_STATEMENT:
            case CMD_SAVE_VALUE:
                ((ViewValuePanel) visiblePanel).saveValue();
                break;
        }
    }
    return null;
}
Also used : IResultSetPanel(org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) Nullable(org.jkiss.code.Nullable)

Example 5 with ResultSetViewer

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.

the class DatabaseDataEditor method createResultSetView.

private void createResultSetView() {
    if (resultSetView == null) {
        resultSetView = new ResultSetViewer(parent, getSite(), this);
        resultSetView.addListener(this);
        parent.layout();
        resultSetView.getControl().setFocus();
        // Set selection provider from resultset
        getSite().setSelectionProvider(resultSetView);
    }
}
Also used : ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Aggregations

ResultSetViewer (org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)6 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 DBRProgressListener (org.jkiss.dbeaver.model.runtime.DBRProgressListener)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Composite (org.eclipse.swt.widgets.Composite)1 Nullable (org.jkiss.code.Nullable)1 DBException (org.jkiss.dbeaver.DBException)1 DBPPreferenceListener (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)1 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)1 SQLQuery (org.jkiss.dbeaver.model.sql.SQLQuery)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 SQLQueryListener (org.jkiss.dbeaver.runtime.sql.SQLQueryListener)1 IResultSetContainer (org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer)1 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)1 IResultSetListener (org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener)1 IResultSetPanel (org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel)1 IValueController (org.jkiss.dbeaver.ui.data.IValueController)1