Search in sources :

Example 1 with StreamConsumerSettings

use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by dbeaver.

the class StreamPOIConsumerPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        Group generalSettings = new Group(composite, SWT.NONE);
        generalSettings.setText(CoreMessages.data_transfer_wizard_settings_group_general);
        gl = new GridLayout(4, false);
        generalSettings.setLayout(gl);
        generalSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        {
            Composite formattingGroup = UIUtils.createPlaceholder(generalSettings, 3);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 4;
            formattingGroup.setLayoutData(gd);
            UIUtils.createControlLabel(formattingGroup, CoreMessages.data_transfer_wizard_settings_label_formatting);
            formatProfilesCombo = new Combo(formattingGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
            gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            gd.widthHint = 200;
            formatProfilesCombo.setLayoutData(gd);
            formatProfilesCombo.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (formatProfilesCombo.getSelectionIndex() > 0) {
                        settings.setFormatterProfile(DataFormatterRegistry.getInstance().getCustomProfile(UIUtils.getComboSelection(formatProfilesCombo)));
                    } else {
                        settings.setFormatterProfile(null);
                    }
                }
            });
            Button profilesManageButton = new Button(formattingGroup, SWT.PUSH);
            profilesManageButton.setText(CoreMessages.data_transfer_wizard_settings_button_edit);
            profilesManageButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    PreferenceDialog propDialog = PreferencesUtil.createPropertyDialogOn(getShell(), DataFormatterRegistry.getInstance(), PrefPageDataFormat.PAGE_ID, null, getSelectedFormatterProfile(), PreferencesUtil.OPTION_NONE);
                    if (propDialog != null) {
                        propDialog.open();
                        reloadFormatProfiles();
                    }
                }
            });
            reloadFormatProfiles();
        }
    }
    Group exporterSettings = new Group(composite, SWT.NONE);
    exporterSettings.setText(CoreMessages.data_transfer_wizard_settings_group_exporter);
    exporterSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
    exporterSettings.setLayout(new GridLayout(1, false));
    propsEditor = new PropertyTreeViewer(exporterSettings, SWT.BORDER);
    setControl(composite);
}
Also used : StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo)

Example 2 with StreamConsumerSettings

use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by dbeaver.

the class StreamPOIConsumerPageSettings method reloadFormatProfiles.

private void reloadFormatProfiles() {
    DataFormatterRegistry registry = DataFormatterRegistry.getInstance();
    formatProfilesCombo.removeAll();
    formatProfilesCombo.add(CoreMessages.data_transfer_wizard_settings_listbox_formatting_item_default);
    for (DBDDataFormatterProfile profile : registry.getCustomProfiles()) {
        formatProfilesCombo.add(profile.getProfileName());
    }
    final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
    DBDDataFormatterProfile formatterProfile = settings.getFormatterProfile();
    if (formatterProfile != null) {
        if (!UIUtils.setComboSelection(formatProfilesCombo, formatterProfile.getProfileName())) {
            formatProfilesCombo.select(0);
        }
    } else {
        formatProfilesCombo.select(0);
    }
}
Also used : StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) DBDDataFormatterProfile(org.jkiss.dbeaver.model.data.DBDDataFormatterProfile) DataFormatterRegistry(org.jkiss.dbeaver.registry.formatter.DataFormatterRegistry)

Example 3 with StreamConsumerSettings

use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by dbeaver.

the class StreamPOIConsumerPageSettings method activatePage.

@Override
public void activatePage() {
    final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
    DataTransferProcessorDescriptor processor = getWizard().getSettings().getProcessor();
    propertySource = new PropertySourceCustom(processor.getProperties(), getWizard().getSettings().getProcessorProperties());
    propsEditor.loadProperties(propertySource);
    updatePageCompletion();
}
Also used : StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) PropertySourceCustom(org.jkiss.dbeaver.runtime.properties.PropertySourceCustom) DataTransferProcessorDescriptor(org.jkiss.dbeaver.registry.transfer.DataTransferProcessorDescriptor)

Example 4 with StreamConsumerSettings

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

the class StreamConsumerPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    DBPDataFormatterRegistry dataFormatterRegistry = DBWorkbench.getPlatform().getDataFormatterRegistry();
    initializeDialogUnits(parent);
    final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
    Composite composite = UIUtils.createComposite(parent, 1);
    {
        Composite generalSettings = UIUtils.createControlGroup(composite, DTMessages.data_transfer_wizard_settings_group_general, 5, GridData.FILL_HORIZONTAL, 0);
        ((GridLayout) generalSettings.getLayout()).verticalSpacing = 0;
        ((GridLayout) generalSettings.getLayout()).marginHeight = 0;
        ((GridLayout) generalSettings.getLayout()).marginWidth = 0;
        {
            formatProfilesCombo = UIUtils.createLabelCombo(generalSettings, DTMessages.data_transfer_wizard_settings_label_formatting, SWT.DROP_DOWN | SWT.READ_ONLY);
            GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 3;
            formatProfilesCombo.setLayoutData(gd);
            formatProfilesCombo.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (formatProfilesCombo.getSelectionIndex() > 0) {
                        settings.setFormatterProfile(dataFormatterRegistry.getCustomProfile(UIUtils.getComboSelection(formatProfilesCombo)));
                    } else {
                        settings.setFormatterProfile(null);
                    }
                }
            });
            UIUtils.createDialogButton(generalSettings, DTMessages.data_transfer_wizard_settings_button_edit, new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    PreferenceDialog propDialog = PreferencesUtil.createPropertyDialogOn(getShell(), dataFormatterRegistry, // TODO: replace this hardcode with some model invocation
                    "org.jkiss.dbeaver.preferences.main.dataformat", null, getSelectedFormatterProfile(), PreferencesUtil.OPTION_NONE);
                    if (propDialog != null) {
                        propDialog.open();
                        reloadFormatProfiles();
                    }
                }
            });
            reloadFormatProfiles();
            UIUtils.createControlLabel(generalSettings, DTMessages.data_transfer_wizard_settings_label_binaries);
            Composite binariesPanel = UIUtils.createComposite(generalSettings, 4);
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 4;
            binariesPanel.setLayoutData(gd);
            lobExtractType = new Combo(binariesPanel, SWT.DROP_DOWN | SWT.READ_ONLY);
            lobExtractType.setItems(DTMessages.data_transfer_wizard_settings_binaries_item_set_to_null, DTMessages.data_transfer_wizard_settings_binaries_item_save_to_file, DTMessages.data_transfer_wizard_settings_binaries_item_inline);
            lobExtractType.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    switch(lobExtractType.getSelectionIndex()) {
                        case EXTRACT_LOB_SKIP:
                            settings.setLobExtractType(StreamConsumerSettings.LobExtractType.SKIP);
                            break;
                        case EXTRACT_LOB_FILES:
                            settings.setLobExtractType(StreamConsumerSettings.LobExtractType.FILES);
                            break;
                        case EXTRACT_LOB_INLINE:
                            settings.setLobExtractType(StreamConsumerSettings.LobExtractType.INLINE);
                            break;
                    }
                    updatePageCompletion();
                }
            });
            lobEncodingLabel = UIUtils.createControlLabel(binariesPanel, DTMessages.data_transfer_wizard_settings_label_encoding);
            lobEncodingCombo = new Combo(binariesPanel, SWT.DROP_DOWN | SWT.READ_ONLY);
            lobEncodingCombo.setItems(// $NON-NLS-1$
            "Base64", // $NON-NLS-1$
            "Hex", // $NON-NLS-1$
            "Binary", // $NON-NLS-1$
            "Native");
            lobEncodingCombo.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    switch(lobEncodingCombo.getSelectionIndex()) {
                        case LOB_ENCODING_BASE64:
                            settings.setLobEncoding(StreamConsumerSettings.LobEncoding.BASE64);
                            break;
                        case LOB_ENCODING_HEX:
                            settings.setLobEncoding(StreamConsumerSettings.LobEncoding.HEX);
                            break;
                        case LOB_ENCODING_BINARY:
                            settings.setLobEncoding(StreamConsumerSettings.LobEncoding.BINARY);
                            break;
                        case LOB_ENCODING_NATIVE:
                            settings.setLobEncoding(StreamConsumerSettings.LobEncoding.NATIVE);
                            break;
                    }
                }
            });
        }
    }
    {
        Composite exporterSettings = UIUtils.createControlGroup(composite, DTMessages.data_transfer_wizard_settings_group_exporter, 1, GridData.FILL_BOTH, 0);
        propsEditor = new PropertyTreeViewer(exporterSettings, SWT.BORDER);
    }
    setControl(composite);
}
Also used : StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataFormatterRegistry(org.jkiss.dbeaver.model.app.DBPDataFormatterRegistry) Combo(org.eclipse.swt.widgets.Combo)

Example 5 with StreamConsumerSettings

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

the class OpenSpreadsheetHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IResultSetController resultSet = ResultSetHandlerMain.getActiveResultSet(HandlerUtil.getActivePart(event));
    if (resultSet == null) {
        DBWorkbench.getPlatformUI().showError("Open Excel", "No active results viewer");
        return null;
    }
    ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
    IResultSetSelection rsSelection = resultSet.getSelection();
    List<ResultSetRow> rsSelectedRows = rsSelection.getSelectedRows();
    if (rsSelectedRows.size() > 1) {
        List<Long> selectedRows = new ArrayList<>();
        for (ResultSetRow selectedRow : rsSelectedRows) {
            selectedRows.add((long) selectedRow.getRowNumber());
        }
        List<String> selectedAttributes = new ArrayList<>();
        for (DBDAttributeBinding attributeBinding : rsSelection.getSelectedAttributes()) {
            selectedAttributes.add(attributeBinding.getName());
        }
        options.setSelectedRows(selectedRows);
        options.setSelectedColumns(selectedAttributes);
    }
    ResultSetDataContainer dataContainer = new ResultSetDataContainer(resultSet, options);
    if (dataContainer.getDataSource() == null) {
        DBWorkbench.getPlatformUI().showError("Open Excel", ModelMessages.error_not_connected_to_database);
        return null;
    }
    AbstractJob exportJob = new AbstractJob("Open Excel") {

        {
            setUser(true);
            setSystem(false);
        }

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                File tempDir = DBWorkbench.getPlatform().getTempFolder(monitor, "office-files");
                File tempFile = new File(tempDir, CommonUtils.escapeFileName(CommonUtils.truncateString(dataContainer.getName(), 32)) + "." + new SimpleDateFormat("yyyyMMdd-HHmmss").format(System.currentTimeMillis()) + ".xlsx");
                tempFile.deleteOnExit();
                StreamExporterAbstract exporter = new DataExporterXLSX();
                StreamTransferConsumer consumer = new StreamTransferConsumer();
                StreamConsumerSettings settings = new StreamConsumerSettings();
                settings.setOutputEncodingBOM(false);
                settings.setOpenFolderOnFinish(false);
                settings.setOutputFolder(tempDir.getAbsolutePath());
                settings.setOutputFilePattern(tempFile.getName());
                Map<String, Object> properties = DataExporterXLSX.getDefaultProperties();
                consumer.initTransfer(dataContainer, settings, new IDataTransferConsumer.TransferParameters(true, false), exporter, properties);
                DBDDataFilter dataFilter = resultSet.getModel().getDataFilter();
                DatabaseTransferProducer producer = new DatabaseTransferProducer(dataContainer, dataFilter);
                DatabaseProducerSettings producerSettings = new DatabaseProducerSettings();
                producerSettings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
                producerSettings.setQueryRowCount(false);
                producerSettings.setSelectedRowsOnly(true);
                producerSettings.setSelectedColumnsOnly(true);
                producer.transferData(monitor, consumer, null, producerSettings, null);
                consumer.finishTransfer(monitor, false);
                UIUtils.asyncExec(() -> {
                    if (!UIUtils.launchProgram(tempFile.getAbsolutePath())) {
                        DBWorkbench.getPlatformUI().showError("Open XLSX", "Can't open XLSX file '" + tempFile.getAbsolutePath() + "'");
                    }
                });
            } catch (Exception e) {
                DBWorkbench.getPlatformUI().showError("Error opening in Excel", null, e);
            }
            return Status.OK_STATUS;
        }
    };
    exportJob.schedule();
    return null;
}
Also used : StreamExporterAbstract(org.jkiss.dbeaver.tools.transfer.stream.exporter.StreamExporterAbstract) ArrayList(java.util.ArrayList) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) StreamTransferConsumer(org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) ExecutionException(org.eclipse.core.commands.ExecutionException) DataExporterXLSX(org.jkiss.dbeaver.data.office.export.DataExporterXLSX) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DatabaseProducerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

StreamConsumerSettings (org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings)21 StreamTransferConsumer (org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer)8 ExecutionException (org.eclipse.core.commands.ExecutionException)6 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)6 DBDDataFilter (org.jkiss.dbeaver.model.data.DBDDataFilter)6 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)6 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 IDataTransferConsumer (org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer)6 DatabaseProducerSettings (org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings)6 DatabaseTransferProducer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 File (java.io.File)4 SimpleDateFormat (java.text.SimpleDateFormat)4 DBPDataFormatterRegistry (org.jkiss.dbeaver.model.app.DBPDataFormatterRegistry)4 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)4 IDataTransferProcessor (org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor)4 IStreamDataExporter (org.jkiss.dbeaver.tools.transfer.stream.IStreamDataExporter)4 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)3