提交 83b9e20e 编写于 作者: S Serge Rider

Navigator model refactoring

上级 a67ba18c
......@@ -1178,6 +1178,7 @@
<extension point="org.jkiss.dbeaver.service">
<service name="org.jkiss.dbeaver.runtime.ui.UIServiceSQL" class="org.jkiss.dbeaver.ui.editors.sql.UIServiceSQLImpl"/>
<service name="org.jkiss.dbeaver.runtime.ui.UIServiceConnections" class="org.jkiss.dbeaver.ui.actions.datasource.UIServiceConnectionsImpl"/>
<service name="org.jkiss.dbeaver.runtime.DBServiceConnections" class="org.jkiss.dbeaver.ui.actions.datasource.UIServiceConnectionsImpl"/>
</extension>
<extension point="org.jkiss.dbeaver.pluginService">
......
......@@ -22,6 +22,7 @@ import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
......@@ -78,11 +79,15 @@ public class NavigateBookmarkHandler extends NavigatorHandlerObjectBase {
}
NavigatorViewBase navigatorView = activeNavigatorView;
dsNode.initializeNode(null, status -> {
if (status.isOK()) {
UIUtils.syncExec(() -> BookmarksHandlerImpl.navigateNodeByPath(navigatorView, dsNode, storage));
}
});
try {
dsNode.initializeNode(null, status -> {
if (status.isOK()) {
UIUtils.syncExec(() -> BookmarksHandlerImpl.navigateNodeByPath(navigatorView, dsNode, storage));
}
});
} catch (DBException e) {
log.error(e);
}
}
}
......
......@@ -22,6 +22,7 @@ import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressListener;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.DBServiceConnections;
import org.jkiss.dbeaver.runtime.ui.UIServiceConnections;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionDialog;
......@@ -29,7 +30,7 @@ import org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionDialog;
/**
* UIServiceConnectionsImpl
*/
public class UIServiceConnectionsImpl implements UIServiceConnections {
public class UIServiceConnectionsImpl implements DBServiceConnections, UIServiceConnections {
private static final Log log = Log.getLog(UIServiceConnectionsImpl.class);
......
......@@ -185,6 +185,7 @@ public class BookmarksHandlerImpl extends AbstractResourceHandler {
}
}
/*
static DBNDatabaseNode getTargetBookmarkNode(DBRProgressMonitor monitor, DBNBookmark bookmark)
{
IFile resource = (IFile) bookmark.getResource();
......@@ -213,6 +214,7 @@ public class BookmarksHandlerImpl extends AbstractResourceHandler {
}
return null;
}
*/
public static void createBookmark(final DBNDatabaseNode node, String title, IFolder folder) throws DBException
{
......
......@@ -271,7 +271,13 @@ public class DatabaseConsumerSettings implements IDataTransferSettings {
if (containerNode instanceof DBNDataSource && containerNode.getDataSource() == null) {
try {
runnableContext.run(true, true,
monitor -> containerNode.initializeNode(monitor, null));
monitor -> {
try {
containerNode.initializeNode(monitor, null);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Init connection", "Error connecting to datasource", e.getTargetException());
} catch (InterruptedException e) {
......
......@@ -111,7 +111,11 @@ public class DatabaseTransferConsumer implements IDataTransferConsumer<DatabaseC
@Override
public void fetchStart(DBCSession session, DBCResultSet resultSet, long offset, long maxRows) throws DBCException {
initExporter(session.getProgressMonitor());
try {
initExporter(session.getProgressMonitor());
} catch (DBException e) {
throw new DBCException("Error initializing exporter");
}
AbstractExecutionSource executionSource = new AbstractExecutionSource(sourceObject, targetContext, this);
......@@ -300,7 +304,7 @@ public class DatabaseTransferConsumer implements IDataTransferConsumer<DatabaseC
closeExporter();
}
private void initExporter(DBRProgressMonitor monitor) throws DBCException {
private void initExporter(DBRProgressMonitor monitor) throws DBException {
DBSObject targetDB = checkTargetContainer(monitor);
DBPDataSourceContainer dataSourceContainer = targetDB.getDataSource().getContainer();
......@@ -333,7 +337,7 @@ public class DatabaseTransferConsumer implements IDataTransferConsumer<DatabaseC
}
}
private DBSObject checkTargetContainer(DBRProgressMonitor monitor) throws DBCException {
private DBSObject checkTargetContainer(DBRProgressMonitor monitor) throws DBException {
if (targetObject == null) {
if (settings.getContainerNode() != null && settings.getContainerNode().getDataSource() == null) {
// Init connection
......
......@@ -28,8 +28,8 @@ import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
import org.jkiss.dbeaver.model.runtime.DBRProgressListener;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.runtime.DBServiceConnections;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.ui.UIServiceConnections;
import org.jkiss.utils.CommonUtils;
import java.util.Collection;
......@@ -143,10 +143,9 @@ public class DBNDataSource extends DBNDatabaseNode implements DBNContainer, IAda
}
@Override
public boolean initializeNode(@Nullable DBRProgressMonitor monitor, DBRProgressListener onFinish)
{
public boolean initializeNode(@Nullable DBRProgressMonitor monitor, DBRProgressListener onFinish) throws DBException {
if (!dataSource.isConnected()) {
UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
DBServiceConnections serviceConnections = DBWorkbench.getService(DBServiceConnections.class);
if (serviceConnections != null) {
serviceConnections.initConnection(monitor, dataSource, onFinish);
}
......
......@@ -293,7 +293,7 @@ public abstract class DBNDatabaseNode extends DBNNode implements DBSWrapper, DBP
return locked || super.isLocked();
}
public boolean initializeNode(DBRProgressMonitor monitor, DBRProgressListener onFinish) {
public boolean initializeNode(DBRProgressMonitor monitor, DBRProgressListener onFinish) throws DBException {
if (onFinish != null) {
onFinish.onTaskFinished(Status.OK_STATUS);
}
......
/*
* 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.runtime;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.runtime.DBRProgressListener;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
/**
* Connections Service
*/
public interface DBServiceConnections {
void initConnection(DBRProgressMonitor monitor, DBPDataSourceContainer dataSourceContainer, DBRProgressListener onFinish) throws DBException;
}
\ No newline at end of file
......@@ -37,5 +37,4 @@ public interface UIServiceConnections {
boolean checkAndCloseActiveTransaction(DBCExecutionContext[] contexts);
void initConnection(DBRProgressMonitor monitor, DBPDataSourceContainer dataSourceContainer, DBRProgressListener onFinish);
}
\ No newline at end of file
......@@ -161,15 +161,20 @@ public class SearchMetadataPage extends AbstractSearchPage {
for (DBNNode node = (DBNNode)object; node != null; node = node.getParentNode()) {
if (node instanceof DBNDataSource) {
DBNDataSource dsNode = (DBNDataSource) node;
dsNode.initializeNode(null, status -> {
if (status.isOK()) {
UIUtils.asyncExec(() -> {
if (!dataSourceTree.isDisposed()) {
fillObjectTypes();
}
});
}
});
try {
dsNode.initializeNode(null, status -> {
if (status.isOK()) {
UIUtils.asyncExec(() -> {
if (!dataSourceTree.isDisposed()) {
fillObjectTypes();
}
});
}
});
} catch (DBException e) {
// shouldn't be here
log.error(e);
}
break;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册