diff --git a/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DatabaseDebugModelPresentation.java b/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DatabaseDebugModelPresentation.java index 608b3b1ec0230e8acba726b6841bf607df1fd725..b06cd54edc19b89fd6eb18c9e4128f21c3fdf052 100644 --- a/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DatabaseDebugModelPresentation.java +++ b/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DatabaseDebugModelPresentation.java @@ -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; diff --git a/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugEditorAdvisor.java b/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugEditorAdvisor.java new file mode 100644 index 0000000000000000000000000000000000000000..b5d525591f7a5df0ca8f62841aece89b2784b34a --- /dev/null +++ b/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugEditorAdvisor.java @@ -0,0 +1,24 @@ +/* + * 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(); + +} diff --git a/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugUI.java b/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugUI.java index 2e8a64a57b581742e7da50c7e9a238332ea939b5..2fc5ddbb4d8ab7e005b289897cad3ea0382952bc 100644 --- a/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugUI.java +++ b/plugins/org.jkiss.dbeaver.debug.ui/src/org/jkiss/dbeaver/debug/ui/DebugUI.java @@ -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(); diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/PostgreDebugAdapterFactory.java b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/PostgreDebugAdapterFactory.java index cb4462a1c6551b73be33d5ac0d5daaa171a37e25..10877965852faa58da803abecb0caf6fff541338 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/PostgreDebugAdapterFactory.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/PostgreDebugAdapterFactory.java @@ -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 getAdapter(Object adaptableObject, Class 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)); } } } diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/plugin.xml b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/plugin.xml index e36ff078c9e457aa20e7d4bb98a504e45a7de94a..b58c00c4c5ffb38185254a79df25e86ccc0f16f0 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/plugin.xml +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/plugin.xml @@ -120,6 +120,13 @@ type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget"> + + + + [] CLASSES = new Class[] { DebugEditorAdvisor.class }; + + private DebugEditorAdvisor debugEditorAdvisor = new PostgreSourceEditorAdvisor(); + + @Override + public T getAdapter(Object adaptableObject, Class 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; + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/src/org/jkiss/dbeaver/ext/postgresql/debug/ui/internal/PostgreSourceEditorAdvisor.java b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/src/org/jkiss/dbeaver/ext/postgresql/debug/ui/internal/PostgreSourceEditorAdvisor.java new file mode 100644 index 0000000000000000000000000000000000000000..7601e70e9bcdeace44a6a3579b75d6dba17eb140 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.ui/src/org/jkiss/dbeaver/ext/postgresql/debug/ui/internal/PostgreSourceEditorAdvisor.java @@ -0,0 +1,31 @@ +/* + * 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; + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreActivator.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreActivator.java index b9ca47a0b16f555108bdec28cff8d5f78b323818..1076e0eab979af15efc84472a3ed14776c7c1b48 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreActivator.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreActivator.java @@ -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); } }