提交 723e9db0 编写于 作者: A Alexander Fedorov

#2357 add DebugEditorAdvisor to remove "postgresql.source.view" hardcode

上级 935f9194
......@@ -169,40 +169,20 @@ public class DatabaseDebugModelPresentation extends LabelProvider implements IDe
protected IEditorInput createEditorInput(DBNDatabaseNode dbnNode) {
EntityEditorInput editorInput = new EntityEditorInput(dbnNode);
editorInput.setAttribute(DBPScriptObject.OPTION_DEBUGGER_SOURCE, Boolean.TRUE);
// FIXME:AF: how to retrieve it? probably org.jkiss.dbeaver.databaseor and EntityEditorsRegistry can help
String folderId = "postgresql.source.view";
editorInput.setDefaultFolderId(folderId);
DebugEditorAdvisor editorAdvisor = DebugUI.findEditorAdvisor(dbnNode.getDataSourceContainer());
if (editorAdvisor != null) {
String sourceFolderId = editorAdvisor.getSourceFolderId();
editorInput.setDefaultFolderId(sourceFolderId);
}
DebugCore.postDebuggerSourceEvent(dbnNode.getNodeItemPath());
return editorInput;
}
@Override
public String getEditorId(IEditorInput input, Object element) {
String nodePath = null;
if (element instanceof IDatabaseBreakpoint) {
IDatabaseBreakpoint breakpoint = (IDatabaseBreakpoint) element;
nodePath = extractNodePath(breakpoint);
}
if (element instanceof DBNDatabaseNode) {
DBNDatabaseNode databaseNode = (DBNDatabaseNode) element;
nodePath = databaseNode.getNodeItemPath();
}
if (nodePath != null) {
DebugCore.postDebuggerSourceEvent(nodePath);
}
return EntityEditor.ID;
}
private String extractNodePath(IDatabaseBreakpoint breakpoint) {
try {
return breakpoint.getNodePath();
} catch (CoreException e) {
String message = NLS.bind("Unable to resolve nodePath for breakpoint {0}", breakpoint);
log.error(message, e);
return null;
}
}
@Override
public boolean requiresUIThread(Object element) {
return false;
......
/*
* 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.debug.ui;
public interface DebugEditorAdvisor {
String getSourceFolderId();
}
......@@ -18,11 +18,13 @@
package org.jkiss.dbeaver.debug.ui;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.struct.DBSObject;
public class DebugUI {
......@@ -31,6 +33,14 @@ public class DebugUI {
private static final Log log = Log.getLog(DebugUI.class);
public static DebugEditorAdvisor findEditorAdvisor(DBPDataSourceContainer dataSourceContainer) {
DebugEditorAdvisor advisor = Adapters.adapt(dataSourceContainer, DebugEditorAdvisor.class);
if (advisor != null) {
return advisor;
}
return null;
}
public static DBSObject extractDatabaseObject(IEditorPart editor) {
if (editor != null) {
IEditorInput editorInput = editor.getEditorInput();
......
......@@ -32,7 +32,6 @@ public class PostgreDebugAdapterFactory implements IAdapterFactory {
private static final Class<?>[] CLASSES = new Class[] { DBGController.class, DBGResolver.class };
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adapterType == DBGController.class) {
......@@ -45,7 +44,7 @@ public class PostgreDebugAdapterFactory implements IAdapterFactory {
DBPDataSourceProvider dataSourceProvider = driver.getDataSourceProvider();
if (dataSourceProvider instanceof PostgreDataSourceProvider) {
PostgreDebugController postgreDebugController = new PostgreDebugController(sourceContainer);
return (T) postgreDebugController;
return adapterType.cast(postgreDebugController);
}
}
......@@ -55,7 +54,7 @@ public class PostgreDebugAdapterFactory implements IAdapterFactory {
DBPDataSource dataSource = sourceContainer.getDataSource();
if (dataSource instanceof PostgreDataSource) {
PostgreDataSource postgeDataSource = (PostgreDataSource) dataSource;
return (T) new PostgreResolver(postgeDataSource);
return adapterType.cast(new PostgreResolver(postgeDataSource));
}
}
}
......
......@@ -120,6 +120,13 @@
type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget">
</adapter>
</factory>
<factory
adaptableType="org.jkiss.dbeaver.model.DBPDataSourceContainer"
class="org.jkiss.dbeaver.ext.postgresql.debug.ui.internal.PostgreDebugUIAdapterFactory">
<adapter
type="org.jkiss.dbeaver.debug.ui.DebugEditorAdvisor">
</adapter>
</factory>
</extension>
<extension
......
/*
* 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.core.runtime.IAdapterFactory;
import org.jkiss.dbeaver.debug.ui.DebugEditorAdvisor;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
public class PostgreDebugUIAdapterFactory implements IAdapterFactory {
private static final Class<?>[] CLASSES = new Class[] { DebugEditorAdvisor.class };
private DebugEditorAdvisor debugEditorAdvisor = new PostgreSourceEditorAdvisor();
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adapterType == DebugEditorAdvisor.class) {
if (adaptableObject instanceof DBPDataSourceContainer) {
DBPDataSourceContainer sourceContainer = (DBPDataSourceContainer) adaptableObject;
DBPDataSource dataSource = sourceContainer.getDataSource();
if (dataSource instanceof PostgreDataSource) {
return adapterType.cast(debugEditorAdvisor);
}
}
}
return null;
}
@Override
public Class<?>[] getAdapterList() {
return CLASSES;
}
}
/*
* 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.jkiss.dbeaver.debug.ui.DebugEditorAdvisor;
public class PostgreSourceEditorAdvisor implements DebugEditorAdvisor {
private static final String POSTGRESQL_SOURCE_VIEW = "postgresql.source.view"; //$NON-NLS-1$
@Override
public String getSourceFolderId() {
return POSTGRESQL_SOURCE_VIEW;
}
}
......@@ -36,8 +36,7 @@ public class PostgreActivator extends AbstractUIPlugin {
// The shared instance
private static PostgreActivator plugin;
private IEventBroker eventBroker;
private static BundleContext bundleContext;
public PostgreActivator() {
}
......@@ -45,15 +44,14 @@ public class PostgreActivator extends AbstractUIPlugin {
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
bundleContext = context;
plugin = this;
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
eventBroker = serviceContext.get(IEventBroker.class);
}
@Override
public void stop(BundleContext context) throws Exception {
eventBroker = null;
plugin = null;
bundleContext = context;
super.stop(context);
}
......@@ -73,6 +71,7 @@ public class PostgreActivator extends AbstractUIPlugin {
}
public IEventBroker getEventBroker() {
return eventBroker;
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext);
return serviceContext.get(IEventBroker.class);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册