Search in sources :

Example 11 with SQLNavigatorContext

use of org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext in project dbeaver by serge-rider.

the class ViewSQLDialog method buttonPressed.

@Override
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OPEN_ID) {
        String title = getTitle();
        String text = getText();
        UIUtils.asyncExec(() -> {
            SQLEditorHandlerOpenEditor.openSQLConsole(UIUtils.getActiveWorkbenchWindow(), new SQLNavigatorContext(contextProvider.getExecutionContext()), title, text);
        });
        close();
    } else if (buttonId == IDialogConstants.PROCEED_ID) {
        setReturnCode(IDialogConstants.PROCEED_ID);
        close();
    } else {
        super.buttonPressed(buttonId);
    }
}
Also used : SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext)

Example 12 with SQLNavigatorContext

use of org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext in project dbeaver by dbeaver.

the class SQLEditor method setDataSourceContainer.

@Override
public boolean setDataSourceContainer(@Nullable DBPDataSourceContainer container) {
    if (container == dataSourceContainer) {
        return true;
    }
    // Release ds container
    releaseContainer();
    closeAllJobs();
    dataSourceContainer = container;
    if (dataSourceContainer != null) {
        dataSourceContainer.getPreferenceStore().addPropertyChangeListener(this);
        dataSourceContainer.getRegistry().addDataSourceListener(this);
    }
    IEditorInput input = getEditorInput();
    if (input != null) {
        DBPDataSourceContainer savedContainer = EditorUtils.getInputDataSource(input);
        if (savedContainer != container) {
            EditorUtils.setInputDataSource(input, new SQLNavigatorContext(container, getExecutionContext()));
        }
        IFile file = EditorUtils.getFileFromInput(input);
        if (file != null) {
            DBNUtils.refreshNavigatorResource(file, container);
        } else {
            // FIXME: this is a hack. We can't fire event on resource change so editor's state won't be updated in UI.
            // FIXME: To update main toolbar and other controls we hade and show this editor
            IWorkbenchPage page = getSite().getPage();
            for (IEditorReference er : page.getEditorReferences()) {
                if (er.getEditor(false) == this) {
                    page.hideEditor(er);
                    page.showEditor(er);
                    break;
                }
            }
        // page.activate(this);
        }
    }
    checkConnected(false, status -> UIUtils.asyncExec(() -> {
        if (!status.isOK()) {
            DBWorkbench.getPlatformUI().showError("Can't connect to database", "Error connecting to datasource", status);
        }
        setFocus();
    }));
    setPartName(getEditorName());
    fireDataSourceChange();
    if (dataSourceContainer != null) {
        dataSourceContainer.acquire(this);
    }
    if (SQLEditorBase.isWriteEmbeddedBinding()) {
        // Patch connection reference
        UIUtils.syncExec(this::embedDataSourceAssociation);
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext)

Example 13 with SQLNavigatorContext

use of org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext in project dbeaver by dbeaver.

the class SQLEditor method onDataSourceChange.

private void onDataSourceChange() {
    if (resultsSash == null || resultsSash.isDisposed()) {
        reloadSyntaxRules();
        return;
    }
    DatabaseEditorUtils.setPartBackground(this, resultTabs);
    if (getSourceViewerConfiguration() instanceof SQLEditorSourceViewerConfiguration) {
        ((SQLEditorSourceViewerConfiguration) getSourceViewerConfiguration()).onDataSourceChange();
    }
    DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext != null) {
        EditorUtils.setInputDataSource(getEditorInput(), new SQLNavigatorContext(executionContext));
    }
    refreshActions();
    if (syntaxLoaded && lastExecutionContext == executionContext) {
        return;
    }
    if (curResultsContainer != null) {
        ResultSetViewer rsv = curResultsContainer.getResultSetController();
        if (rsv != null) {
            if (executionContext == null) {
                rsv.setStatus(ModelMessages.error_not_connected_to_database);
            } else {
                // $NON-NLS-2$
                rsv.setStatus(SQLEditorMessages.editors_sql_staus_connected_to + executionContext.getDataSource().getContainer().getName() + "'");
            }
        }
    }
    if (lastExecutionContext == null || executionContext == null || lastExecutionContext.getDataSource() != executionContext.getDataSource()) {
        // Update command states
        SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXECUTE);
        SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXPLAIN);
        reloadSyntaxRules();
    }
    if (getDataSourceContainer() == null) {
        resultsSash.setMaximizedControl(sqlEditorPanel);
    } else {
        resultsSash.setMaximizedControl(null);
    }
    lastExecutionContext = executionContext;
    syntaxLoaded = true;
    loadActivePreferenceSettings();
}
Also used : SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext)

Example 14 with SQLNavigatorContext

use of org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext in project dbeaver by dbeaver.

the class ViewSQLDialog method buttonPressed.

@Override
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OPEN_ID) {
        String title = getTitle();
        String text = getText();
        UIUtils.asyncExec(() -> {
            SQLEditorHandlerOpenEditor.openSQLConsole(UIUtils.getActiveWorkbenchWindow(), new SQLNavigatorContext(contextProvider.getExecutionContext()), title, text);
        });
        close();
    } else if (buttonId == IDialogConstants.PROCEED_ID) {
        setReturnCode(IDialogConstants.PROCEED_ID);
        close();
    } else {
        super.buttonPressed(buttonId);
    }
}
Also used : SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext)

Aggregations

SQLNavigatorContext (org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext)14 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IFile (org.eclipse.core.resources.IFile)2 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)2 DBException (org.jkiss.dbeaver.DBException)2 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)2 ScriptVariablesResolver (org.jkiss.dbeaver.model.sql.eval.ScriptVariablesResolver)2 SQLEditor (org.jkiss.dbeaver.ui.editors.sql.SQLEditor)2