提交 32674d49 编写于 作者: J jurgen

Data import handler

Former-commit-id: 530f7b3f
上级 8599de22
......@@ -110,7 +110,9 @@ command.org.jkiss.dbeaver.ui.editors.sql.comment.single.description=Add or remov
command.org.jkiss.dbeaver.ui.editors.sql.comment.multi.name=Toggle Block Comment
command.org.jkiss.dbeaver.ui.editors.sql.comment.multi.description=Add or remove multi line comment
command.org.jkiss.dbeaver.core.export.data.name=Export Data
command.org.jkiss.dbeaver.core.export.data.description=Export data to file(s)
command.org.jkiss.dbeaver.core.export.data.description=Export data to file(s) or database table(s)
command.org.jkiss.dbeaver.core.import.data.name=Import Data
command.org.jkiss.dbeaver.core.import.data.description=Import data from database table(s)
command.org.jkiss.dbeaver.core.compare.objects.name=Compare
command.org.jkiss.dbeaver.core.compare.objects.description=Compare database objects
......
......@@ -206,6 +206,7 @@
<command id="org.jkiss.dbeaver.ui.editors.sql.comment.multi" name="%command.org.jkiss.dbeaver.ui.editors.sql.comment.multi.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.comment.multi.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.ui.editors.sql.export.data" name="%command.org.jkiss.dbeaver.ui.editors.sql.export.data.name" description="%command.org.jkiss.dbeaver.ui.editors.sql.export.data.description" categoryId="org.jkiss.dbeaver.core.sql"/>
<command id="org.jkiss.dbeaver.core.export.data" name="%command.org.jkiss.dbeaver.core.export.data.name" description="%command.org.jkiss.dbeaver.core.export.data.description" categoryId="org.jkiss.dbeaver.core.util"/>
<command id="org.jkiss.dbeaver.core.import.data" name="%command.org.jkiss.dbeaver.core.import.data.name" description="%command.org.jkiss.dbeaver.core.import.data.description" categoryId="org.jkiss.dbeaver.core.util"/>
<command id="org.jkiss.dbeaver.core.compare.objects" name="%command.org.jkiss.dbeaver.core.compare.objects.name" description="%command.org.jkiss.dbeaver.core.compare.objects.description" categoryId="org.jkiss.dbeaver.core.util"/>
<command id="org.jkiss.dbeaver.core.resultset.toggleMode" name="%command.org.jkiss.dbeaver.core.resultset.toggleMode.name" description="%command.org.jkiss.dbeaver.core.resultset.toggleMode.description" categoryId="org.jkiss.dbeaver.core.rs"/>
......@@ -235,6 +236,7 @@
<extension point="org.eclipse.ui.commandImages">
<image commandId="org.jkiss.dbeaver.ui.editors.sql.export.data" icon="icons/file/export.png"/>
<image commandId="org.jkiss.dbeaver.core.export.data" icon="icons/file/export.png"/>
<image commandId="org.jkiss.dbeaver.core.import.data" icon="icons/file/import.png"/>
<image commandId="org.jkiss.dbeaver.core.compare.objects" icon="icons/file/compare.png"/>
<image commandId="org.jkiss.dbeaver.core.driver.manager" icon="icons/driver_manager.png"/>
<image commandId="org.jkiss.dbeaver.core.new.connection" icon="icons/database_connect.png"/>
......@@ -366,6 +368,16 @@
</with>
</enabledWhen>
</handler>
<handler commandId="org.jkiss.dbeaver.core.import.data" class="org.jkiss.dbeaver.tools.transfer.handlers.DataImportHandler">
<enabledWhen>
<with variable="selection">
<count value="+"/>
<iterate operator="and">
<adapt type="org.jkiss.dbeaver.model.struct.DBSDataManipulator"/>
</iterate>
</with>
</enabledWhen>
</handler>
<handler commandId="org.jkiss.dbeaver.core.compare.objects" class="org.jkiss.dbeaver.tools.compare.CompareObjectsHandler">
<enabledWhen>
<with variable="selection">
......@@ -1338,6 +1350,9 @@
<command commandId="org.jkiss.dbeaver.core.export.data">
<visibleWhen checkEnabled="true"/>
</command>
<command commandId="org.jkiss.dbeaver.core.import.data">
<visibleWhen checkEnabled="true"/>
</command>
<command commandId="org.jkiss.dbeaver.core.compare.objects">
<visibleWhen checkEnabled="true"/>
</command>
......
......@@ -107,7 +107,9 @@ command.org.jkiss.dbeaver.ui.editors.sql.open.file.description=\u0417\u0430\u043
command.org.jkiss.dbeaver.ui.editors.sql.save.file.name=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C SQL \u0441\u043A\u0440\u0438\u043F\u0442
command.org.jkiss.dbeaver.ui.editors.sql.save.file.description=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C \u0432 \u0444\u0430\u0439\u043B
command.org.jkiss.dbeaver.core.export.data.name=\u042D\u043A\u0441\u043F\u043E\u0440\u0442 \u0434\u0430\u043D\u043D\u044B\u0445
command.org.jkiss.dbeaver.core.export.data.description=\u042D\u043A\u0441\u043F\u043E\u0440\u0442 \u0434\u0430\u043D\u043D\u044B\u0445 \u0432 \u0444\u0430\u0439\u043B(\u044B)
command.org.jkiss.dbeaver.core.export.data.description=\u042D\u043A\u0441\u043F\u043E\u0440\u0442 \u0434\u0430\u043D\u043D\u044B\u0445 \u0432 \u0444\u0430\u0439\u043B\u044B \u0438\u043B\u0438 \u0442\u0430\u0431\u043B\u0438\u0446\u044B \u0411\u0414
command.org.jkiss.dbeaver.core.import.data.name=\u0418\u043C\u043F\u043E\u0440\u0442 \u0434\u0430\u043D\u043D\u044B\u0445
command.org.jkiss.dbeaver.core.import.data.description=\u0418\u043C\u043F\u043E\u0440\u0442 \u0434\u0430\u043D\u043D\u044B\u0445 \u0438\u0437 \u0442\u0430\u0431\u043B\u0438\u0446 \u0411\u0414
command.org.jkiss.dbeaver.core.compare.objects.name=\u0421\u0440\u0430\u0432\u043D\u0438\u0442\u044C
command.org.jkiss.dbeaver.core.compare.objects.description=\u0421\u0440\u0430\u0432\u043D\u0438\u0442\u044C \u043E\u0431\u044A\u0435\u043A\u0442\u044B \u0411\u0414
......
......@@ -33,10 +33,7 @@ import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.DBPObject;
import org.jkiss.dbeaver.model.DBPQualifiedObject;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSWrapper;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.ui.properties.PropertyCollector;
/**
......@@ -50,6 +47,7 @@ public class DBNAdapterFactory implements IAdapterFactory
DBPObject.class,
DBSObject.class,
DBSDataContainer.class,
DBSDataManipulator.class,
DBSDataSourceContainer.class,
IPropertySource.class,
IProject.class,
......
......@@ -47,6 +47,11 @@ public class DatabaseTransferConsumer implements IDataTransferConsumer<DatabaseC
{
}
public DatabaseTransferConsumer(DBSDataManipulator targetObject)
{
}
@Override
public void fetchStart(DBCExecutionContext context, DBCResultSet resultSet) throws DBCException
{
......
......@@ -18,52 +18,21 @@
*/
package org.jkiss.dbeaver.tools.transfer.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.tools.transfer.IDataTransferNode;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProducer;
import org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard;
import org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class DataExportHandler extends AbstractHandler {
public class DataExportHandler extends DataTransferHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection)) {
protected IDataTransferNode adaptTransferNode(Object object)
{
final DBSDataContainer adapted = RuntimeUtils.getObjectAdapter(object, DBSDataContainer.class);
if (adapted != null) {
return new DatabaseTransferProducer(adapted);
} else {
return null;
}
IStructuredSelection ss = (IStructuredSelection)selection;
final List<IDataTransferProducer> dataProducers = new ArrayList<IDataTransferProducer>();
for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
Object object = iter.next();
final DBSDataContainer adapted = RuntimeUtils.getObjectAdapter(object, DBSDataContainer.class);
if (adapted != null) {
dataProducers.add(new DatabaseTransferProducer(adapted));
}
}
// Refresh objects
if (!dataProducers.isEmpty()) {
ActiveWizardDialog dialog = new ActiveWizardDialog(
workbenchWindow,
new DataTransferWizard(dataProducers));
dialog.open();
}
return null;
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2012 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.tools.transfer.handlers;
import org.jkiss.dbeaver.model.struct.DBSDataManipulator;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.tools.transfer.IDataTransferNode;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer;
public class DataImportHandler extends DataTransferHandler {
@Override
protected IDataTransferNode adaptTransferNode(Object object)
{
final DBSDataManipulator adapted = RuntimeUtils.getObjectAdapter(object, DBSDataManipulator.class);
if (adapted != null) {
return new DatabaseTransferConsumer(adapted);
} else {
return null;
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2012 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.tools.transfer.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.tools.transfer.IDataTransferNode;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProducer;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer;
import org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard;
import org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public abstract class DataTransferHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection ss = (IStructuredSelection)selection;
final List<IDataTransferNode> transferNodes = new ArrayList<IDataTransferNode>();
for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
Object object = iter.next();
IDataTransferNode node = adaptTransferNode(object);
if (node != null) {
transferNodes.add(node);
}
}
// Run transfer wizard
if (!transferNodes.isEmpty()) {
ActiveWizardDialog dialog = new ActiveWizardDialog(
workbenchWindow,
new DataTransferWizard(transferNodes));
dialog.open();
}
return null;
}
protected abstract IDataTransferNode adaptTransferNode(Object object);
}
\ No newline at end of file
......@@ -76,13 +76,18 @@ public class DataTransferSettings {
private transient int curPipeNum = 0;
public DataTransferSettings(Collection<? extends IDataTransferProducer> sources)
public DataTransferSettings(Collection<? extends IDataTransferNode> transferNodes)
{
this(sources, null);
}
final List<IDataTransferProducer> producers = new ArrayList<IDataTransferProducer>();
final List<IDataTransferConsumer> consumers = new ArrayList<IDataTransferConsumer>();
for (IDataTransferNode node : transferNodes) {
if (node instanceof IDataTransferProducer) {
producers.add((IDataTransferProducer) node);
} else if (node instanceof IDataTransferConsumer) {
consumers.add((IDataTransferConsumer) node);
}
}
public DataTransferSettings(Collection<? extends IDataTransferProducer> producers, Collection<? extends IDataTransferConsumer> consumers)
{
dataPipes = new ArrayList<DataTransferPipe>();
if (!CommonUtils.isEmpty(producers)) {
// Make pipes
......
......@@ -29,6 +29,8 @@ import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer;
import org.jkiss.dbeaver.tools.transfer.IDataTransferNode;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProducer;
import org.jkiss.dbeaver.tools.transfer.IDataTransferSettings;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -42,8 +44,13 @@ public class DataTransferWizard extends Wizard implements IExportWizard {
private DataTransferSettings settings;
public DataTransferWizard(List<? extends IDataTransferProducer> dataContainers) {
this.settings = new DataTransferSettings(dataContainers);
public DataTransferWizard(List<? extends IDataTransferNode> transferNodes) {
this.settings = new DataTransferSettings(transferNodes);
loadSettings();
}
private void loadSettings()
{
IDialogSettings section = UIUtils.getDialogSettings(RS_EXPORT_WIZARD_DIALOG_SETTINGS);
setDialogSettings(section);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册