提交 882d2101 编写于 作者: A Alexander Fedorov

#3118 suggest launch configurations according to attach kind

上级 18f245d3
......@@ -22,6 +22,7 @@ package org.jkiss.dbeaver.debug.ui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Adapters;
......@@ -47,6 +48,7 @@ import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.core.DebugCore;
import org.jkiss.dbeaver.debug.internal.ui.DebugUIMessages;
import org.jkiss.dbeaver.model.struct.DBSObject;
......@@ -133,7 +135,8 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
}
protected void launch(DBSObject launchable, String mode) {
List<ILaunchConfiguration> configs = getCandidates(launchable, getConfigurationType());
Map<String, Object> databaseContext = DebugCore.resolveDatabaseContext(launchable);
List<ILaunchConfiguration> configs = getCandidates(launchable, getConfigurationType(), databaseContext);
if (configs != null) {
ILaunchConfiguration config = null;
int count = configs.size();
......@@ -192,7 +195,7 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
return (DBSObject) dialog.getFirstResult();
}
protected List<ILaunchConfiguration> getCandidates(DBSObject launchable, ILaunchConfigurationType configType) {
protected List<ILaunchConfiguration> getCandidates(DBSObject launchable, ILaunchConfigurationType configType, Map<String, Object> databaseContext) {
List<ILaunchConfiguration> candidateConfigs = Collections.emptyList();
try {
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
......@@ -200,7 +203,7 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
candidateConfigs = new ArrayList<ILaunchConfiguration>(configs.length);
for (int i = 0; i < configs.length; i++) {
ILaunchConfiguration config = configs[i];
if (isCandidate(config, launchable)) {
if (isCandidate(config, launchable, databaseContext)) {
candidateConfigs.add(config);
}
}
......@@ -210,7 +213,36 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
return candidateConfigs;
}
protected abstract boolean isCandidate(ILaunchConfiguration config, DBSObject launchable);
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable, Map<String, Object> databaseContext) {
if (!config.exists()) {
return false;
}
String datasource = DebugCore.extractDatasourceId(config);
String id = launchable.getDataSource().getContainer().getId();
if (!datasource.equals(id)) {
return false;
}
String database = DebugCore.extractDatabaseName(config);
String databaseName = String.valueOf(databaseContext.get(DBGController.DATABASE_NAME));
if (!database.equals(databaseName)) {
return false;
}
String schema = DebugCore.extractSchemaName(config);
String schemaName = String.valueOf(databaseContext.get(DBGController.SCHEMA_NAME));
if (!schema.equals(schemaName)) {
return false;
}
String oid = DebugCore.extractProcedureOid(config);
String procedureOid = String.valueOf(databaseContext.get(DBGController.PROCEDURE_OID));
if (!oid.equals(procedureOid)) {
return false;
}
return true;
}
protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) {
IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
* Copyright (C) 2017-2018 Alexander Fedorov (alexander.fedorov@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.ext.postgresql.debug.ui.internal;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.jkiss.dbeaver.debug.core.DebugCore;
import org.jkiss.dbeaver.debug.ui.DatabaseLaunchShortcut;
import org.jkiss.dbeaver.ext.postgresql.debug.core.PostgreSqlDebugCore;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure;
import org.jkiss.dbeaver.model.struct.DBSObject;
public abstract class PgSqlBaseLaunchShortcut extends DatabaseLaunchShortcut {
public PgSqlBaseLaunchShortcut() {
super(PostgreSqlDebugCore.CONFIGURATION_TYPE, PostgreDebugUIMessages.PgSqlLaunchShortcut_name);
}
@Override
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable) {
if (!config.exists()) {
return false;
}
boolean isInstance = launchable instanceof PostgreProcedure;
if (!isInstance) {
return false;
}
PostgreProcedure procedure = (PostgreProcedure) launchable;
String datasource = DebugCore.extractDatasourceId(config);
String id = launchable.getDataSource().getContainer().getId();
if (!datasource.equals(id)) {
return false;
}
String database = DebugCore.extractDatabaseName(config);
String databaseName = procedure.getDatabase().getName();
if (!database.equals(databaseName)) {
return false;
}
String schema = DebugCore.extractSchemaName(config);
String schemaName = procedure.getContainer().getName();
if (!schema.equals(schemaName)) {
return false;
}
try {
String oid = config.getAttribute(DebugCore.ATTR_PROCEDURE_OID, String.valueOf(0));
long objectId = procedure.getObjectId();
if (!(Long.parseLong(oid) == objectId)) {
return false;
}
} catch (Exception e) {
// ignore
return false;
}
return true;
}
}
......@@ -17,15 +17,22 @@
*/
package org.jkiss.dbeaver.ext.postgresql.debug.ui.internal;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.core.DebugCore;
import org.jkiss.dbeaver.debug.ui.DatabaseLaunchShortcut;
import org.jkiss.dbeaver.ext.postgresql.debug.core.PostgreSqlDebugCore;
import org.jkiss.dbeaver.model.struct.DBSObject;
public class PgSqlGlobalLaunchShortcut extends PgSqlBaseLaunchShortcut {
public class PgSqlGlobalLaunchShortcut extends DatabaseLaunchShortcut {
public PgSqlGlobalLaunchShortcut() {
super(PostgreSqlDebugCore.CONFIGURATION_TYPE, PostgreDebugUIMessages.PgSqlLaunchShortcut_name);
}
@Override
protected ILaunchConfiguration createConfiguration(DBSObject launchable) throws CoreException {
......@@ -33,5 +40,15 @@ public class PgSqlGlobalLaunchShortcut extends PgSqlBaseLaunchShortcut {
workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DBGController.ATTACH_KIND_GLOBAL);
return workingCopy.doSave();
}
@Override
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable,
Map<String, Object> databaseContext) {
String kind = DebugCore.extractAttachKind(config);
if (!DBGController.ATTACH_KIND_GLOBAL.equals(kind)) {
return false;
}
return super.isCandidate(config, launchable, databaseContext);
}
}
......@@ -17,15 +17,22 @@
*/
package org.jkiss.dbeaver.ext.postgresql.debug.ui.internal;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.core.DebugCore;
import org.jkiss.dbeaver.debug.ui.DatabaseLaunchShortcut;
import org.jkiss.dbeaver.ext.postgresql.debug.core.PostgreSqlDebugCore;
import org.jkiss.dbeaver.model.struct.DBSObject;
public class PgSqlLocalLaunchShortcut extends PgSqlBaseLaunchShortcut {
public class PgSqlLocalLaunchShortcut extends DatabaseLaunchShortcut {
public PgSqlLocalLaunchShortcut() {
super(PostgreSqlDebugCore.CONFIGURATION_TYPE, PostgreDebugUIMessages.PgSqlLaunchShortcut_name);
}
@Override
protected ILaunchConfiguration createConfiguration(DBSObject launchable) throws CoreException {
......@@ -34,4 +41,14 @@ public class PgSqlLocalLaunchShortcut extends PgSqlBaseLaunchShortcut {
return workingCopy.doSave();
}
@Override
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable,
Map<String, Object> databaseContext) {
String kind = DebugCore.extractAttachKind(config);
if (!DBGController.ATTACH_KIND_LOCAL.equals(kind)) {
return false;
}
return super.isCandidate(config, launchable, databaseContext);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册