From e4d3455860e552ad9f7f84540ada4012eb895e4c Mon Sep 17 00:00:00 2001 From: serge-rider Date: Sat, 14 Apr 2018 22:45:32 +0300 Subject: [PATCH] Data transfer processors model refactoring. Binary format support. XLSX exporter refactoring. --- .../transfer/DataTransferNodeDescriptor.java | 11 +- .../DataTransferProcessorDescriptor.java | 7 + .../transfer/DataTransferRegistry.java | 25 +++ .../tools/transfer/IDataTransferConsumer.java | 2 +- .../database/DatabaseTransferConsumer.java | 2 +- .../stream/StreamConsumerPageOutput.java | 17 +- .../stream/StreamTransferConsumer.java | 95 ++++---- .../wizard/DataTransferPageFinal.java | 11 +- .../org.jkiss.dbeaver.data.office/plugin.xml | 27 +-- .../data/office/export/DataExporterXLSX.java | 9 +- .../export/StreamPOIConsumerPageOutput.java | 212 ------------------ .../export/StreamPOIConsumerPageSettings.java | 197 ---------------- .../export/StreamPOIConsumerSettings.java | 26 --- .../export/StreamPOITransferConsumer.java | 27 --- .../handlers/OpenSpreadsheetHandler.java | 22 +- 15 files changed, 137 insertions(+), 553 deletions(-) delete mode 100644 plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageOutput.java delete mode 100644 plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageSettings.java delete mode 100644 plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerSettings.java delete mode 100644 plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOITransferConsumer.java diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferNodeDescriptor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferNodeDescriptor.java index 7139926a6f..dd5365c0d8 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferNodeDescriptor.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferNodeDescriptor.java @@ -30,10 +30,7 @@ import org.jkiss.dbeaver.tools.transfer.IDataTransferNode; import org.jkiss.dbeaver.tools.transfer.IDataTransferSettings; import org.jkiss.utils.ArrayUtils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Locale; +import java.util.*; /** * DataTransferNodeDescriptor @@ -72,6 +69,11 @@ public class DataTransferNodeDescriptor extends AbstractDescriptor this.nodeType = NodeType.valueOf(config.getAttribute(RegistryConstants.ATTR_TYPE).toUpperCase(Locale.ENGLISH)); this.implType = new ObjectType(config.getAttribute(RegistryConstants.ATTR_CLASS)); this.settingsType = new ObjectType(config.getAttribute(RegistryConstants.ATTR_SETTINGS)); + + loadNodeConfigurations(config); + } + + void loadNodeConfigurations(IConfigurationElement config) { for (IConfigurationElement typeCfg : ArrayUtils.safeArray(config.getChildren(RegistryConstants.ATTR_SOURCE_TYPE))) { sourceTypes.add(new ObjectType(typeCfg.getAttribute(RegistryConstants.ATTR_TYPE))); } @@ -81,6 +83,7 @@ public class DataTransferNodeDescriptor extends AbstractDescriptor for (IConfigurationElement processorConfig : ArrayUtils.safeArray(config.getChildren(RegistryConstants.TAG_PROCESSOR))) { processors.add(new DataTransferProcessorDescriptor(this, processorConfig)); } + processors.sort(Comparator.comparing(DataTransferProcessorDescriptor::getName)); } public String getId() diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferProcessorDescriptor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferProcessorDescriptor.java index 661e5801cf..8748356979 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferProcessorDescriptor.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferProcessorDescriptor.java @@ -28,6 +28,7 @@ import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor; import org.jkiss.dbeaver.registry.RegistryConstants; import org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor; import org.jkiss.utils.ArrayUtils; +import org.jkiss.utils.CommonUtils; import java.util.ArrayList; import java.util.List; @@ -46,6 +47,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen @NotNull private final DBPImage icon; private final List properties = new ArrayList<>(); + private boolean isBinary; DataTransferProcessorDescriptor(DataTransferNodeDescriptor node, IConfigurationElement config) { @@ -56,6 +58,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen this.name = config.getAttribute(RegistryConstants.ATTR_LABEL); this.description = config.getAttribute(RegistryConstants.ATTR_DESCRIPTION); this.icon = iconToImage(config.getAttribute(RegistryConstants.ATTR_ICON), DBIcon.TYPE_UNKNOWN); + this.isBinary = CommonUtils.getBoolean(config.getAttribute("binary"), false); for (IConfigurationElement typeCfg : ArrayUtils.safeArray(config.getChildren(RegistryConstants.ATTR_SOURCE_TYPE))) { sourceTypes.add(new ObjectType(typeCfg.getAttribute(RegistryConstants.ATTR_TYPE))); @@ -119,4 +122,8 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen { return node; } + + public boolean isBinaryFormat() { + return isBinary; + } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferRegistry.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferRegistry.java index 0f89e0c409..ec635a619a 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferRegistry.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/transfer/DataTransferRegistry.java @@ -20,11 +20,14 @@ package org.jkiss.dbeaver.registry.transfer; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; +import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.registry.RegistryConstants; import org.jkiss.dbeaver.tools.transfer.IDataTransferNode; +import org.jkiss.utils.CommonUtils; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.List; /** @@ -36,6 +39,8 @@ public class DataTransferRegistry { private static DataTransferRegistry instance = null; + private static final Log log = Log.getLog(DataTransferRegistry.class); + public synchronized static DataTransferRegistry getInstance() { if (instance == null) { @@ -51,10 +56,30 @@ public class DataTransferRegistry { // Load datasource providers from external plugins IConfigurationElement[] extElements = registry.getConfigurationElementsFor(EXTENSION_ID); for (IConfigurationElement ext : extElements) { + // Load main nodes if (RegistryConstants.TAG_NODE.equals(ext.getName())) { + if (!CommonUtils.isEmpty(ext.getAttribute(RegistryConstants.ATTR_REF))) { + continue; + } nodes.add(new DataTransferNodeDescriptor(ext)); } } + // Load references + for (IConfigurationElement ext : extElements) { + if (RegistryConstants.TAG_NODE.equals(ext.getName())) { + String nodeReference = ext.getAttribute(RegistryConstants.ATTR_REF); + if (CommonUtils.isEmpty(nodeReference)) { + continue; + } + DataTransferNodeDescriptor refNode = getNodeById(nodeReference); + if (refNode == null) { + log.error("Referenced data transfer node '" + nodeReference + "' not found"); + } else { + refNode.loadNodeConfigurations(ext); + } + } + } + nodes.sort(Comparator.comparing(DataTransferNodeDescriptor::getName)); } public List getAvailableProducers(Collection> objectTypes) diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/IDataTransferConsumer.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/IDataTransferConsumer.java index f26d145877..3021436a0b 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/IDataTransferConsumer.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/IDataTransferConsumer.java @@ -30,7 +30,7 @@ public interface IDataTransferConsumer, DBDDataReceiver { - void initTransfer(DBSObject sourceObject, SETTINGS settings, PROCESSOR processor, Map processorProperties); + void initTransfer(DBSObject sourceObject, SETTINGS settings, boolean isBinary, PROCESSOR processor, Map processorProperties); void startTransfer(DBRProgressMonitor monitor) throws DBException; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/database/DatabaseTransferConsumer.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/database/DatabaseTransferConsumer.java index 859bfe8e12..34b800a1f7 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/database/DatabaseTransferConsumer.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/database/DatabaseTransferConsumer.java @@ -239,7 +239,7 @@ public class DatabaseTransferConsumer implements IDataTransferConsumer processorProperties) + public void initTransfer(DBSObject sourceObject, DatabaseConsumerSettings settings, boolean isBinary, IDataTransferProcessor processor, Map processorProperties) { this.sourceObject = (DBSDataContainer)sourceObject; this.settings = settings; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/StreamConsumerPageOutput.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/StreamConsumerPageOutput.java index f9c0b791ed..e140103f8e 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/StreamConsumerPageOutput.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/StreamConsumerPageOutput.java @@ -191,13 +191,15 @@ public class StreamConsumerPageOutput extends ActiveWizardPage processorProperties; private StringWriter outputBuffer; + private boolean isBinary; private boolean initialized = false; public StreamTransferConsumer() @@ -208,7 +209,7 @@ public class StreamTransferConsumer implements IDataTransferConsumer processorProperties) + public void initTransfer(DBSObject sourceObject, StreamConsumerSettings settings, boolean isBinary, IStreamDataExporter processor, Map processorProperties) { this.sourceObject = sourceObject; + this.isBinary = isBinary; this.processor = processor; this.settings = settings; this.processorProperties = processorProperties; @@ -320,16 +324,13 @@ public class StreamTransferConsumer implements IDataTransferConsumer { + TextTransfer textTransfer = TextTransfer.getInstance(); + new Clipboard(DBeaverUI.getDisplay()).setContents( + new Object[]{outputBuffer.toString()}, + new Transfer[]{textTransfer}); }); outputBuffer = null; } @@ -494,40 +495,46 @@ public class StreamTransferConsumer implements IDataTransferConsumer { List dataPipes = settings.getDataPipes(); for (DataTransferPipe pipe : dataPipes) { IDataTransferSettings consumerSettings = settings.getNodeSettings(pipe.getConsumer()); + DataTransferProcessorDescriptor processorDescriptor = settings.getProcessor(); IDataTransferProcessor processor = null; - if (settings.getProcessor() != null) { + if (processorDescriptor != null) { // Processor is optional try { - processor = settings.getProcessor().getInstance(); + processor = processorDescriptor.getInstance(); } catch (Throwable e) { log.error("Can't create processor", e); continue; @@ -98,6 +100,7 @@ class DataTransferPageFinal extends ActiveWizardPage { pipe.getConsumer().initTransfer( pipe.getProducer().getSourceObject(), consumerSettings, + processorDescriptor != null && processorDescriptor.isBinaryFormat(), processor, processor == null ? null : @@ -108,8 +111,8 @@ class DataTransferPageFinal extends ActiveWizardPage { item.setImage(0, DBeaverIcons.getImage(settings.getProducer().getIcon())); } item.setText(1, pipe.getConsumer().getTargetName()); - if (settings.getProcessor() != null && settings.getProcessor().getIcon() != null) { - item.setImage(1, DBeaverIcons.getImage(settings.getProcessor().getIcon())); + if (processorDescriptor != null && processorDescriptor.getIcon() != null) { + item.setImage(1, DBeaverIcons.getImage(processorDescriptor.getIcon())); } else if (settings.getConsumer() != null && settings.getConsumer().getIcon() != null) { item.setImage(1, DBeaverIcons.getImage(settings.getConsumer().getIcon())); } diff --git a/plugins/org.jkiss.dbeaver.data.office/plugin.xml b/plugins/org.jkiss.dbeaver.data.office/plugin.xml index bd4acf60b1..89481b6ea3 100644 --- a/plugins/org.jkiss.dbeaver.data.office/plugin.xml +++ b/plugins/org.jkiss.dbeaver.data.office/plugin.xml @@ -3,21 +3,14 @@ - - - - + + @@ -30,9 +23,9 @@ - + - + diff --git a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/DataExporterXLSX.java b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/DataExporterXLSX.java index 681af068c8..c65534b44f 100644 --- a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/DataExporterXLSX.java +++ b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/DataExporterXLSX.java @@ -110,7 +110,7 @@ public class DataExporterXLSX extends StreamExporterAbstract { properties.put(DataExporterXLSX.PROP_EXPORT_SQL, false); properties.put(DataExporterXLSX.PROP_SPLIT_SQLTEXT, false); properties.put(DataExporterXLSX.PROP_SPLIT_BYROWCOUNT, EXCEL2007MAXROWS); - properties.put(DataExporterXLSX.PROP_SPLIT_BYCOL, -1); + properties.put(DataExporterXLSX.PROP_SPLIT_BYCOL, 0); return properties; } @@ -317,6 +317,11 @@ public class DataExporterXLSX extends StreamExporterAbstract { super.dispose(); } + @Override + public boolean isTextExporter() { + return false; + } + @Override public void exportHeader(DBCSession session) throws DBException, IOException { @@ -425,7 +430,7 @@ public class DataExporterXLSX extends StreamExporterAbstract { } private Worksheet getWsh(Object[] row) { - Object colValue = ((splitByCol < 0) || (splitByCol >= columns.size())) ? "" : row[splitByCol]; + Object colValue = ((splitByCol <= 0) || (splitByCol >= columns.size())) ? "" : row[splitByCol]; Worksheet w = worksheets.get(colValue); if (w == null) { w = createSheet(colValue); diff --git a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageOutput.java b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageOutput.java deleted file mode 100644 index 88e4ebcb1b..0000000000 --- a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageOutput.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * DBeaver - Universal Database Manager - * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com) - * Copyright (C) 2017 Adolfo Suarez (agustavo@gmail.com) - * - * 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.data.office.export; - - -import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; -import org.eclipse.jface.fieldassist.TextContentAdapter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.jkiss.dbeaver.core.CoreMessages; -import org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard; -import org.jkiss.dbeaver.ui.UIUtils; -import org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage; -import org.jkiss.dbeaver.ui.dialogs.DialogUtils; -import org.jkiss.dbeaver.utils.GeneralUtils; -import org.jkiss.utils.CommonUtils; - -/** - * @author Andrey.Hitrin - * - */ -public class StreamPOIConsumerPageOutput extends ActiveWizardPage { - - private Text directoryText; - private Text fileNameText; - private Button showFolderCheckbox; - private Button execProcessCheckbox; - private Text execProcessText; - - public StreamPOIConsumerPageOutput() { - super(CoreMessages.data_transfer_wizard_output_name); - setTitle(CoreMessages.data_transfer_wizard_output_title); - setDescription(CoreMessages.data_transfer_wizard_output_description); - setPageComplete(false); - } - - @Override - public void createControl(Composite parent) { - initializeDialogUnits(parent); - - 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)); - - final StreamPOIConsumerSettings settings = getWizard().getPageSettings(this, StreamPOIConsumerSettings.class); - - { - Group generalSettings = UIUtils.createControlGroup(composite, CoreMessages.data_transfer_wizard_output_group_general, 5, GridData.FILL_HORIZONTAL, 0); - - directoryText = DialogUtils.createOutputFolderChooser(generalSettings, null, new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - settings.setOutputFolder(directoryText.getText()); - updatePageCompletion(); - } - }); - ((GridData)directoryText.getParent().getLayoutData()).horizontalSpan = 4; - - UIUtils.createControlLabel(generalSettings, CoreMessages.data_transfer_wizard_output_label_file_name_pattern); - fileNameText = new Text(generalSettings, SWT.BORDER); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 4; - UIUtils.setContentProposalToolTip(fileNameText, "Output file name pattern", - StreamPOITransferConsumer.VARIABLE_TABLE, - StreamPOITransferConsumer.VARIABLE_TIMESTAMP, - StreamPOITransferConsumer.VARIABLE_PROJECT); - fileNameText.setLayoutData(gd); - fileNameText.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - settings.setOutputFilePattern(fileNameText.getText()); - updatePageCompletion(); - } - }); - UIUtils.installContentProposal( - fileNameText, - new TextContentAdapter(), - new SimpleContentProposalProvider(new String[] { - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_TABLE), - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_TIMESTAMP), - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_PROJECT) - })); - - { - new Label(generalSettings, SWT.NONE); - } - - } - - { - Group resultsSettings = UIUtils.createControlGroup(composite, "Results", 2, GridData.FILL_HORIZONTAL, 0); - - showFolderCheckbox = UIUtils.createCheckbox(resultsSettings, CoreMessages.data_transfer_wizard_output_checkbox_open_folder, true); - showFolderCheckbox.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - settings.setOpenFolderOnFinish(showFolderCheckbox.getSelection()); - } - }); - showFolderCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 2, 1)); - - execProcessCheckbox = UIUtils.createCheckbox(resultsSettings, "Execute process on finish", true); - execProcessCheckbox.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - settings.setExecuteProcessOnFinish(execProcessCheckbox.getSelection()); - toggleExecProcessControls(); - updatePageCompletion(); - } - }); - execProcessText = new Text(resultsSettings, SWT.BORDER); - execProcessText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - execProcessText.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - settings.setFinishProcessCommand(execProcessText.getText()); - updatePageCompletion(); - } - }); - UIUtils.setContentProposalToolTip(execProcessText, "Process command line", - StreamPOITransferConsumer.VARIABLE_FILE, - StreamPOITransferConsumer.VARIABLE_TABLE, - StreamPOITransferConsumer.VARIABLE_TIMESTAMP, - StreamPOITransferConsumer.VARIABLE_PROJECT); - UIUtils.installContentProposal( - execProcessText, - new TextContentAdapter(), - new SimpleContentProposalProvider(new String[] { - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_TABLE), - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_TIMESTAMP), - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_PROJECT), - GeneralUtils.variablePattern(StreamPOITransferConsumer.VARIABLE_FILE) - })); - } - - setControl(composite); - - } - - - private void toggleExecProcessControls() { - final boolean isExecCommand = execProcessCheckbox.getSelection(); - execProcessText.setEnabled(isExecCommand); - } - - @Override - public void activatePage() - { - final StreamPOIConsumerSettings settings = getWizard().getPageSettings(this, StreamPOIConsumerSettings.class); - - directoryText.setText(CommonUtils.toString(settings.getOutputFolder())); - fileNameText.setText(CommonUtils.toString(settings.getOutputFilePattern())); - showFolderCheckbox.setSelection(settings.isOpenFolderOnFinish()); - execProcessCheckbox.setSelection(settings.isExecuteProcessOnFinish()); - execProcessText.setText(CommonUtils.toString(settings.getFinishProcessCommand())); - updatePageCompletion(); - toggleExecProcessControls(); - } - - @Override - protected boolean determinePageCompletion() - { - final StreamPOIConsumerSettings settings = getWizard().getPageSettings(this, StreamPOIConsumerSettings.class); - - boolean valid = true; - if (CommonUtils.isEmpty(settings.getOutputFolder())) { - valid = false; - } - if (CommonUtils.isEmpty(settings.getOutputFilePattern())) { - valid = false; - } - if (settings.isExecuteProcessOnFinish() && CommonUtils.isEmpty(settings.getFinishProcessCommand())) { - return false; - } - - //To avoid problem with BOM - //Do not TOUCH !!! - settings.setOutputEncodingBOM(false); - - return valid; - } - -} diff --git a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageSettings.java b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageSettings.java deleted file mode 100644 index c5fcf51555..0000000000 --- a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerPageSettings.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * DBeaver - Universal Database Manager - * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com) - * - * 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.data.office.export; - -import org.eclipse.jface.preference.PreferenceDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.jkiss.dbeaver.core.CoreMessages; -import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile; -import org.jkiss.dbeaver.registry.formatter.DataFormatterRegistry; -import org.jkiss.dbeaver.registry.transfer.DataTransferProcessorDescriptor; -import org.jkiss.dbeaver.runtime.properties.PropertySourceCustom; -import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerPageSettings; -import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings; -import org.jkiss.dbeaver.ui.UIUtils; -import org.jkiss.dbeaver.ui.preferences.PrefPageDataFormat; -import org.jkiss.dbeaver.ui.properties.PropertyTreeViewer; - -/** - * @author Andrey.Hitrin - * - */ - - - -public class StreamPOIConsumerPageSettings extends StreamConsumerPageSettings { - - private PropertyTreeViewer propsEditor; - private Combo formatProfilesCombo; - private PropertySourceCustom propertySource; - - - public StreamPOIConsumerPageSettings() { - super(); - setTitle(CoreMessages.data_transfer_wizard_settings_title); - setDescription(CoreMessages.data_transfer_wizard_settings_description); - setPageComplete(false); - } - - - @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); - } - - private Object getSelectedFormatterProfile() - { - DataFormatterRegistry registry = DataFormatterRegistry.getInstance(); - int selectionIndex = formatProfilesCombo.getSelectionIndex(); - if (selectionIndex < 0) { - return null; - } else if (selectionIndex == 0) { - return registry.getGlobalProfile(); - } else { - return registry.getCustomProfile(UIUtils.getComboSelection(formatProfilesCombo)); - } - } - - 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); - } - } - - @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(); - - } - - @Override - public void deactivatePage() - { - getWizard().getSettings().setProcessorProperties(propertySource.getPropertiesWithDefaults()); - } - - @Override - protected boolean determinePageCompletion() - { - - return true; - } -} diff --git a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerSettings.java b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerSettings.java deleted file mode 100644 index 8ddc34526e..0000000000 --- a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOIConsumerSettings.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * DBeaver - Universal Database Manager - * Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com) - * - * 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.data.office.export; - -import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings; - -/** - * @author Andrey.Hitrin - * - */ -public class StreamPOIConsumerSettings extends StreamConsumerSettings { -} diff --git a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOITransferConsumer.java b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOITransferConsumer.java deleted file mode 100644 index f311fe0349..0000000000 --- a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/export/StreamPOITransferConsumer.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * DBeaver - Universal Database Manager - * Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com) - * - * 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.data.office.export; - -import org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer; - -/** - * @author Andrey.Hitrin - * - */ -public class StreamPOITransferConsumer extends StreamTransferConsumer { - -} diff --git a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/handlers/OpenSpreadsheetHandler.java b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/handlers/OpenSpreadsheetHandler.java index 5f1ef4a6d1..7fa0db66fe 100644 --- a/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/handlers/OpenSpreadsheetHandler.java +++ b/plugins/org.jkiss.dbeaver.data.office/src/org/jkiss/dbeaver/data/office/handlers/OpenSpreadsheetHandler.java @@ -22,17 +22,16 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.ui.handlers.HandlerUtil; -import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.core.DBeaverUI; import org.jkiss.dbeaver.data.office.export.DataExporterXLSX; -import org.jkiss.dbeaver.data.office.export.StreamPOIConsumerSettings; -import org.jkiss.dbeaver.data.office.export.StreamPOITransferConsumer; import org.jkiss.dbeaver.model.runtime.AbstractJob; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.struct.DBSDataContainer; import org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings; import org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer; +import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings; +import org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer; import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.controls.resultset.IResultSetController; import org.jkiss.dbeaver.ui.controls.resultset.ResultSetCommandHandler; @@ -44,8 +43,6 @@ import java.util.Map; public class OpenSpreadsheetHandler extends AbstractHandler { - private static final Log log = Log.getLog(OpenSpreadsheetHandler.class); - @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -79,8 +76,8 @@ public class OpenSpreadsheetHandler extends AbstractHandler DataExporterXLSX exporter = new DataExporterXLSX(); - StreamPOITransferConsumer consumer = new StreamPOITransferConsumer(); - StreamPOIConsumerSettings settings = new StreamPOIConsumerSettings(); + StreamTransferConsumer consumer = new StreamTransferConsumer(); + StreamConsumerSettings settings = new StreamConsumerSettings(); settings.setOutputEncodingBOM(false); settings.setOpenFolderOnFinish(false); @@ -88,7 +85,7 @@ public class OpenSpreadsheetHandler extends AbstractHandler settings.setOutputFilePattern(tempFile.getName()); Map properties = DataExporterXLSX.getDefaultProperties(); - consumer.initTransfer(dataContainer, settings, exporter, properties); + consumer.initTransfer(dataContainer, settings, true, exporter, properties); DatabaseTransferProducer producer = new DatabaseTransferProducer(dataContainer); DatabaseProducerSettings producerSettings = new DatabaseProducerSettings(); @@ -99,12 +96,9 @@ public class OpenSpreadsheetHandler extends AbstractHandler consumer.finishTransfer(monitor, false); - DBeaverUI.asyncExec(new Runnable() { - @Override - public void run() { - if (!UIUtils.launchProgram(tempFile.getAbsolutePath())) { - DBeaverUI.getInstance().showError("Open XLSX", "Can't open XLSX file '" + tempFile.getAbsolutePath() + "'"); - } + DBeaverUI.asyncExec(() -> { + if (!UIUtils.launchProgram(tempFile.getAbsolutePath())) { + DBeaverUI.getInstance().showError("Open XLSX", "Can't open XLSX file '" + tempFile.getAbsolutePath() + "'"); } }); } catch (Exception e) { -- GitLab