Search in sources :

Example 6 with DataTransferProcessorDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by dbeaver.

the class DataTransferWizard method saveConfiguration.

private Map<String, Object> saveConfiguration(Map<String, Object> config) {
    config.put("maxJobCount", settings.getMaxJobCount());
    config.put("showFinalMessage", settings.isShowFinalMessage());
    // Save nodes' settings
    boolean isTask = getCurrentTask() != null;
    for (Map.Entry<Class, NodePageSettings> entry : nodeSettings.entrySet()) {
        NodePageSettings nodePageSettings = entry.getValue();
        if (isTask) {
            // Do not save settings for nodes not involved in this task
            if (nodePageSettings.sourceNode.getNodeType() == DataTransferNodeDescriptor.NodeType.PRODUCER && settings.getProducer() != null && !settings.getProducer().getId().equals(nodePageSettings.sourceNode.getId())) {
                continue;
            }
            if (nodePageSettings.sourceNode.getNodeType() == DataTransferNodeDescriptor.NodeType.CONSUMER && settings.getConsumer() != null && !settings.getConsumer().getId().equals(nodePageSettings.sourceNode.getId())) {
                continue;
            }
        }
        Map<String, Object> nodeSection = new LinkedHashMap<>();
        IDataTransferSettings settings = this.settings.getNodeSettings(nodePageSettings.sourceNode);
        if (settings != null) {
            settings.saveSettings(nodeSection);
        }
        // Note: do it in the end because of limitation of IDialogSettings wrapper
        config.put(entry.getKey().getSimpleName(), nodeSection);
    }
    if (settings.getProducer() != null) {
        config.put("producer", settings.getProducer().getId());
    }
    if (settings.getConsumer() != null) {
        config.put("consumer", settings.getConsumer().getId());
    }
    if (settings.getProcessor() != null) {
        config.put("processor", settings.getProcessor().getId());
    }
    // Save processors' properties
    Map<String, Object> processorsSection = new LinkedHashMap<>();
    for (DataTransferProcessorDescriptor procDescriptor : settings.getProcessorPropsHistory().keySet()) {
        if (isTask) {
            // Do not save settings for nodes not involved in this task
            if (settings.getProcessor() == null || !settings.getProcessor().getId().equals(procDescriptor.getId())) {
                continue;
            }
        }
        Map<String, Object> procSettings = new LinkedHashMap<>();
        Map<String, Object> props = settings.getProcessorPropsHistory().get(procDescriptor);
        if (!CommonUtils.isEmpty(props)) {
            StringBuilder propNames = new StringBuilder();
            for (Map.Entry<String, Object> prop : props.entrySet()) {
                propNames.append(prop.getKey()).append(',');
            }
            procSettings.put("@propNames", propNames.toString());
            for (Map.Entry<String, Object> prop : props.entrySet()) {
                procSettings.put(CommonUtils.toString(prop.getKey()), CommonUtils.toString(prop.getValue()));
            }
        }
        processorsSection.put(procDescriptor.getFullId(), procSettings);
    }
    config.put("processors", processorsSection);
    return config;
}
Also used : DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DialogSettingsMap(org.jkiss.dbeaver.ui.DialogSettingsMap)

Example 7 with DataTransferProcessorDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by dbeaver.

the class ResultSetHandlerCopyAs method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    // Put processor name in command label
    DataTransferProcessorDescriptor processor = getActiveProcessor((String) parameters.get(PARAM_PROCESSOR_ID));
    if (processor != null) {
        String commandName = ActionUtils.findCommandName(CMD_COPY_AS);
        element.setText(commandName + " " + processor.getName());
        if (!CommonUtils.isEmpty(processor.getDescription())) {
            element.setTooltip(processor.getDescription());
        }
        if (processor.getIcon() != null) {
            element.setIcon(DBeaverIcons.getImageDescriptor(processor.getIcon()));
        }
    }
}
Also used : DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)

Example 8 with DataTransferProcessorDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by dbeaver.

the class ResultSetHandlerOpenWith method getDefaultAppProcessor.

private static DataTransferProcessorDescriptor getDefaultAppProcessor() {
    List<DataTransferProcessorDescriptor> processors = new ArrayList<>();
    for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getNodes(DataTransferNodeDescriptor.NodeType.CONSUMER)) {
        for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
            if (processor.getAppFileExtension() != null) {
                processors.add(processor);
            }
        }
    }
    processors.sort(Comparator.comparingInt(DataTransferProcessorDescriptor::getOrder));
    return processors.isEmpty() ? null : processors.get(0);
}
Also used : DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)

Example 9 with DataTransferProcessorDescriptor

use of org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor in project dbeaver by dbeaver.

the class ResultSetHandlerOpenWith method fillOpenWithMenu.

public static void fillOpenWithMenu(ResultSetViewer viewer, IContributionManager openWithMenu) {
    ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
    ResultSetDataContainer dataContainer = new ResultSetDataContainer(viewer, options);
    List<DataTransferProcessorDescriptor> appProcessors = new ArrayList<>();
    for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getAvailableConsumers(Collections.singleton(dataContainer))) {
        for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
            if (processor.getAppFileExtension() != null) {
                appProcessors.add(processor);
            }
        }
    }
    appProcessors.sort(Comparator.comparingInt(DataTransferProcessorDescriptor::getOrder));
    for (DataTransferProcessorDescriptor processor : appProcessors) {
        CommandContributionItemParameter params = new CommandContributionItemParameter(viewer.getSite(), processor.getId(), ResultSetHandlerOpenWith.CMD_OPEN_WITH, CommandContributionItem.STYLE_RADIO);
        params.label = processor.getAppName();
        if (processor.getIcon() != null) {
            params.icon = DBeaverIcons.getImageDescriptor(processor.getIcon());
        }
        Map<String, Object> parameters = new HashMap<>();
        parameters.put(ResultSetHandlerOpenWith.PARAM_PROCESSOR_ID, processor.getFullId());
        params.parameters = parameters;
        openWithMenu.add(new CommandContributionItem(params));
    }
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 10 with DataTransferProcessorDescriptor

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

the class DataImportHandler method getProcessorByFile.

private DataTransferProcessorDescriptor getProcessorByFile(IFile file) {
    String extension = file.getFileExtension();
    if (CommonUtils.isEmpty(extension)) {
        return null;
    }
    extension = extension.toLowerCase(Locale.ENGLISH);
    DataTransferNodeDescriptor producerDesc = DataTransferRegistry.getInstance().getNodeById(StreamTransferProducer.NODE_ID);
    if (producerDesc != null) {
        for (DataTransferProcessorDescriptor processor : producerDesc.getProcessors()) {
            DBPPropertyDescriptor extList = processor.getProperty("extension");
            if (extList == null) {
                continue;
            }
            String[] defExtensions = CommonUtils.split(CommonUtils.toString(extList.getDefaultValue()), ",");
            if (ArrayUtils.contains(defExtensions, extension)) {
                return processor;
            }
        }
    }
    return null;
}
Also used : DataTransferNodeDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor) DataTransferProcessorDescriptor(org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Aggregations

DataTransferProcessorDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)34 DataTransferNodeDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)16 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)10 DBException (org.jkiss.dbeaver.DBException)6 ArrayList (java.util.ArrayList)4 CommandContributionItem (org.eclipse.ui.menus.CommandContributionItem)4 CommandContributionItemParameter (org.eclipse.ui.menus.CommandContributionItemParameter)4 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)4 PropertySourceCustom (org.jkiss.dbeaver.runtime.properties.PropertySourceCustom)4 DataTransferSettings (org.jkiss.dbeaver.tools.transfer.DataTransferSettings)4 Collection (java.util.Collection)2 Date (java.util.Date)2 Color (org.eclipse.swt.graphics.Color)2 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)2 DBPImage (org.jkiss.dbeaver.model.DBPImage)2 DBPObject (org.jkiss.dbeaver.model.DBPObject)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 MonitorRunnableContext (org.jkiss.dbeaver.model.runtime.MonitorRunnableContext)2 DataTransferRegistry (org.jkiss.dbeaver.tools.transfer.registry.DataTransferRegistry)2 StreamConsumerSettings (org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings)2