Search in sources :

Example 1 with IDataTransferProducer

use of org.jkiss.dbeaver.tools.transfer.IDataTransferProducer in project dbeaver by serge-rider.

the class DataTransferHandler method execute.

@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<IDataTransferProducer> producers = new ArrayList<>();
    final List<IDataTransferConsumer> consumers = new ArrayList<>();
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        IDataTransferNode node = adaptTransferNode(object);
        if (node instanceof IDataTransferProducer) {
            producers.add((IDataTransferProducer) node);
        } else if (node instanceof IDataTransferConsumer) {
            consumers.add((IDataTransferConsumer) node);
        }
    }
    if (!consumers.isEmpty()) {
        // We need to choose producer for consumers
        for (IDataTransferConsumer consumer : consumers) {
            IDataTransferProducer producer = chooseProducer(event, consumer);
            if (producer == null) {
                return null;
            }
            producers.add(producer);
        }
    }
    // Run transfer wizard
    if (!producers.isEmpty() || !consumers.isEmpty()) {
        ActiveWizardDialog dialog = new ActiveWizardDialog(workbenchWindow, new DataTransferWizard(producers.toArray(new IDataTransferProducer[producers.size()]), consumers.toArray(new IDataTransferConsumer[consumers.size()])));
        dialog.open();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferNode(org.jkiss.dbeaver.tools.transfer.IDataTransferNode) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 2 with IDataTransferProducer

use of org.jkiss.dbeaver.tools.transfer.IDataTransferProducer in project dbeaver by serge-rider.

the class DataTransferJob method transferData.

private boolean transferData(DBRProgressMonitor monitor, DataTransferPipe transferPipe) {
    IDataTransferProducer producer = transferPipe.getProducer();
    IDataTransferConsumer consumer = transferPipe.getConsumer();
    IDataTransferSettings consumerSettings = settings.getNodeSettings(consumer);
    setName(NLS.bind(CoreMessages.data_transfer_wizard_job_container_name, CommonUtils.truncateString(producer.getSourceObject().getName(), 200)));
    IDataTransferSettings nodeSettings = settings.getNodeSettings(producer);
    try {
        //consumer.initTransfer(producer.getSourceObject(), consumerSettings, );
        producer.transferData(monitor, consumer, nodeSettings);
        consumer.finishTransfer(monitor, false);
        return true;
    } catch (Exception e) {
        new DataTransferErrorJob(e).schedule();
        return false;
    }
}
Also used : IDataTransferSettings(org.jkiss.dbeaver.tools.transfer.IDataTransferSettings) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 3 with IDataTransferProducer

use of org.jkiss.dbeaver.tools.transfer.IDataTransferProducer in project dbeaver by dbeaver.

the class DataTransferHandler method execute.

@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<IDataTransferProducer> producers = new ArrayList<>();
    final List<IDataTransferConsumer> consumers = new ArrayList<>();
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        IDataTransferNode node = adaptTransferNode(object);
        if (node instanceof IDataTransferProducer) {
            producers.add((IDataTransferProducer) node);
        } else if (node instanceof IDataTransferConsumer) {
            consumers.add((IDataTransferConsumer) node);
        }
    }
    if (!consumers.isEmpty()) {
        // We need to choose producer for consumers
        for (IDataTransferConsumer consumer : consumers) {
            IDataTransferProducer producer = chooseProducer(event, consumer);
            if (producer == null) {
                return null;
            }
            producers.add(producer);
        }
    }
    // Run transfer wizard
    if (!producers.isEmpty() || !consumers.isEmpty()) {
        ActiveWizardDialog dialog = new ActiveWizardDialog(workbenchWindow, new DataTransferWizard(producers.toArray(new IDataTransferProducer[producers.size()]), consumers.toArray(new IDataTransferConsumer[consumers.size()])));
        dialog.open();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferNode(org.jkiss.dbeaver.tools.transfer.IDataTransferNode) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 4 with IDataTransferProducer

use of org.jkiss.dbeaver.tools.transfer.IDataTransferProducer in project dbeaver by serge-rider.

the class DataTransferHandler method execute.

@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<IDataTransferProducer> producers = new ArrayList<>();
    final List<IDataTransferConsumer> consumers = new ArrayList<>();
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        IDataTransferNode node = adaptTransferNode(object);
        if (node instanceof IDataTransferProducer) {
            producers.add((IDataTransferProducer) node);
        } else if (node instanceof IDataTransferConsumer) {
            consumers.add((IDataTransferConsumer) node);
        }
    }
    // Run transfer wizard
    if (!producers.isEmpty() || !consumers.isEmpty()) {
        try {
            DataTransferWizard.openWizard(workbenchWindow, producers, consumers);
        } catch (Exception e) {
            DBWorkbench.getPlatformUI().showError(DTUIMessages.data_transfer_handler_title_data_transfer_error, DTUIMessages.data_transfer_handler_message_data_transfer_error, e);
        }
    } else {
        DBWorkbench.getPlatformUI().showError(DTUIMessages.data_transfer_handler_title_data_transfer_error, "Can't perform data transfer: selected objects are not recognized as data producers or data consumers");
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDataTransferNode(org.jkiss.dbeaver.tools.transfer.IDataTransferNode) ExecutionException(org.eclipse.core.commands.ExecutionException) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 5 with IDataTransferProducer

use of org.jkiss.dbeaver.tools.transfer.IDataTransferProducer in project dbeaver by dbeaver.

the class DataTransferJob method transferData.

private boolean transferData(DBRProgressMonitor monitor, DataTransferPipe transferPipe) {
    IDataTransferProducer producer = transferPipe.getProducer();
    IDataTransferConsumer consumer = transferPipe.getConsumer();
    IDataTransferSettings consumerSettings = settings.getNodeSettings(consumer);
    setName(NLS.bind(CoreMessages.data_transfer_wizard_job_container_name, CommonUtils.truncateString(producer.getSourceObject().getName(), 200)));
    IDataTransferSettings nodeSettings = settings.getNodeSettings(producer);
    try {
        // consumer.initTransfer(producer.getSourceObject(), consumerSettings, );
        producer.transferData(monitor, consumer, nodeSettings);
        consumer.finishTransfer(monitor, false);
        return true;
    } catch (Exception e) {
        new DataTransferErrorJob(e).schedule();
        return false;
    }
}
Also used : IDataTransferSettings(org.jkiss.dbeaver.tools.transfer.IDataTransferSettings) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Aggregations

IDataTransferConsumer (org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer)5 IDataTransferProducer (org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)5 ArrayList (java.util.ArrayList)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 IDataTransferNode (org.jkiss.dbeaver.tools.transfer.IDataTransferNode)3 IDataTransferSettings (org.jkiss.dbeaver.tools.transfer.IDataTransferSettings)2 DataTransferWizard (org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard)2 ActiveWizardDialog (org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1