protected void onDataSourceChange(boolean contextChanged) {
        if (contextChanged) {
            reloadSyntaxRules();
        }
        if (resultsSash == null || resultsSash.isDisposed()) {
            return;
        }

        DBPDataSourceContainer dsContainer = getDataSourceContainer();

        if (sqlEditorPanel != null) {
            DatabaseEditorUtils.setPartBackground(this, sqlEditorPanel);
        }

        if (resultTabs != null) {
            DatabaseEditorUtils.setPartBackground(this, resultTabs);
        }

        DBCExecutionContext executionContext = getExecutionContext();
        if (executionContext != null) {
            EditorUtils.setInputDataSource(getEditorInput(), new SQLNavigatorContext(executionContext));
        }
        refreshActions();

        refreshEditorIconAndTitle();

        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 {
                    rsv.setStatus(SQLEditorMessages.editors_sql_staus_connected_to + executionContext.getDataSource().getContainer().getName() + "'"); //$NON-NLS-2$
                }
            }
        }

        if (lastExecutionContext == null || executionContext == null || lastExecutionContext.getDataSource() != executionContext.getDataSource()) {
            // Update command states
            SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXECUTE);
            SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXPLAIN);
        }

        if (!isHideQueryText()) {
            if (dsContainer == null) {
                resultsSash.setMaximizedControl(sqlEditorPanel);
            } else {
                if (curQueryProcessor != null && curQueryProcessor.getFirstResults().hasData()) {
                    resultsSash.setMaximizedControl(null);
                }
            }
        }

        lastExecutionContext = executionContext;
        syntaxLoaded = true;

        loadActivePreferenceSettings();

        if (dsContainer != null) {
            globalScriptContext.loadVariables(dsContainer.getDriver(), null);
        } else {
            globalScriptContext.clearVariables();
        }

        if (outputViewer != null && executionContext != null) {
            outputViewer.setExecutionContext(executionContext);
        }
    }
Handles datasource change action in UI
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java