提交 6fed5501 编写于 作者: S Serge Rider

#7822 Add "Open separate connection" option to the main menu. Extra logging.

上级 7977190d
......@@ -33,6 +33,7 @@ import org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer;
import org.jkiss.dbeaver.ui.editors.entity.EntityEditor;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditor;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorCommands;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorContributions;
import org.jkiss.dbeaver.ui.navigator.INavigatorModelView;
import org.jkiss.dbeaver.ui.perspective.DBeaverPerspective;
......@@ -222,6 +223,8 @@ class WorkbenchContextListener implements IWindowListener, IPageListener, IPartL
}
// Refresh auto-commit element state (#3315)
ActionUtils.fireCommandRefresh(CoreCommands.CMD_TOGGLE_AUTOCOMMIT);
// Refresh OpenSeparateConnection
ActionUtils.fireCommandRefresh(SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
}
finally {
contextService.deferUpdates(false);
......
......@@ -49,6 +49,8 @@ public abstract class AbstractExecutionContext<DATASOURCE extends DBPDataSource>
this.dataSource = dataSource;
this.purpose = purpose;
this.id = generateContextId();
log.debug("Execution context opened (" + dataSource.getName() + ", " + this.id + ")");
}
public static synchronized long generateContextId() {
......@@ -122,6 +124,8 @@ public abstract class AbstractExecutionContext<DATASOURCE extends DBPDataSource>
protected void closeContext()
{
QMUtils.getDefaultHandler().handleContextClose(this);
log.debug("Execution context closed (" + dataSource.getName() + ", " + this.id + ")");
}
@Override
......
......@@ -108,6 +108,8 @@ command.org.jkiss.dbeaver.ui.editors.sql.sync.connection.name=Set connection fro
command.org.jkiss.dbeaver.ui.editors.sql.sync.connection.description=Set active connection from database navigator selection
command.org.jkiss.dbeaver.ui.editors.sql.sync.auto.name=Auto-sync connection with navigator
command.org.jkiss.dbeaver.ui.editors.sql.sync.auto.description=Auto-sync active connection with database navigator selection
command.org.jkiss.dbeaver.ui.editors.sql.connection.separate.name=Open separate connection
command.org.jkiss.dbeaver.ui.editors.sql.connection.separate.description=Open separate connection
command.org.jkiss.dbeaver.ui.editors.sql.rename.name=Rename SQL Script
command.org.jkiss.dbeaver.ui.editors.sql.rename.description=Rename current SQL script
command.org.jkiss.dbeaver.ui.editors.sql.deleteThisScript.name=Delete this script
......
......@@ -246,6 +246,7 @@
<command id="org.jkiss.dbeaver.ui.editors.sql.assist.templates" name="%command.org.jkiss.dbeaver.ui.editors.sql.assist.templates.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.assist.templates.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.sync.connection" name="%command.org.jkiss.dbeaver.ui.editors.sql.sync.connection.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.sync.connection.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.sync.auto" name="%command.org.jkiss.dbeaver.ui.editors.sql.sync.auto.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.sync.auto.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.connection.separate" name="%command.org.jkiss.dbeaver.ui.editors.sql.connection.separate.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.connection.separate.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.rename" name="%command.org.jkiss.dbeaver.ui.editors.sql.rename.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.rename.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.deleteThisScript" name="%command.org.jkiss.dbeaver.ui.editors.sql.deleteThisScript.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.deleteThisScript.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.close.tab" name="%command.org.jkiss.dbeaver.ui.editors.sql.close.tab.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.close.tab.description" categoryId="org.jkiss.dbeaver.core.sql"/>
......@@ -485,6 +486,7 @@
</enabledWhen>
</handler>
<handler commandId="org.jkiss.dbeaver.ui.editors.sql.sync.auto" class="org.jkiss.dbeaver.ui.editors.sql.handlers.SQLEditorHandlerSyncConnectionAuto"/>
<handler commandId="org.jkiss.dbeaver.ui.editors.sql.connection.separate" class="org.jkiss.dbeaver.ui.editors.sql.handlers.SQLEditorHandlerSeparateConnectionOption"/>
<handler commandId="org.jkiss.dbeaver.ui.editors.sql.export.data" class="org.jkiss.dbeaver.ui.editors.sql.handlers.SQLEditorHandlerExportData">
<enabledWhen>
<with variable="activeEditor">
......@@ -598,7 +600,9 @@
<command commandId="org.jkiss.dbeaver.core.sql.editor.open"/>
<command commandId="org.jkiss.dbeaver.core.sql.editor.recent"/>
<command commandId="org.jkiss.dbeaver.core.sql.editor.create"/>
<separator name="execute" visible="true"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.run.statement">
<visibleWhen>
<with variable="activeEditor">
......@@ -648,8 +652,11 @@
</with>
</visibleWhen>
</command>
<separator name="query" visible="true"/>
<separator name="plan" visible="true"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.run.explain">
<visibleWhen>
<with variable="activeEditor">
......@@ -664,7 +671,9 @@
</with>
</visibleWhen>
</command>
<separator name="files" visible="true"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.open.file">
<visibleWhen>
<with variable="activeEditor">
......@@ -679,17 +688,22 @@
</with>
</visibleWhen>
</command>
<separator name="misc" visible="true"/>
<separator name="layout" visible="true"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.toggle.result.panel"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.maximize.result.panel" style="push"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.switch.panel"/>
<separator name="sync" visible="true"/>
<separator name="context" visible="true"/>
<command commandId="org.jkiss.dbeaver.ui.tools.select.connection"><parameter name="noCustomLabel" value="true"/></command>
<command commandId="org.jkiss.dbeaver.ui.tools.select.schema"><parameter name="noCustomLabel" value="true"/></command>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.sync.connection"/>
<separator name="options" visible="true"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.sync.auto" style="toggle"/>
<command commandId="org.jkiss.dbeaver.ui.editors.sql.connection.separate" style="toggle"/>
</menu>
</menuContribution>
......
......@@ -391,7 +391,7 @@ public class SQLEditor extends SQLEditorBase implements
}
}
private void initSeparateConnection(DBPDataSource dataSource, Runnable onSuccess) {
private void initSeparateConnection(@NotNull DBPDataSource dataSource, Runnable onSuccess) {
DBSInstance dsInstance = dataSource.getDefaultInstance();
String[] contextDefaults = EditorUtils.getInputContextDefaults(getEditorInput());
if (contextDefaults.length > 0 && contextDefaults[0] != null) {
......@@ -1985,6 +1985,18 @@ public class SQLEditor extends SQLEditorBase implements
return createScriptContext().fillQueryParameters(query, false);
}
// Called on OPEN_SEPARATE_CONNECTION optio nchange
public void updateExecutionContextState() {
// Save current datasource (we want to keep it here)
DBPDataSource dataSource = curDataSource;
releaseExecutionContext();
// Restore cur data source (as it is reset in releaseExecutionContext)
curDataSource = dataSource;
if (dataSource != null && SQLEditorUtils.isOpenSeparateConnection(dataSource.getContainer())) {
initSeparateConnection(dataSource, null);
}
}
private boolean checkSession(DBRProgressListener onFinish)
throws DBException
{
......
......@@ -50,5 +50,6 @@ public interface SQLEditorCommands
String CMD_NAVIGATE_OBJECT = "org.jkiss.dbeaver.ui.editors.sql.navigate.object";
String CMD_TOGGLE_LAYOUT = "org.jkiss.dbeaver.ui.editors.sql.toggleLayout";
String CMD_TOGGLE_SEPARATE_CONNECTION = "org.jkiss.dbeaver.ui.editors.sql.connection.separate";
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors.sql.handlers;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.actions.AbstractDataSourceHandler;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditor;
import org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants;
import org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages;
import java.io.IOException;
import java.util.Map;
public class SQLEditorHandlerSeparateConnectionOption extends AbstractDataSourceHandler implements IElementUpdater {
public SQLEditorHandlerSeparateConnectionOption()
{
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
final DBPPreferenceStore prefs = getPreferenceStore(event);
prefs.setValue(SQLPreferenceConstants.EDITOR_SEPARATE_CONNECTION,
!prefs.getBoolean(SQLPreferenceConstants.EDITOR_SEPARATE_CONNECTION));
try {
prefs.save();
} catch (IOException e) {
throw new ExecutionException("Error saving configuration", e);
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof SQLEditor) {
((SQLEditor) editor).updateExecutionContextState();
}
return null;
}
@NotNull
private DBPPreferenceStore getPreferenceStore(ExecutionEvent event) {
DBPDataSourceContainer dsContainer = getActiveDataSourceContainer(event, false);
return dsContainer == null ? DBWorkbench.getPlatform().getPreferenceStore() : dsContainer.getPreferenceStore();
}
@Override
public void updateElement(UIElement element, Map parameters) {
element.setText(SQLEditorMessages.pref_page_sql_editor_label_separate_connection_each_editor);
element.setTooltip(SQLEditorMessages.pref_page_sql_editor_label_separate_connection_each_editor);
IEditorPart activeEditor = UIUtils.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
DBPDataSourceContainer dsContainer = activeEditor == null ? null : getDataSourceContainerFromPart(activeEditor);
DBPPreferenceStore prefStore = dsContainer == null ? DBWorkbench.getPlatform().getPreferenceStore() : dsContainer.getPreferenceStore();
element.setChecked(prefStore.getBoolean(SQLPreferenceConstants.EDITOR_SEPARATE_CONNECTION));
}
}
......@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.navigator.NavigatorPreferences;
import java.io.IOException;
import java.util.Map;
public class SQLEditorHandlerSyncConnectionAuto extends AbstractHandler implements IElementUpdater {
......@@ -39,6 +40,13 @@ public class SQLEditorHandlerSyncConnectionAuto extends AbstractHandler implemen
final DBPPreferenceStore prefs = DBWorkbench.getPlatform().getPreferenceStore();
prefs.setValue(NavigatorPreferences.NAVIGATOR_SYNC_EDITOR_DATASOURCE,
!prefs.getBoolean(NavigatorPreferences.NAVIGATOR_SYNC_EDITOR_DATASOURCE));
try {
prefs.save();
} catch (IOException e) {
throw new ExecutionException("Error saving configuration", e);
}
return null;
}
......
......@@ -39,8 +39,7 @@ public abstract class AbstractDataSourceHandler extends AbstractHandler {
/**
* Get execution context from active editor or active selection
*/
public static DBCExecutionContext getActiveExecutionContext(ExecutionEvent event, boolean useEditor)
{
public static DBCExecutionContext getActiveExecutionContext(ExecutionEvent event, boolean useEditor) {
if (useEditor) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof DBPContextProvider) {
......@@ -63,8 +62,7 @@ public abstract class AbstractDataSourceHandler extends AbstractHandler {
return null;
}
public static DBSObject getActiveObject(ExecutionEvent event)
{
public static DBSObject getActiveObject(ExecutionEvent event) {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
IStructuredSelection navSelection = NavigatorUtils.getSelectionFromPart(activePart);
......@@ -78,16 +76,14 @@ public abstract class AbstractDataSourceHandler extends AbstractHandler {
return null;
}
public static DBCExecutionContext getExecutionContextFromPart(IWorkbenchPart activePart)
{
public static DBCExecutionContext getExecutionContextFromPart(IWorkbenchPart activePart) {
if (activePart instanceof DBPContextProvider) {
return ((DBPContextProvider) activePart).getExecutionContext();
}
return null;
}
public static DBPDataSourceContainer getActiveDataSourceContainer(ExecutionEvent event, boolean useEditor)
{
public static DBPDataSourceContainer getActiveDataSourceContainer(ExecutionEvent event, boolean useEditor) {
if (useEditor) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor != null) {
......@@ -107,7 +103,7 @@ public abstract class AbstractDataSourceHandler extends AbstractHandler {
DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
if (selectedObject instanceof DBPDataSourceContainer) {
return (DBPDataSourceContainer)selectedObject;
return (DBPDataSourceContainer) selectedObject;
} else if (selectedObject != null) {
DBPDataSource dataSource = selectedObject.getDataSource();
return dataSource == null ? null : dataSource.getContainer();
......@@ -116,8 +112,7 @@ public abstract class AbstractDataSourceHandler extends AbstractHandler {
return null;
}
public static DBPDataSourceContainer getDataSourceContainerFromPart(IWorkbenchPart activePart)
{
public static DBPDataSourceContainer getDataSourceContainerFromPart(IWorkbenchPart activePart) {
if (activePart instanceof IDataSourceContainerProvider) {
return ((IDataSourceContainerProvider) activePart).getDataSourceContainer();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册