Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
512468e8
by Tony Chemit at 2022-08-03T09:49:49+02:00
28 changed files:
- client/configuration/src/main/config/Client.ini
- client/configuration/src/main/i18n/getters/config.getter
- client/configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java
- client/core/src/main/java/fr/ird/observe/client/main/body/ClientConfigUI.java
- client/core/src/main/resources/observe-ui.properties
- client/datasource/actions/src/main/i18n/getters/java.getter
- client/datasource/actions/src/main/i18n/getters/jaxx.getter
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/ObserveKeyStrokesActions.java
- + client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/CsvExportUI.jaxx
- + client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/CsvExportUI.jcss
- + client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/CsvExportUIHandler.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportUI.jaxx
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportUI.jcss
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportUIHandler.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ResultTableModel.java
- + client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ChooseExportCsvDirectory.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/CopyResultToClipboard.java → client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ExportToClipboard.java
- + client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ExportToCsv.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ToggleConfigure.java
- + client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ToggleExport.java
- + client/datasource/actions/src/main/resources/icons/action-export-csv.png
- + client/datasource/actions/src/main/resources/icons/action-format-csv.png
- client/runner/src/main/i18n/translations/client-runner_en_GB.properties
- client/runner/src/main/i18n/translations/client-runner_es_ES.properties
- client/runner/src/main/i18n/translations/client-runner_fr_FR.properties
- toolkit/api/src/main/java/fr/ird/observe/dto/ObserveUtil.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/DataMatrix.java
Changes:
| ... | ... | @@ -409,6 +409,14 @@ defaultValue = ${instance.data.directory}/tmp |
| 409 | 409 | final = true
|
| 410 | 410 | transient = true
|
| 411 | 411 | |
| 412 | +[option exportDirectory]
|
|
| 413 | +description = observe.config.exportDirectory.description
|
|
| 414 | +key = instance.export.directory
|
|
| 415 | +type = file
|
|
| 416 | +defaultValue = ${instance.data.directory}/export
|
|
| 417 | +final = true
|
|
| 418 | +transient = true
|
|
| 419 | + |
|
| 412 | 420 | [option navigationEditModelFile]
|
| 413 | 421 | description = observe.config.ui.tree.edit.nodes
|
| 414 | 422 | key = instance.ui.file.tree.edit.nodes
|
| ... | ... | @@ -38,6 +38,7 @@ observe.config.defaultReportDirectory.description |
| 38 | 38 | observe.config.defaultReportFile.description
|
| 39 | 39 | observe.config.defaultResourcesDirectory.description
|
| 40 | 40 | observe.config.defaultValidationReportDirectory.description
|
| 41 | +observe.config.exportDirectory.description
|
|
| 41 | 42 | observe.config.feedBackDirectory.description
|
| 42 | 43 | observe.config.h2.can.editReferential.description
|
| 43 | 44 | observe.config.h2.can.migrate.description
|
| ... | ... | @@ -430,6 +430,9 @@ public class ClientConfig extends GeneratedClientConfig implements TripMapConfig |
| 430 | 430 | log.info(message);
|
| 431 | 431 | ClientResources.ObserveSwingPreferences.copyResource(preferencesFile);
|
| 432 | 432 | }
|
| 433 | + |
|
| 434 | + // 11 - export directory
|
|
| 435 | + createDirectory(ClientConfigOption.EXPORT_DIRECTORY);
|
|
| 433 | 436 | }
|
| 434 | 437 | |
| 435 | 438 | public void detectLocalDataBase() {
|
| ... | ... | @@ -415,6 +415,7 @@ public class ClientConfigUI extends JXTitledPanel implements WithClientUIContext |
| 415 | 415 | helper.addOption(ClientConfigOption.DATA_DIRECTORY);
|
| 416 | 416 | helper.addOption(ClientConfigOption.DB_DIRECTORY);
|
| 417 | 417 | helper.addOption(ClientConfigOption.BACKUP_DIRECTORY);
|
| 418 | + helper.addOption(ClientConfigOption.EXPORT_DIRECTORY);
|
|
| 418 | 419 | helper.addOption(ClientConfigOption.LOG_DIRECTORY);
|
| 419 | 420 | helper.addOption(ClientConfigOption.IMPORT_DIRECTORY);
|
| 420 | 421 | helper.addOption(ClientConfigOption.TEMPORARY_DIRECTORY);
|
| ... | ... | @@ -229,6 +229,7 @@ icon.action.wizard-pause=action-wizard-pause-16.png |
| 229 | 229 | icon.action.wizard-refresh=action-wizard-refresh-16.png
|
| 230 | 230 | icon.action.wizard-config=action-wizard-config-16.png
|
| 231 | 231 | icon.action.wizard-message=action-wizard-message-16.png
|
| 232 | +icon.action.export-csv=action-export-csv.png
|
|
| 232 | 233 | # couleurs au format (r,g,b)
|
| 233 | 234 | icon.Table.removeIcon=action-delete.png
|
| 234 | 235 | color.Table.lastRowColor=255,255,0
|
| ... | ... | @@ -9,6 +9,7 @@ observe.ui.action.admin.close |
| 9 | 9 | observe.ui.action.apply
|
| 10 | 10 | observe.ui.action.cancel
|
| 11 | 11 | observe.ui.action.choose.db.dump.directory
|
| 12 | +observe.ui.action.choose.export.csv.directory
|
|
| 12 | 13 | observe.ui.action.choose.reportFile
|
| 13 | 14 | observe.ui.action.choose.reportFile.description
|
| 14 | 15 | observe.ui.action.close
|
| ... | ... | @@ -19,6 +20,7 @@ observe.ui.action.configuration.tip |
| 19 | 20 | observe.ui.action.continue
|
| 20 | 21 | observe.ui.action.copy.to.clipBoard
|
| 21 | 22 | observe.ui.action.do.backup.tip
|
| 23 | +observe.ui.action.export.tip
|
|
| 22 | 24 | observe.ui.action.goto.next.stage
|
| 23 | 25 | observe.ui.action.goto.next.stage.tip
|
| 24 | 26 | observe.ui.action.goto.previous.stage
|
| ... | ... | @@ -69,6 +71,9 @@ observe.ui.datasource.editor.actions.pairing.tip |
| 69 | 71 | observe.ui.datasource.editor.actions.pairing.title
|
| 70 | 72 | observe.ui.datasource.editor.actions.report
|
| 71 | 73 | observe.ui.datasource.editor.actions.report.description
|
| 74 | +observe.ui.datasource.editor.actions.report.exportToCsv
|
|
| 75 | +observe.ui.datasource.editor.actions.report.exportToCsv.done
|
|
| 76 | +observe.ui.datasource.editor.actions.report.exportToCsv.tip
|
|
| 72 | 77 | observe.ui.datasource.editor.actions.report.no.report.found
|
| 73 | 78 | observe.ui.datasource.editor.actions.report.report.count.found
|
| 74 | 79 | observe.ui.datasource.editor.actions.report.title
|
| ... | ... | @@ -175,6 +180,7 @@ observe.ui.menu.actions |
| 175 | 180 | observe.ui.message.no.report.selected
|
| 176 | 181 | observe.ui.message.select.report
|
| 177 | 182 | observe.ui.title.choose.db.dump.directory
|
| 183 | +observe.ui.title.choose.export.csv.directory
|
|
| 178 | 184 | observe.ui.title.choose.reportFile
|
| 179 | 185 | observe.ui.title.storage.info
|
| 180 | 186 | observe.ui.tree.action.collapseAll.tip
|
| ... | ... | @@ -11,6 +11,7 @@ observe.info.selected.validators |
| 11 | 11 | observe.info.validation.credentials
|
| 12 | 12 | observe.ui.action.show.properties
|
| 13 | 13 | observe.ui.action.show.properties.tip
|
| 14 | +observe.ui.choice.cancel.tip
|
|
| 14 | 15 | observe.ui.datasource.editor.actions.operation.configuration
|
| 15 | 16 | observe.ui.datasource.editor.actions.operations
|
| 16 | 17 | observe.ui.datasource.editor.actions.report.auto.copy.to.clipboard
|
| ... | ... | @@ -39,6 +39,9 @@ public class ObserveKeyStrokesActions extends ObserveKeyStrokesEditorApi { |
| 39 | 39 | |
| 40 | 40 | public static final KeyStroke KEY_STROKE_DATA_SYNCHRO_COPY_RIGHT = KeyStroke.getKeyStroke("pressed F9");
|
| 41 | 41 | public static final KeyStroke KEY_STROKE_DATA_SYNCHRO_DELETE_RIGHT = KeyStroke.getKeyStroke("pressed F10");
|
| 42 | + public static final KeyStroke KEY_STROKE_EXPORT_POPUP = KeyStroke.getKeyStroke("pressed F10");
|
|
| 43 | + public static final KeyStroke KEY_STROKE_EXPORT_CLIPBOARD = KeyStroke.getKeyStroke("pressed F2");
|
|
| 44 | + public static final KeyStroke KEY_STROKE_EXPORT_CSV = KeyStroke.getKeyStroke("pressed F3");
|
|
| 42 | 45 | |
| 43 | 46 | public static final KeyStroke KEY_STROKE_EXIT = KeyStroke.getKeyStroke("alt pressed F");
|
| 44 | 47 | } |
| 1 | +<!--
|
|
| 2 | + #%L
|
|
| 3 | + ObServe Client :: DataSource :: Actions
|
|
| 4 | + %%
|
|
| 5 | + Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 6 | + %%
|
|
| 7 | + This program is free software: you can redistribute it and/or modify
|
|
| 8 | + it under the terms of the GNU General Public License as
|
|
| 9 | + published by the Free Software Foundation, either version 3 of the
|
|
| 10 | + License, or (at your option) any later version.
|
|
| 11 | + This program is distributed in the hope that it will be useful,
|
|
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 14 | + GNU General Public License for more details.
|
|
| 15 | + You should have received a copy of the GNU General Public
|
|
| 16 | + License along with this program. If not, see
|
|
| 17 | + <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 18 | + #L%
|
|
| 19 | + -->
|
|
| 20 | +<Table id="reportConfig">
|
|
| 21 | + <import>
|
|
| 22 | + java.io.File
|
|
| 23 | + javax.swing.Box
|
|
| 24 | + javax.swing.BoxLayout
|
|
| 25 | + java.awt.Dimension
|
|
| 26 | + |
|
| 27 | + static fr.ird.observe.client.util.UIHelper.getStringValue
|
|
| 28 | + </import>
|
|
| 29 | + <ReportModel id='stepModel' initializer='getContextValue(ReportModel.class)'/>
|
|
| 30 | + <row>
|
|
| 31 | + <cell anchor="west">
|
|
| 32 | + <JLabel id="directoryLabel"/>
|
|
| 33 | + </cell>
|
|
| 34 | + <cell weightx='1' fill="horizontal">
|
|
| 35 | + <JTextField id='directoryText' onKeyReleased='getHandler().changeDirectory(new File(((JTextField)event.getSource()).getText()))'/>
|
|
| 36 | + </cell>
|
|
| 37 | + <cell anchor="east">
|
|
| 38 | + <JButton id="chooseExportCsvDirectory"/>
|
|
| 39 | + </cell>
|
|
| 40 | + </row>
|
|
| 41 | + <row>
|
|
| 42 | + <cell anchor="west">
|
|
| 43 | + <JLabel id="fileLabel"/>
|
|
| 44 | + </cell>
|
|
| 45 | + <cell weightx='1' fill="horizontal" columns="2">
|
|
| 46 | + <JTextField id='filenameText' onKeyReleased='getHandler().changeFilename(((JTextField)event.getSource()).getText())'/>
|
|
| 47 | + </cell>
|
|
| 48 | + </row>
|
|
| 49 | + <row>
|
|
| 50 | + <cell columns="3" anchor="west" fill="both">
|
|
| 51 | + <JPanel id='actions' layout="{new BoxLayout(actions, BoxLayout.Y_AXIS)}">
|
|
| 52 | + <JPanel id="cancelMessagePanel" layout="{new GridLayout(0, 1)}">
|
|
| 53 | + <JSeparator constructorParams="JSeparator.HORIZONTAL"/>
|
|
| 54 | + <JLabel id="cancelMessage" styleClass="information italic"/>
|
|
| 55 | + <Component initializer="Box.createRigidArea(new Dimension(10, 5))"/>
|
|
| 56 | + </JPanel>
|
|
| 57 | + </JPanel>
|
|
| 58 | + </cell>
|
|
| 59 | + </row>
|
|
| 60 | +</Table> |
| 1 | +/*-
|
|
| 2 | + * #%L
|
|
| 3 | + * ObServe Client :: DataSource :: Actions
|
|
| 4 | + * %%
|
|
| 5 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 6 | + * %%
|
|
| 7 | + * This program is free software: you can redistribute it and/or modify
|
|
| 8 | + * it under the terms of the GNU General Public License as
|
|
| 9 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 10 | + * License, or (at your option) any later version.
|
|
| 11 | + *
|
|
| 12 | + * This program is distributed in the hope that it will be useful,
|
|
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 | + * GNU General Public License for more details.
|
|
| 16 | + *
|
|
| 17 | + * You should have received a copy of the GNU General Public
|
|
| 18 | + * License along with this program. If not, see
|
|
| 19 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 | + * #L%
|
|
| 21 | + */
|
|
| 22 | + |
|
| 23 | +#directoryLabel {
|
|
| 24 | + text:"observe.Common.directory";
|
|
| 25 | +}
|
|
| 26 | + |
|
| 27 | +#directoryText {
|
|
| 28 | + text:{stepModel.getExportCsvFile().getParent()};
|
|
| 29 | +}
|
|
| 30 | + |
|
| 31 | +#fileLabel {
|
|
| 32 | + text:"observe.Common.file";
|
|
| 33 | +}
|
|
| 34 | + |
|
| 35 | +#filenameText {
|
|
| 36 | + text:{stepModel.getExportCsvFileName()};
|
|
| 37 | +}
|
|
| 38 | + |
|
| 39 | +#cancelMessage {
|
|
| 40 | + text:"observe.ui.choice.cancel.tip";
|
|
| 41 | +} |
| 1 | +package fr.ird.observe.client.datasource.actions.report;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Client :: DataSource :: Actions
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import fr.ird.observe.dto.ObserveUtil;
|
|
| 26 | +import org.nuiton.jaxx.runtime.spi.UIHandler;
|
|
| 27 | + |
|
| 28 | +import java.io.File;
|
|
| 29 | + |
|
| 30 | +/**
|
|
| 31 | + * Created on 02/08/2022.
|
|
| 32 | + *
|
|
| 33 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 34 | + * @since 9.0.7
|
|
| 35 | + */
|
|
| 36 | +public class CsvExportUIHandler implements UIHandler<CsvExportUI> {
|
|
| 37 | + private CsvExportUI ui;
|
|
| 38 | + |
|
| 39 | + @Override
|
|
| 40 | + public void beforeInit(CsvExportUI ui) {
|
|
| 41 | + this.ui = ui;
|
|
| 42 | + }
|
|
| 43 | + |
|
| 44 | + public void changeDirectory(File f) {
|
|
| 45 | + ui.getStepModel().setExportCsvFile(new File(f, ObserveUtil.addCsvExtension(ui.getStepModel().getExportCsvFileName())));
|
|
| 46 | + }
|
|
| 47 | + |
|
| 48 | + public void changeFilename(String filename) {
|
|
| 49 | + ui.getStepModel().setExportCsvFile(new File(ui.getDirectoryText().getText(), ObserveUtil.addCsvExtension(filename)));
|
|
| 50 | + }
|
|
| 51 | +} |
| ... | ... | @@ -27,6 +27,7 @@ import fr.ird.observe.client.datasource.actions.AdminStep; |
| 27 | 27 | import fr.ird.observe.client.datasource.actions.AdminUIModel;
|
| 28 | 28 | import fr.ird.observe.client.datasource.actions.config.SelectDataModel;
|
| 29 | 29 | import fr.ird.observe.client.datasource.editor.api.wizard.connexion.DataSourceSelectorModel;
|
| 30 | +import fr.ird.observe.dto.ObserveUtil;
|
|
| 30 | 31 | import fr.ird.observe.dto.report.Report;
|
| 31 | 32 | import fr.ird.observe.dto.report.ReportBuilder;
|
| 32 | 33 | import fr.ird.observe.navigation.tree.selection.SelectionTreeConfig;
|
| ... | ... | @@ -41,6 +42,7 @@ import java.io.IOException; |
| 41 | 42 | import java.net.URL;
|
| 42 | 43 | import java.nio.file.Files;
|
| 43 | 44 | import java.util.Collections;
|
| 45 | +import java.util.Date;
|
|
| 44 | 46 | import java.util.List;
|
| 45 | 47 | import java.util.Map;
|
| 46 | 48 | import java.util.Objects;
|
| ... | ... | @@ -57,6 +59,8 @@ import java.util.stream.Collectors; |
| 57 | 59 | @GenerateJavaBeanDefinition
|
| 58 | 60 | public class ReportModel extends AdminActionModel {
|
| 59 | 61 | |
| 62 | + public static final String EXPORT_CSV_FILE_PROPERTY_NAME = "exportCsvFile";
|
|
| 63 | + public static final String EXPORT_CSV_FILE_NAME_PROPERTY_NAME = "exportCsvFileName";
|
|
| 60 | 64 | public static final String SELECTED_REPORT_PROPERTY_NAME = "selectedReport";
|
| 61 | 65 | |
| 62 | 66 | public static final String REPORTS_PROPERTY_NAME = "reports";
|
| ... | ... | @@ -115,6 +119,10 @@ public class ReportModel extends AdminActionModel { |
| 115 | 119 | * Pour copier les entêtes de colonnes
|
| 116 | 120 | */
|
| 117 | 121 | protected boolean copyColumnHeaders = true;
|
| 122 | + /**
|
|
| 123 | + * Where to do optional csv export.
|
|
| 124 | + */
|
|
| 125 | + protected File exportCsvFile = new File("");
|
|
| 118 | 126 | private List<Report> allReports;
|
| 119 | 127 | private SelectDataModel selectDataModel;
|
| 120 | 128 | |
| ... | ... | @@ -125,6 +133,22 @@ public class ReportModel extends AdminActionModel { |
| 125 | 133 | addPropertyChangeListener(REPORT_FILE_PROPERTY_NAME, evt -> updateReports());
|
| 126 | 134 | }
|
| 127 | 135 | |
| 136 | + public File getExportCsvFile() {
|
|
| 137 | + return exportCsvFile;
|
|
| 138 | + }
|
|
| 139 | + |
|
| 140 | + public void setExportCsvFile(File exportCsvFile) {
|
|
| 141 | + File oldValue = getExportCsvFile();
|
|
| 142 | + String oldBackupFileName = getExportCsvFileName();
|
|
| 143 | + this.exportCsvFile = exportCsvFile;
|
|
| 144 | + firePropertyChange(EXPORT_CSV_FILE_PROPERTY_NAME, oldValue, exportCsvFile);
|
|
| 145 | + firePropertyChange(EXPORT_CSV_FILE_NAME_PROPERTY_NAME, oldBackupFileName, getExportCsvFileName());
|
|
| 146 | + }
|
|
| 147 | + |
|
| 148 | + public String getExportCsvFileName() {
|
|
| 149 | + return ObserveUtil.removeCsvExtension(exportCsvFile.getName());
|
|
| 150 | + }
|
|
| 151 | + |
|
| 128 | 152 | @Override
|
| 129 | 153 | public void start(AdminUIModel uiModel) {
|
| 130 | 154 | |
| ... | ... | @@ -341,4 +365,7 @@ public class ReportModel extends AdminActionModel { |
| 341 | 365 | log.info(String.format("Detects %d report(s).", reports.size()));
|
| 342 | 366 | }
|
| 343 | 367 | |
| 368 | + public File newExportCsvFile() {
|
|
| 369 | + return new File(getClientConfig().getExportDirectory(), String.format("export-%1$s--%2$tF--%2$tk-%2$tM-%2$tS.csv", Objects.requireNonNull(getSelectedReport()).getId().replaceAll("\\.", "_"), new Date()));
|
|
| 370 | + }
|
|
| 344 | 371 | } |
| ... | ... | @@ -50,31 +50,22 @@ public void destroy() { |
| 50 | 50 | ]]>
|
| 51 | 51 | </script>
|
| 52 | 52 | <JPanel id='PENDING_content' layout='{new BorderLayout()}'>
|
| 53 | -<!-- <JPanel id='northPanel' constraints='BorderLayout.NORTH' layout='{new GridLayout(1, 2)}'>-->
|
|
| 54 | - <JXTitledPanel id="configurationPane" contentContainer="{configurationPanel}" constraints='BorderLayout.NORTH'>
|
|
| 55 | - <JPanel id="configurationPanel" layout='{new BorderLayout()}'>
|
|
| 56 | - <JPanel id='requestSelectorPane' constraints='BorderLayout.NORTH' layout='{new BorderLayout()}'>
|
|
| 57 | - <JToolBar id='toolbar' constraints='BorderLayout.WEST'>
|
|
| 58 | - <JButton id="resetSelectedReport" onActionPerformed="getHandler().updateSelectedReport(null)"/>
|
|
| 59 | - </JToolBar>
|
|
| 60 | - <JComboBox id='reportSelector' constraints='BorderLayout.CENTER' onItemStateChanged='getHandler().updateSelectedReportFromEvent(event)'/>
|
|
| 61 | - </JPanel>
|
|
| 62 | - <JScrollPane id='reportVariableSelectorPane' constraints='BorderLayout.CENTER'>
|
|
| 63 | - <JPanel id='reportVariableSelectorPanel' layout="{new GridLayout(0,1)}"/>
|
|
| 64 | - </JScrollPane>
|
|
| 65 | - <JScrollPane id='reportDescriptionPane' constraints='BorderLayout.SOUTH'>
|
|
| 66 | - <JTextArea id='reportDescription'/>
|
|
| 67 | - </JScrollPane>
|
|
| 53 | + <JXTitledPanel id="configurationPane" contentContainer="{configurationPanel}" constraints='BorderLayout.NORTH'>
|
|
| 54 | + <JPanel id="configurationPanel" layout='{new BorderLayout()}'>
|
|
| 55 | + <JPanel id='requestSelectorPane' constraints='BorderLayout.NORTH' layout='{new BorderLayout()}'>
|
|
| 56 | + <JToolBar id='toolbar' constraints='BorderLayout.WEST'>
|
|
| 57 | + <JButton id="resetSelectedReport" onActionPerformed="getHandler().updateSelectedReport(null)" styleClass="enabledIfReportSelected"/>
|
|
| 58 | + </JToolBar>
|
|
| 59 | + <JComboBox id='reportSelector' constraints='BorderLayout.CENTER' onItemStateChanged='getHandler().updateSelectedReportFromEvent(event)'/>
|
|
| 68 | 60 | </JPanel>
|
| 69 | - </JXTitledPanel>
|
|
| 70 | -<!-- <JPanel id="copyPane" layout='{new BorderLayout()}'>-->
|
|
| 71 | -<!-- <JPanel id='copyOptions' constraints='BorderLayout.NORTH' beanScope="stepModel" layout="{new GridLayout(0,1)}">-->
|
|
| 72 | -<!-- <BeanCheckBox id='autoCopyToClipboard'/>-->
|
|
| 73 | -<!-- <BeanCheckBox id='copyRowHeaders'/>-->
|
|
| 74 | -<!-- <BeanCheckBox id='copyColumnHeaders'/>-->
|
|
| 75 | -<!-- </JPanel>-->
|
|
| 76 | -<!-- </JPanel>-->
|
|
| 77 | -<!-- </JPanel>-->
|
|
| 61 | + <JScrollPane id='reportVariableSelectorPane' constraints='BorderLayout.CENTER'>
|
|
| 62 | + <JPanel id='reportVariableSelectorPanel' layout="{new GridLayout(0,1)}"/>
|
|
| 63 | + </JScrollPane>
|
|
| 64 | + <JScrollPane id='reportDescriptionPane' constraints='BorderLayout.SOUTH'>
|
|
| 65 | + <JTextArea id='reportDescription'/>
|
|
| 66 | + </JScrollPane>
|
|
| 67 | + </JPanel>
|
|
| 68 | + </JXTitledPanel>
|
|
| 78 | 69 | <JXTitledPanel id="resultPanel" constraints='BorderLayout.CENTER' contentContainer="{resultPane}" rightDecoration='{titleRightToolBar}'>
|
| 79 | 70 | <JScrollPane id='resultPane'>
|
| 80 | 71 | <JXTable id='resultTable'/>
|
| ... | ... | @@ -84,8 +75,12 @@ public void destroy() { |
| 84 | 75 | <BeanCheckBox id='copyRowHeaders'/>
|
| 85 | 76 | <BeanCheckBox id='copyColumnHeaders'/>
|
| 86 | 77 | </JPopupMenu>
|
| 78 | + <JPopupMenu id='exportPopup'>
|
|
| 79 | + <JMenuItem id='exportToClipboard' styleClass="enabledIfReportSelected"/>
|
|
| 80 | + <JMenuItem id='exportToCsv' styleClass="enabledIfReportSelected"/>
|
|
| 81 | + </JPopupMenu>
|
|
| 87 | 82 | <JToolBar id='titleRightToolBar'>
|
| 88 | - <JButton id="copyResultToClipboard"/>
|
|
| 83 | + <JToggleButton id='toggleExport'/>
|
|
| 89 | 84 | <JToggleButton id='toggleConfigure'/>
|
| 90 | 85 | </JToolBar>
|
| 91 | 86 | </JXTitledPanel>
|
| ... | ... | @@ -30,6 +30,10 @@ BeanCheckBox { |
| 30 | 30 | bean:{stepModel};
|
| 31 | 31 | }
|
| 32 | 32 | |
| 33 | +.enabledIfReportSelected {
|
|
| 34 | + enabled:{stepModel.getSelectedReport() != null};
|
|
| 35 | +}
|
|
| 36 | + |
|
| 33 | 37 | #reportVariableSelectorPanel {
|
| 34 | 38 | border:{new TitledBorder(t("observe.ui.datasource.editor.actions.report.variables") + " ")};
|
| 35 | 39 | }
|
| ... | ... | @@ -76,7 +80,6 @@ BeanCheckBox { |
| 76 | 80 | #resetSelectedReport {
|
| 77 | 81 | actionIcon:"combobox-reset";
|
| 78 | 82 | toolTipText:"observe.ui.datasource.editor.actions.synchro.report.reset.tip";
|
| 79 | - enabled:{stepModel.getSelectedReport() != null};
|
|
| 80 | 83 | mnemonic:R;
|
| 81 | 84 | }
|
| 82 | 85 | |
| ... | ... | @@ -94,7 +97,3 @@ BeanCheckBox { |
| 94 | 97 | text:"observe.ui.datasource.editor.actions.report.copy.column.headers";
|
| 95 | 98 | toolTipText:"observe.ui.datasource.editor.actions.report.copy.column.headers.tip";
|
| 96 | 99 | } |
| 97 | - |
|
| 98 | -#copyResultToClipboard {
|
|
| 99 | - enabled:{stepModel.isValid()};
|
|
| 100 | -} |
| ... | ... | @@ -24,7 +24,7 @@ package fr.ird.observe.client.datasource.actions.report; |
| 24 | 24 | import fr.ird.observe.client.datasource.actions.AdminTabUIHandler;
|
| 25 | 25 | import fr.ird.observe.client.datasource.actions.AdminUIModel;
|
| 26 | 26 | import fr.ird.observe.client.datasource.actions.config.ConfigUI;
|
| 27 | -import fr.ird.observe.client.datasource.actions.report.actions.CopyResultToClipboard;
|
|
| 27 | +import fr.ird.observe.client.datasource.actions.report.actions.ExportToClipboard;
|
|
| 28 | 28 | import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
|
| 29 | 29 | import fr.ird.observe.client.util.ObserveSwingTechnicalException;
|
| 30 | 30 | import fr.ird.observe.client.util.UIHelper;
|
| ... | ... | @@ -319,7 +319,7 @@ public class ReportUIHandler extends AdminTabUIHandler<ReportUI> implements UIHa |
| 319 | 319 | |
| 320 | 320 | // mise a jour du clipboard automatique si requis
|
| 321 | 321 | if (stepModel.isAutoCopyToClipboard()) {
|
| 322 | - CopyResultToClipboard.copyReportToClipBoard(report, stepModel);
|
|
| 322 | + ExportToClipboard.copyReportToClipBoard(report, stepModel);
|
|
| 323 | 323 | }
|
| 324 | 324 | } catch (Exception e) {
|
| 325 | 325 | stepModel.getResultModel().clear();
|
| ... | ... | @@ -220,6 +220,14 @@ public class ResultTableModel extends AbstractTableModel { |
| 220 | 220 | }
|
| 221 | 221 | |
| 222 | 222 | public String getClipboardContent(boolean copyRowHeaders, boolean copyColumnHeaders) {
|
| 223 | + return getDataContent(copyRowHeaders, copyColumnHeaders, true,'\t');
|
|
| 224 | + }
|
|
| 225 | + |
|
| 226 | + public String getCsvContent() {
|
|
| 227 | + return getDataContent(true, true, true, ';');
|
|
| 228 | + }
|
|
| 229 | + |
|
| 230 | + public String getDataContent(boolean copyRowHeaders, boolean copyColumnHeaders, boolean escapeCell, char separator) {
|
|
| 223 | 231 | if (data == null) {
|
| 224 | 232 | return "";
|
| 225 | 233 | }
|
| ... | ... | @@ -234,9 +242,9 @@ public class ResultTableModel extends AbstractTableModel { |
| 234 | 242 | String rowName = getColumnName(i);
|
| 235 | 243 | columns.setValue(i, 0, rowName);
|
| 236 | 244 | });
|
| 237 | - result = columns.getClipboardContent(true, true, false, '\t');
|
|
| 245 | + result = columns.getClipboardContent(true, true, escapeCell, separator);
|
|
| 238 | 246 | }
|
| 239 | - result += data.getClipboardContent(copyRowHeaders || !withRowHeader, true, false, '\t');
|
|
| 247 | + result += data.getClipboardContent(copyRowHeaders || !withRowHeader, true, escapeCell, separator);
|
|
| 240 | 248 | return result;
|
| 241 | 249 | }
|
| 242 | 250 |
| 1 | +package fr.ird.observe.client.datasource.actions.report.actions;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Client :: DataSource :: Actions
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import fr.ird.observe.client.datasource.actions.ObserveKeyStrokesActions;
|
|
| 26 | +import fr.ird.observe.client.datasource.actions.report.CsvExportUI;
|
|
| 27 | +import fr.ird.observe.client.util.UIFileHelper;
|
|
| 28 | +import org.nuiton.jaxx.runtime.swing.action.JComponentActionSupport;
|
|
| 29 | + |
|
| 30 | +import java.awt.event.ActionEvent;
|
|
| 31 | +import java.io.File;
|
|
| 32 | + |
|
| 33 | +import static io.ultreia.java4all.i18n.I18n.t;
|
|
| 34 | + |
|
| 35 | +/**
|
|
| 36 | + * Created on 02/08/2022.
|
|
| 37 | + *
|
|
| 38 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 39 | + * @since 9.0.7
|
|
| 40 | + */
|
|
| 41 | +public class ChooseExportCsvDirectory extends JComponentActionSupport<CsvExportUI> {
|
|
| 42 | + |
|
| 43 | + public ChooseExportCsvDirectory() {
|
|
| 44 | + super("", t("observe.ui.action.choose.export.csv.directory"), "fileChooser", ObserveKeyStrokesActions.KEY_STROKE_STORAGE_DO_CHOOSE_FILE);
|
|
| 45 | + }
|
|
| 46 | + |
|
| 47 | + @Override
|
|
| 48 | + protected void doActionPerformed(ActionEvent e, CsvExportUI ui) {
|
|
| 49 | + File f = UIFileHelper.chooseDirectory(
|
|
| 50 | + ui,
|
|
| 51 | + t("observe.ui.title.choose.export.csv.directory"),
|
|
| 52 | + t("observe.ui.action.choose.export.csv.directory"),
|
|
| 53 | + new File(ui.getDirectoryText().getText())
|
|
| 54 | + );
|
|
| 55 | + if (f != null) {
|
|
| 56 | + ui.getHandler().changeDirectory(f);
|
|
| 57 | + }
|
|
| 58 | + }
|
|
| 59 | +} |
| ... | ... | @@ -22,6 +22,7 @@ package fr.ird.observe.client.datasource.actions.report.actions; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | +import fr.ird.observe.client.datasource.actions.ObserveKeyStrokesActions;
|
|
| 25 | 26 | import fr.ird.observe.client.datasource.actions.actions.AdminTabUIActionSupport;
|
| 26 | 27 | import fr.ird.observe.client.datasource.actions.report.ReportModel;
|
| 27 | 28 | import fr.ird.observe.client.datasource.actions.report.ReportUI;
|
| ... | ... | @@ -35,12 +36,16 @@ import java.awt.event.ActionEvent; |
| 35 | 36 | |
| 36 | 37 | import static io.ultreia.java4all.i18n.I18n.t;
|
| 37 | 38 | |
| 38 | -public class CopyResultToClipboard extends AdminTabUIActionSupport<ReportUI> {
|
|
| 39 | +public class ExportToClipboard extends AdminTabUIActionSupport<ReportUI> {
|
|
| 39 | 40 | |
| 40 | - private static final Logger log = LogManager.getLogger(CopyResultToClipboard.class);
|
|
| 41 | + private static final Logger log = LogManager.getLogger(ExportToClipboard.class);
|
|
| 41 | 42 | |
| 42 | - public CopyResultToClipboard() {
|
|
| 43 | - super(""/*t("observe.ui.action.copy")*/, t("observe.ui.datasource.editor.actions.synchro.copy.tip"), "report-copy", 'C');
|
|
| 43 | + public ExportToClipboard() {
|
|
| 44 | + super("observe.ui.datasource.editor.actions.report.exportToClipboard",
|
|
| 45 | + t("observe.ui.datasource.editor.actions.synchro.copy.tip"),
|
|
| 46 | + "report-copy",
|
|
| 47 | + ObserveKeyStrokesActions.KEY_STROKE_EXPORT_CLIPBOARD);
|
|
| 48 | + setCheckMenuItemIsArmed(false);
|
|
| 44 | 49 | }
|
| 45 | 50 | |
| 46 | 51 | public static void copyReportToClipBoard(Report report, ReportModel stepModel) {
|
| 1 | +package fr.ird.observe.client.datasource.actions.report.actions;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Client :: DataSource :: Actions
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import fr.ird.observe.client.datasource.actions.ObserveKeyStrokesActions;
|
|
| 26 | +import fr.ird.observe.client.datasource.actions.actions.AdminTabUIActionSupport;
|
|
| 27 | +import fr.ird.observe.client.datasource.actions.report.CsvExportUI;
|
|
| 28 | +import fr.ird.observe.client.datasource.actions.report.ReportModel;
|
|
| 29 | +import fr.ird.observe.client.datasource.actions.report.ReportUI;
|
|
| 30 | +import fr.ird.observe.client.datasource.actions.report.ResultTableModel;
|
|
| 31 | +import fr.ird.observe.client.datasource.editor.api.ObserveKeyStrokesEditorApi;
|
|
| 32 | +import fr.ird.observe.client.datasource.usage.UsageUIHandlerSupport;
|
|
| 33 | +import fr.ird.observe.client.util.UIHelper;
|
|
| 34 | +import fr.ird.observe.dto.ObserveUtil;
|
|
| 35 | +import org.apache.logging.log4j.LogManager;
|
|
| 36 | +import org.apache.logging.log4j.Logger;
|
|
| 37 | +import org.nuiton.jaxx.runtime.context.JAXXInitialContext;
|
|
| 38 | + |
|
| 39 | +import javax.swing.AbstractAction;
|
|
| 40 | +import javax.swing.Action;
|
|
| 41 | +import javax.swing.ActionMap;
|
|
| 42 | +import javax.swing.InputMap;
|
|
| 43 | +import javax.swing.JButton;
|
|
| 44 | +import javax.swing.JComponent;
|
|
| 45 | +import javax.swing.JOptionPane;
|
|
| 46 | +import javax.swing.KeyStroke;
|
|
| 47 | +import java.awt.Dimension;
|
|
| 48 | +import java.awt.event.ActionEvent;
|
|
| 49 | +import java.beans.PropertyChangeEvent;
|
|
| 50 | +import java.beans.PropertyChangeListener;
|
|
| 51 | +import java.io.File;
|
|
| 52 | +import java.io.IOException;
|
|
| 53 | +import java.nio.charset.StandardCharsets;
|
|
| 54 | +import java.nio.file.Files;
|
|
| 55 | +import java.nio.file.Path;
|
|
| 56 | +import java.util.Objects;
|
|
| 57 | + |
|
| 58 | +import static io.ultreia.java4all.i18n.I18n.t;
|
|
| 59 | + |
|
| 60 | +/**
|
|
| 61 | + * Created on 02/08/2022.
|
|
| 62 | + *
|
|
| 63 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 64 | + * @since 9.0.7
|
|
| 65 | + */
|
|
| 66 | +public class ExportToCsv extends AdminTabUIActionSupport<ReportUI> implements PropertyChangeListener {
|
|
| 67 | + |
|
| 68 | + private static final Logger log = LogManager.getLogger(ExportToClipboard.class);
|
|
| 69 | + private JButton applyButton;
|
|
| 70 | + |
|
| 71 | + public ExportToCsv() {
|
|
| 72 | + super(t("observe.ui.datasource.editor.actions.report.exportToCsv"),
|
|
| 73 | + t("observe.ui.datasource.editor.actions.report.exportToCsv.tip"),
|
|
| 74 | + "export-csv",
|
|
| 75 | + ObserveKeyStrokesActions.KEY_STROKE_EXPORT_CSV);
|
|
| 76 | + setCheckMenuItemIsArmed(false);
|
|
| 77 | + }
|
|
| 78 | + |
|
| 79 | + @Override
|
|
| 80 | + protected void doActionPerformed(ActionEvent e, ReportUI ui) {
|
|
| 81 | + ReportModel stepModel = ui.getStepModel();
|
|
| 82 | + JAXXInitialContext context = new JAXXInitialContext().add(stepModel);
|
|
| 83 | + CsvExportUI exportUi = new CsvExportUI(context);
|
|
| 84 | + KeyStroke keyStroke = ObserveKeyStrokesActions.KEY_STROKE_ALT_ENTER;
|
|
| 85 | + |
|
| 86 | + String applyText = ObserveKeyStrokesEditorApi.suffixTextWithKeyStroke(t("observe.ui.action.apply"), keyStroke);
|
|
| 87 | + |
|
| 88 | + |
|
| 89 | + Object[] options = {applyText};
|
|
| 90 | + |
|
| 91 | + |
|
| 92 | + JOptionPane optionPane = new JOptionPane(exportUi, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[0]);
|
|
| 93 | + |
|
| 94 | + applyButton = UsageUIHandlerSupport.findButton(optionPane, applyText);
|
|
| 95 | + Objects.requireNonNull(applyButton).setEnabled(false);
|
|
| 96 | + |
|
| 97 | + stepModel.addPropertyChangeListener(ReportModel.EXPORT_CSV_FILE_PROPERTY_NAME, this);
|
|
| 98 | + |
|
| 99 | + try {
|
|
| 100 | + AbstractAction applyAction = new AbstractAction() {
|
|
| 101 | + @Override
|
|
| 102 | + public void actionPerformed(ActionEvent e) {
|
|
| 103 | + applyButton.doClick();
|
|
| 104 | + }
|
|
| 105 | + };
|
|
| 106 | + |
|
| 107 | + applyAction.putValue(Action.ACCELERATOR_KEY, keyStroke);
|
|
| 108 | + applyAction.putValue(Action.NAME, applyText);
|
|
| 109 | + applyAction.putValue(Action.SMALL_ICON, UIHelper.getContentActionIcon("save"));
|
|
| 110 | + |
|
| 111 | + applyButton.setIcon(UIHelper.getContentActionIcon("save"));
|
|
| 112 | + |
|
| 113 | + InputMap inputMap = optionPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
|
| 114 | + inputMap.put((KeyStroke) applyAction.getValue(Action.ACCELERATOR_KEY), "apply");
|
|
| 115 | + |
|
| 116 | + ActionMap actionMap = optionPane.getActionMap();
|
|
| 117 | + actionMap.put("apply", applyAction);
|
|
| 118 | + |
|
| 119 | + File exportFile = stepModel.newExportCsvFile();
|
|
| 120 | + ui.getStepModel().setExportCsvFile(exportFile);
|
|
| 121 | + |
|
| 122 | + int response = UIHelper.askUser(getMainUI(), optionPane, new Dimension(600, 220), t("observe.ui.datasource.editor.actions.report.exportToCsv.tip"), options);
|
|
| 123 | + |
|
| 124 | + boolean accept = response == 0;
|
|
| 125 | + if (accept) {
|
|
| 126 | + Path exportCsvFile = stepModel.getExportCsvFile().toPath();
|
|
| 127 | + ResultTableModel model = stepModel.getResultModel();
|
|
| 128 | + String content = model.getCsvContent();
|
|
| 129 | + log.info("Export csv to: " + exportCsvFile);
|
|
| 130 | + try {
|
|
| 131 | + Files.write(exportCsvFile, content.getBytes(StandardCharsets.UTF_8));
|
|
| 132 | + } catch (IOException ex) {
|
|
| 133 | + throw new RuntimeException("Can't export csv to file: " + exportCsvFile, ex);
|
|
| 134 | + }
|
|
| 135 | + setUiStatus(t("observe.ui.datasource.editor.actions.report.exportToCsv.done", exportCsvFile));
|
|
| 136 | + }
|
|
| 137 | + } finally {
|
|
| 138 | + stepModel.removePropertyChangeListener(ReportModel.EXPORT_CSV_FILE_PROPERTY_NAME, this);
|
|
| 139 | + }
|
|
| 140 | + }
|
|
| 141 | + |
|
| 142 | + @Override
|
|
| 143 | + public void propertyChange(PropertyChangeEvent evt) {
|
|
| 144 | + File exportFile = (File) evt.getNewValue();
|
|
| 145 | + applyButton.setEnabled(exportFile != null && !exportFile.exists() && ObserveUtil.withCsvExtension(exportFile.getName()));
|
|
| 146 | + }
|
|
| 147 | +} |
| ... | ... | @@ -45,7 +45,6 @@ public class ToggleConfigure extends AdminTabUIActionSupport<ReportUI> { |
| 45 | 45 | |
| 46 | 46 | public ToggleConfigure() {
|
| 47 | 47 | super("", n("observe.ui.action.configuration.tip"), "generate", ObserveKeyStrokesEditorApi.KEY_STROKE_NAVIGATION_CONFIGURE);
|
| 48 | -// setIcon(getContentScaledImage("configure"));
|
|
| 49 | 48 | }
|
| 50 | 49 | |
| 51 | 50 | @Override
|
| 1 | +package fr.ird.observe.client.datasource.actions.report.actions;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Client :: DataSource :: Actions
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import fr.ird.observe.client.datasource.actions.ObserveKeyStrokesActions;
|
|
| 26 | +import fr.ird.observe.client.datasource.actions.actions.AdminTabUIActionSupport;
|
|
| 27 | +import fr.ird.observe.client.datasource.actions.report.ReportUI;
|
|
| 28 | +import org.nuiton.jaxx.runtime.swing.action.MenuAction;
|
|
| 29 | + |
|
| 30 | +import javax.swing.JComponent;
|
|
| 31 | +import javax.swing.JPopupMenu;
|
|
| 32 | +import javax.swing.SwingUtilities;
|
|
| 33 | +import javax.swing.event.PopupMenuEvent;
|
|
| 34 | +import javax.swing.event.PopupMenuListener;
|
|
| 35 | +import java.awt.event.ActionEvent;
|
|
| 36 | + |
|
| 37 | +import static io.ultreia.java4all.i18n.I18n.n;
|
|
| 38 | + |
|
| 39 | +/**
|
|
| 40 | + * Created on 02/08/2022.
|
|
| 41 | + *
|
|
| 42 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 43 | + * @since 9.0.7
|
|
| 44 | + */
|
|
| 45 | +public class ToggleExport extends AdminTabUIActionSupport<ReportUI> {
|
|
| 46 | + |
|
| 47 | + public ToggleExport() {
|
|
| 48 | + super("", n("observe.ui.action.export.tip"), "data-export", ObserveKeyStrokesActions.KEY_STROKE_EXPORT_POPUP);
|
|
| 49 | + }
|
|
| 50 | + |
|
| 51 | + @Override
|
|
| 52 | + public void init() {
|
|
| 53 | + super.init();
|
|
| 54 | + ui.getExportPopup().addPopupMenuListener(new PopupMenuListener() {
|
|
| 55 | + @Override
|
|
| 56 | + public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
|
| 57 | + }
|
|
| 58 | + |
|
| 59 | + @Override
|
|
| 60 | + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
|
| 61 | + ui.getToggleExport().setSelected(false);
|
|
| 62 | + }
|
|
| 63 | + |
|
| 64 | + @Override
|
|
| 65 | + public void popupMenuCanceled(PopupMenuEvent e) {
|
|
| 66 | + ui.getToggleExport().setSelected(false);
|
|
| 67 | + }
|
|
| 68 | + });
|
|
| 69 | + }
|
|
| 70 | + |
|
| 71 | + @Override
|
|
| 72 | + protected void doActionPerformed(ActionEvent e, ReportUI ui) {
|
|
| 73 | + ui.getToggleExport().setSelected(true);
|
|
| 74 | + SwingUtilities.invokeLater(() -> {
|
|
| 75 | + JComponent c = ui.getToggleExport();
|
|
| 76 | + JPopupMenu p = ui.getExportPopup();
|
|
| 77 | + MenuAction.preparePopup(p, c, false);
|
|
| 78 | + });
|
|
| 79 | + }
|
|
| 80 | + |
|
| 81 | +}
|
|
| 82 | + |
| ... | ... | @@ -55,6 +55,7 @@ observe.config.defaultReportDirectory.description=Default directory where to sto |
| 55 | 55 | observe.config.defaultReportFile.description=Default report file to use
|
| 56 | 56 | observe.config.defaultResourcesDirectory.description=Default user resources directory
|
| 57 | 57 | observe.config.defaultValidationReportDirectory.description=Default validation report directory
|
| 58 | +observe.config.exportDirectory.description=Default export directory for user export.
|
|
| 58 | 59 | observe.config.feedBackDirectory.description=FeedBack directory
|
| 59 | 60 | observe.config.h2.can.editReferential.description=Local database can edit referential
|
| 60 | 61 | observe.config.h2.can.migrate.description=Flag to know if you can migrate h2 data sources
|
| ... | ... | @@ -315,6 +316,7 @@ observe.ui.action.choose.avdth.file.description=AVDTH Database (*.mdb) |
| 315 | 316 | observe.ui.action.choose.db.dump=Choose the backup
|
| 316 | 317 | observe.ui.action.choose.db.dump.description=Database backup (*.sql.gz)
|
| 317 | 318 | observe.ui.action.choose.db.dump.directory=Choose the backup directory
|
| 319 | +observe.ui.action.choose.export.csv.directory=Choose csv export directory
|
|
| 318 | 320 | observe.ui.action.choose.reportFile=Choose the reports file
|
| 319 | 321 | observe.ui.action.choose.reportFile.description=Report's file (*.properties)
|
| 320 | 322 | observe.ui.action.close=Close
|
| ... | ... | @@ -360,6 +362,7 @@ observe.ui.action.duplicate.remote.tip=Duplicate remote |
| 360 | 362 | observe.ui.action.duplicate.server.tip=Duplicate server
|
| 361 | 363 | observe.ui.action.exit=Quit
|
| 362 | 364 | observe.ui.action.exit.tip=quit Observe
|
| 365 | +observe.ui.action.export.tip=Export
|
|
| 363 | 366 | observe.ui.action.goDown.tip=Go down in navigation tree
|
| 364 | 367 | observe.ui.action.goUp.tip=Go up in navigation tree
|
| 365 | 368 | observe.ui.action.goto.next.stage=Next step
|
| ... | ... | @@ -531,6 +534,10 @@ observe.ui.datasource.editor.actions.report.copy.column.headers.tip=Add in resul |
| 531 | 534 | observe.ui.datasource.editor.actions.report.copy.row.headers=Copy row header
|
| 532 | 535 | observe.ui.datasource.editor.actions.report.copy.row.headers.tip=Add in result row headers
|
| 533 | 536 | observe.ui.datasource.editor.actions.report.description=Generate reports
|
| 537 | +observe.ui.datasource.editor.actions.report.exportToClipboard=Clipboard
|
|
| 538 | +observe.ui.datasource.editor.actions.report.exportToCsv=CSV
|
|
| 539 | +observe.ui.datasource.editor.actions.report.exportToCsv.done=Csv export done at %s
|
|
| 540 | +observe.ui.datasource.editor.actions.report.exportToCsv.tip=Export to csv
|
|
| 534 | 541 | observe.ui.datasource.editor.actions.report.no.report.found=No report found.
|
| 535 | 542 | observe.ui.datasource.editor.actions.report.report.count.found=Found %s reports.
|
| 536 | 543 | observe.ui.datasource.editor.actions.report.report.description=Description of selected report
|
| ... | ... | @@ -827,6 +834,7 @@ observe.ui.title.can.not.export.obstuna=Could not export data... |
| 827 | 834 | observe.ui.title.choose.avdth.file=Select avdth file
|
| 828 | 835 | observe.ui.title.choose.db.dump=Choose a database backup
|
| 829 | 836 | observe.ui.title.choose.db.dump.directory=Choose directory of backup
|
| 837 | +observe.ui.title.choose.export.csv.directory=Choose directory of csv export
|
|
| 830 | 838 | observe.ui.title.choose.reportFile=Choose report definition file
|
| 831 | 839 | observe.ui.title.confirmReplace=Confirm to replace
|
| 832 | 840 | observe.ui.title.connect.existingDB=Connect to existing database
|
| ... | ... | @@ -55,6 +55,7 @@ observe.config.defaultReportDirectory.description=Directorio por defecto de los |
| 55 | 55 | observe.config.defaultReportFile.description=Default report file to use
|
| 56 | 56 | observe.config.defaultResourcesDirectory.description=Directorio de almacenamiento de los recursos de usuario como las traducciones o la consultas de informes
|
| 57 | 57 | observe.config.defaultValidationReportDirectory.description=Directorio por defecto de almacenamiento de los informes de validación
|
| 58 | +observe.config.exportDirectory.description=Default export directory for user export.
|
|
| 58 | 59 | observe.config.feedBackDirectory.description=FeedBack directory \#TODO
|
| 59 | 60 | observe.config.h2.can.editReferential.description=Para poder editar el referencial de una base local
|
| 60 | 61 | observe.config.h2.can.migrate.description=Autorizar la actualización de las bases locales (h2)
|
| ... | ... | @@ -315,6 +316,7 @@ observe.ui.action.choose.avdth.file.description=AVDTH Database (*.mdb) \#TODO |
| 315 | 316 | observe.ui.action.choose.db.dump=Elegir la copia de seguridad
|
| 316 | 317 | observe.ui.action.choose.db.dump.description=Copia de seguridad de la base (*.sql.gz)
|
| 317 | 318 | observe.ui.action.choose.db.dump.directory=Elegir el directorio de la copia de seguridad
|
| 319 | +observe.ui.action.choose.export.csv.directory=Choisir le répertoire de l'export csv
|
|
| 318 | 320 | observe.ui.action.choose.reportFile=Elegir el archivo de definición de informe
|
| 319 | 321 | observe.ui.action.choose.reportFile.description=Archivo de definición (*.properties)
|
| 320 | 322 | observe.ui.action.close=Cerrar
|
| ... | ... | @@ -360,6 +362,7 @@ observe.ui.action.duplicate.remote.tip=Duplicate remote \#TODO |
| 360 | 362 | observe.ui.action.duplicate.server.tip=Duplicate server \#TODO
|
| 361 | 363 | observe.ui.action.exit=Salir
|
| 362 | 364 | observe.ui.action.exit.tip=Salir de ObServe
|
| 365 | +observe.ui.action.export.tip=Export
|
|
| 363 | 366 | observe.ui.action.goDown.tip=Descender hacia etapas porteriores
|
| 364 | 367 | observe.ui.action.goUp.tip=Ascender hacia etapas anteriores
|
| 365 | 368 | observe.ui.action.goto.next.stage=Siguiente
|
| ... | ... | @@ -531,6 +534,10 @@ observe.ui.datasource.editor.actions.report.copy.column.headers.tip=Añadir al r |
| 531 | 534 | observe.ui.datasource.editor.actions.report.copy.row.headers=Copiar las cabeceras de linea
|
| 532 | 535 | observe.ui.datasource.editor.actions.report.copy.row.headers.tip=Añadir al resultado las cabeceras de linea (ej. la primera columna)
|
| 533 | 536 | observe.ui.datasource.editor.actions.report.description=Generar los cuadros de síntesis del informe de fin del embarque
|
| 537 | +observe.ui.datasource.editor.actions.report.exportToClipboard=Clipboard
|
|
| 538 | +observe.ui.datasource.editor.actions.report.exportToCsv=CSV
|
|
| 539 | +observe.ui.datasource.editor.actions.report.exportToCsv.done=Csv export done at %s
|
|
| 540 | +observe.ui.datasource.editor.actions.report.exportToCsv.tip=Export to csv
|
|
| 534 | 541 | observe.ui.datasource.editor.actions.report.no.report.found=No report found. \#TODO
|
| 535 | 542 | observe.ui.datasource.editor.actions.report.report.count.found=Found %s reports. \#TODO
|
| 536 | 543 | observe.ui.datasource.editor.actions.report.report.description=Descripción del informe seleccionado
|
| ... | ... | @@ -827,6 +834,7 @@ observe.ui.title.can.not.export.obstuna=Impossible exportar los datos... |
| 827 | 834 | observe.ui.title.choose.avdth.file=Select avdth file \#TODO
|
| 828 | 835 | observe.ui.title.choose.db.dump=Seleccionar una copia de seguridad de base local
|
| 829 | 836 | observe.ui.title.choose.db.dump.directory=Seleccionar e directorio de destinación de la copia de seguridad
|
| 837 | +observe.ui.title.choose.export.csv.directory=Choose directory of csv export
|
|
| 830 | 838 | observe.ui.title.choose.reportFile=Seleccionar el archivo de definición de los informes
|
| 831 | 839 | observe.ui.title.confirmReplace=Confirmar para reemplazar
|
| 832 | 840 | observe.ui.title.connect.existingDB=Conexión a una fuente de datos que ya existe
|
| ... | ... | @@ -55,6 +55,7 @@ observe.config.defaultReportDirectory.description=Répertoire par défaut des ra |
| 55 | 55 | observe.config.defaultReportFile.description=Fichier par défaut des rapports de l'application
|
| 56 | 56 | observe.config.defaultResourcesDirectory.description=Répertoire où sont stockées les ressources.
|
| 57 | 57 | observe.config.defaultValidationReportDirectory.description=Répertoire où sont stockés les rapports de validation
|
| 58 | +observe.config.exportDirectory.description=Le répertoire par défaut pour les exports.
|
|
| 58 | 59 | observe.config.feedBackDirectory.description=Répertoire où sont consigner les feedback
|
| 59 | 60 | observe.config.h2.can.editReferential.description=Pour pouvoir éditer le référentiel d'une base locale
|
| 60 | 61 | observe.config.h2.can.migrate.description=Autoriser la mise à jour des bases locales (H2)
|
| ... | ... | @@ -315,6 +316,7 @@ observe.ui.action.choose.avdth.file.description=Base AVDTH (*.mdb) |
| 315 | 316 | observe.ui.action.choose.db.dump=Choisir la sauvegarde
|
| 316 | 317 | observe.ui.action.choose.db.dump.description=Sauvegarde de base (*.sql.gz)
|
| 317 | 318 | observe.ui.action.choose.db.dump.directory=Choisir le répertoire de sauvegarde
|
| 319 | +observe.ui.action.choose.export.csv.directory=Choisir le répertoire de l'export csv
|
|
| 318 | 320 | observe.ui.action.choose.reportFile=Choisir le fichier de définition de report
|
| 319 | 321 | observe.ui.action.choose.reportFile.description=Fichier de définition (*.properties)
|
| 320 | 322 | observe.ui.action.close=Fermer
|
| ... | ... | @@ -360,6 +362,7 @@ observe.ui.action.duplicate.remote.tip=Duplicate la connexion distante |
| 360 | 362 | observe.ui.action.duplicate.server.tip=Duplicate la connexion server
|
| 361 | 363 | observe.ui.action.exit=Quitter
|
| 362 | 364 | observe.ui.action.exit.tip=Quitter ObServe
|
| 365 | +observe.ui.action.export.tip=Exporter
|
|
| 363 | 366 | observe.ui.action.goDown.tip=Descendre dans la navigation
|
| 364 | 367 | observe.ui.action.goUp.tip=Remonter dans la navigation
|
| 365 | 368 | observe.ui.action.goto.next.stage=Suivant
|
| ... | ... | @@ -531,6 +534,10 @@ observe.ui.datasource.editor.actions.report.copy.column.headers.tip=Ajoute dans |
| 531 | 534 | observe.ui.datasource.editor.actions.report.copy.row.headers=Copier les entêtes de ligne
|
| 532 | 535 | observe.ui.datasource.editor.actions.report.copy.row.headers.tip=Ajoute dans le résultat les entêtes de ligne (i.e la première colonne)
|
| 533 | 536 | observe.ui.datasource.editor.actions.report.description=Générer les tableaux de synthèse du rapport de fin d'embarquement
|
| 537 | +observe.ui.datasource.editor.actions.report.exportToClipboard=Presse papier
|
|
| 538 | +observe.ui.datasource.editor.actions.report.exportToCsv=Csv
|
|
| 539 | +observe.ui.datasource.editor.actions.report.exportToCsv.done=Export csv sauvegardé dans le fichier %s
|
|
| 540 | +observe.ui.datasource.editor.actions.report.exportToCsv.tip=Exporter au format Csv
|
|
| 534 | 541 | observe.ui.datasource.editor.actions.report.no.report.found=Aucun rapport trouvé.
|
| 535 | 542 | observe.ui.datasource.editor.actions.report.report.count.found=%s rapports détectés.
|
| 536 | 543 | observe.ui.datasource.editor.actions.report.report.description=Description du rapport sélectionné
|
| ... | ... | @@ -827,6 +834,7 @@ observe.ui.title.can.not.export.obstuna=Impossible d'exporter des données... |
| 827 | 834 | observe.ui.title.choose.avdth.file=Choisir une base AVDTH
|
| 828 | 835 | observe.ui.title.choose.db.dump=Choisir une sauvegarder de base locale
|
| 829 | 836 | observe.ui.title.choose.db.dump.directory=Choisir le répertoire de destination de la sauvegarde
|
| 837 | +observe.ui.title.choose.export.csv.directory=Choisir le répertoire de destination de l'export csc
|
|
| 830 | 838 | observe.ui.title.choose.reportFile=Choisir le fichier de définition des reports
|
| 831 | 839 | observe.ui.title.confirmReplace=Confirmation de remplacement
|
| 832 | 840 | observe.ui.title.connect.existingDB=Connexion à une source de données existante
|
| ... | ... | @@ -62,7 +62,9 @@ import java.util.function.Supplier; |
| 62 | 62 | public class ObserveUtil {
|
| 63 | 63 | |
| 64 | 64 | public static final String SQL_GZ_EXTENSION_PATTERN = "^.+\\.sql\\.gz|.+\\.SQL\\.GZ$";
|
| 65 | + public static final String CSV_EXTENSION_PATTERN = "^.+\\.csv|.+\\.CSV$";
|
|
| 65 | 66 | public static final String SQL_GZ_EXTENSION = ".sql.gz";
|
| 67 | + public static final String CSV_EXTENSION = ".csv";
|
|
| 66 | 68 | public static final String PROPERTIES_EXTENSION_PATTERN = "^.+\\.properties|.+\\.PROPERTIES$";
|
| 67 | 69 | public static final String PROPERTIES_EXTENSION = ".properties";
|
| 68 | 70 | public static final String PNG_EXTENSION_PATTERN = "^.+\\.png|.+\\.PNG$";
|
| ... | ... | @@ -150,6 +152,24 @@ public class ObserveUtil { |
| 150 | 152 | return filePath.endsWith(SQL_GZ_EXTENSION);
|
| 151 | 153 | }
|
| 152 | 154 | |
| 155 | + public static String addCsvExtension(String filePath) {
|
|
| 156 | + if (!filePath.endsWith(CSV_EXTENSION)) {
|
|
| 157 | + filePath += CSV_EXTENSION;
|
|
| 158 | + }
|
|
| 159 | + return filePath;
|
|
| 160 | + }
|
|
| 161 | + |
|
| 162 | + public static String removeCsvExtension(String filePath) {
|
|
| 163 | + if (filePath.endsWith(CSV_EXTENSION)) {
|
|
| 164 | + filePath = Strings.removeEnd(filePath, CSV_EXTENSION);
|
|
| 165 | + }
|
|
| 166 | + return filePath;
|
|
| 167 | + }
|
|
| 168 | + |
|
| 169 | + public static boolean withCsvExtension(String filePath) {
|
|
| 170 | + return filePath.endsWith(CSV_EXTENSION);
|
|
| 171 | + }
|
|
| 172 | + |
|
| 153 | 173 | public static ScriptEngine getScriptEngine() {
|
| 154 | 174 | ScriptEngineManager factory = new ScriptEngineManager();
|
| 155 | 175 | return factory.getEngineByName(JS_ENGINE_NAME);
|
| ... | ... | @@ -223,44 +223,38 @@ public class DataMatrix implements JsonAware { |
| 223 | 223 | |
| 224 | 224 | public String getClipboardContent(boolean copyRowHeaders,
|
| 225 | 225 | boolean copyColumnHeaders,
|
| 226 | - boolean escapeCells, char sep) {
|
|
| 227 | - |
|
| 226 | + boolean escapeCells,
|
|
| 227 | + char sep) {
|
|
| 228 | 228 | if (getWidth() <= 0 || getHeight() <= 0) {
|
| 229 | 229 | return "";
|
| 230 | 230 | }
|
| 231 | - |
|
| 232 | 231 | StringBuilder buffer = new StringBuilder();
|
| 233 | - |
|
| 234 | 232 | char eol = '\n';
|
| 235 | - |
|
| 236 | 233 | for (int y = copyColumnHeaders ? 0 : 1, rows = getHeight(); y < rows; y++) {
|
| 237 | - |
|
| 238 | 234 | Serializable value;
|
| 239 | - |
|
| 240 | - // nouvell ligne
|
|
| 241 | - |
|
| 235 | + // new line
|
|
| 242 | 236 | int x = copyRowHeaders ? 0 : 1;
|
| 243 | - |
|
| 244 | 237 | for (int columns = getWidth() - 1; x < columns; x++) {
|
| 245 | - |
|
| 246 | - // sur chaque cellule (sauf la dernière)
|
|
| 238 | + // all cells except the last one
|
|
| 247 | 239 | value = getValue(x, y);
|
| 248 | 240 | if (escapeCells) {
|
| 249 | - value = "\"" + value + "\"";
|
|
| 241 | + value = escapeCell(value);
|
|
| 250 | 242 | }
|
| 251 | 243 | buffer.append(value).append(sep);
|
| 252 | 244 | }
|
| 253 | - |
|
| 254 | - // dernière cellule
|
|
| 245 | + // last cell
|
|
| 255 | 246 | value = getValue(x, y);
|
| 256 | 247 | if (escapeCells) {
|
| 257 | - value = "\"" + value + "\"";
|
|
| 248 | + value = escapeCell(value);
|
|
| 258 | 249 | }
|
| 259 | 250 | buffer.append(value);
|
| 260 | - |
|
| 261 | - // fin de ligne
|
|
| 251 | + // end of line
|
|
| 262 | 252 | buffer.append(eol);
|
| 263 | 253 | }
|
| 264 | 254 | return buffer.toString();
|
| 265 | 255 | }
|
| 256 | + |
|
| 257 | + private String escapeCell(Object value) {
|
|
| 258 | + return String.format("\"%s\"", value == null ? "" : value.toString().replaceAll("\"", "\"\""));
|
|
| 259 | + }
|
|
| 266 | 260 | } |