This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit bf8a93c34480c6529baf9c75591bac53274f0665 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 30 16:00:01 2015 +0200 add new export screen --- .../filtered-resources/tutti-help-fr.properties | 39 ++--- .../fr/ifremer/tutti/ui/swing/TuttiScreen.java | 6 + .../actions/OpenGenericFormatExportScreen.java | 41 +++++ .../genericformat/GenericFormatExportUI.css | 169 +++++++++++++++++++++ .../genericformat/GenericFormatExportUI.jaxx | 121 +++++++++++++++ .../GenericFormatExportUIHandler.java | 154 +++++++++++++++++++ .../genericformat/GenericFormatExportUIModel.java | 156 +++++++++++++++++++ .../genericformat/actions/FoldAllDataAction.java | 41 +++++ .../actions/GenericFormatExportAction.java | 113 ++++++++++++++ .../genericformat/actions/SelectAllDataAction.java | 35 +++++ .../genericformat/actions/UnfoldAllDataAction.java | 39 +++++ .../actions/UnselectAllDataAction.java | 35 +++++ .../genericformat/tree/CruiseSelectTreeNode.java | 121 +++++++++++++++ .../tree/DataSelectTreeCellEditor.java | 65 ++++++++ .../tree/DataSelectTreeCellRenderer.java | 112 ++++++++++++++ .../tree/DataSelectTreeNodeSupport.java | 49 ++++++ .../tree/OperationSelectTreeNode.java | 51 +++++++ .../genericformat/tree/ProgramSelectTreeNode.java | 64 ++++++++ .../src/main/resources/icons/action-collapse.png | Bin 0 -> 372 bytes .../src/main/resources/icons/action-expand.png | Bin 0 -> 371 bytes .../src/main/resources/icons/action-select.png | Bin 0 -> 392 bytes .../src/main/resources/icons/action-unselect.png | Bin 0 -> 311 bytes 22 files changed, 1387 insertions(+), 24 deletions(-) diff --git a/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties b/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties index 3e7f55a..0a7e502 100644 --- a/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties +++ b/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties @@ -1,28 +1,5 @@ -### -# #%L -# Tutti :: UI -# $Id:$ -# $HeadURL:$ -# %% -# Copyright (C) 2012 - 2015 Ifremer -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program. If not, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Sat Mar 07 10:47:12 CET 2015 +#Sun Mar 29 16:12:43 CEST 2015 tutti.config.help=config.html tutti.createAccidentalBatch.action.cancel.help=editFishingOperation.html\#captureCapturesAccidentellesActions tutti.createAccidentalBatch.action.saveAndClose.help=editFishingOperation.html\#captureCapturesAccidentellesActions @@ -334,6 +311,19 @@ tutti.fishingOperations.action.deleteFishingOperation.help=editFishingOperation. tutti.fishingOperations.action.newFishingOperation.help=editFishingOperation.html\#traitActions tutti.fishingOperations.field.fishingOperation.help=editFishingOperation.html\#fields tutti.fishingOperations.help=editFishingOperation.html +tutti.genericFormatExport.action.closeGenericFormatExport.help= +tutti.genericFormatExport.action.export.help= +tutti.genericFormatExport.action.foldAll.help= +tutti.genericFormatExport.action.selectAll.help= +tutti.genericFormatExport.action.unfoldAll.help= +tutti.genericFormatExport.action.unselectAll.help= +tutti.genericFormatExport.field.exportAccidentalCatch.help= +tutti.genericFormatExport.field.exportAttachments.help= +tutti.genericFormatExport.field.exportBenthos.help= +tutti.genericFormatExport.field.exportIndividualObservation.help= +tutti.genericFormatExport.field.exportMarineLitter.help= +tutti.genericFormatExport.field.exportSpecies.help= +tutti.genericFormatExport.field.program.help= tutti.genericFormatImport.action.closeGenericFormatImport.help=genericFormat.html\#generic_format_import_actions tutti.genericFormatImport.action.generateReport.help=genericFormat.html\#generic_format_import_actions tutti.genericFormatImport.action.import.help=genericFormat.html\#generic_format_import_actions @@ -373,6 +363,7 @@ tutti.main.menu.action.editSampleCategoryModel.help=menu.html\#menu_administrati tutti.main.menu.action.exit.help=menu.html\#menu_fichier tutti.main.menu.action.generateCruiseReport.help=menu.html\#menu_action tutti.main.menu.action.generateSelectedCruiseReport.help=menu.html\#menu_action +tutti.main.menu.action.genericFormatExport.help= tutti.main.menu.action.genericFormatImport.help=menu.html\#menu_action tutti.main.menu.action.importTemporaryReferential.help=menu.html\#menu_administration tutti.main.menu.action.manageDb.help=menu.html\#menu_fichier diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiScreen.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiScreen.java index 76801dc..e1f370a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiScreen.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiScreen.java @@ -110,4 +110,10 @@ public enum TuttiScreen { * @since 3.14 */ GENERIC_FORMAT_IMPORT, + /** + * To perform a generic format export. + * + * @since 3.14.3 + */ + GENERIC_FORMAT_EXPORT, } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/OpenGenericFormatExportScreen.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/OpenGenericFormatExportScreen.java new file mode 100644 index 0000000..2825e49 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/OpenGenericFormatExportScreen.java @@ -0,0 +1,41 @@ +package fr.ifremer.tutti.ui.swing.content.actions; + +import fr.ifremer.tutti.ui.swing.TuttiScreen; +import fr.ifremer.tutti.ui.swing.content.MainUIHandler; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class OpenGenericFormatExportScreen extends AbstractChangeScreenAction { + + public OpenGenericFormatExportScreen(MainUIHandler handler) { + super(handler, true, TuttiScreen.GENERIC_FORMAT_EXPORT); + } + + @Override + public void doAction() throws Exception { + + createProgressionModelIfRequired(5); + + getProgressionModel().increments(t("tutti.openGenericFormatExportScreen.step.loading.allGear")); + getContext().getPersistenceService().getAllGear(); + + getProgressionModel().increments(t("tutti.openGenericFormatExportScreen.step.loading.allPerson")); + getContext().getPersistenceService().getAllPerson(); + + getProgressionModel().increments(t("tutti.openGenericFormatExportScreen.step.loading.allSpecies")); + getContext().getPersistenceService().getAllSpecies(); + + getProgressionModel().increments(t("tutti.openGenericFormatExportScreen.step.loading.allVessel")); + getContext().getPersistenceService().getAllVessel(); + + getProgressionModel().increments(t("tutti.openGenericFormatExportScreen.step.loading.ui")); + + super.doAction(); + } +} \ No newline at end of file diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUI.css b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUI.css new file mode 100644 index 0000000..ea92a8e --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUI.css @@ -0,0 +1,169 @@ +/* + * #%L + * Tutti :: UI + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 - 2015 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +BeanFilterableComboBox { + showReset: true; + bean: {model}; +} + +JToolBar { + borderPainted: false; + floatable: false; + opaque: true; +} + +#genericFormatExportTopPanel { + _help: {"tutti.genericFormatExport.help"}; +} + +#exportOptions { + border: {BorderFactory.createTitledBorder(t("tutti.genericFormatExport.exportOptions.legend"))}; +} + +#dataSelectionPane { + border: {BorderFactory.createTitledBorder(t("tutti.genericFormatExport.selectData.legend"))}; + columnHeaderView: {dataSelectionTreeHeader}; +} + +#dataSelectionTree { + model: {new DefaultTreeModel(null)}; + rootVisible: false; + scrollsOnExpand: true; + editable: true; + toggleClickCount: 1; + cellEditor: {new DataSelectTreeCellEditor(dataSelectionTree)}; + cellRenderer: {new DataSelectTreeCellRenderer()}; +} + +#programLabel { + text: "tutti.genericFormatExport.field.program"; + labelFor: {programComboBox}; + toolTipText: "tutti.genericFormatExport.field.program.tip"; + _help: {"tutti.genericFormatExport.field.program.help"}; +} + +#programComboBox { + property: program; + selectedItem: {model.getProgram()}; + _validatorLabel: {t("tutti.genericFormatExport.field.program")}; + _help: {"tutti.genericFormatExport.field.program.help"}; +} + +#exportAttachmentsCheckBox { + text: "tutti.genericFormatExport.field.exportAttachments"; + selected: {model.isExportAttachments()}; + toolTipText: "tutti.genericFormatExport.field.exportAttachments.tip"; + _help: {"tutti.genericFormatExport.field.exportAttachments.help"}; +} + +#exportSpeciesCheckBox { + text: "tutti.genericFormatExport.field.exportSpecies"; + selected: {model.isExportSpecies()}; + toolTipText: "tutti.genericFormatExport.field.exportSpecies.tip"; + _help: {"tutti.genericFormatExport.field.exportSpecies.help"}; +} + +#exportBenthosCheckBox { + text: "tutti.genericFormatExport.field.exportBenthos"; + selected: {model.isExportBenthos()}; + toolTipText: "tutti.genericFormatExport.field.exportBenthos.tip"; + _help: {"tutti.genericFormatExport.field.exportBenthos.help"}; +} + +#exportMarineLitterCheckBox { + text: "tutti.genericFormatExport.field.exportMarineLitter"; + selected: {model.isExportMarineLitter()}; + toolTipText: "tutti.genericFormatExport.field.exportMarineLitter.tip"; + _help: {"tutti.genericFormatExport.field.exportMarineLitter.help"}; +} + +#exportAccidentalCatchCheckBox { + text: "tutti.genericFormatExport.field.exportAccidentalCatch"; + selected: {model.isExportAccidentalCatch()}; + toolTipText: "tutti.genericFormatExport.field.exportAccidentalCatch.tip"; + _help: {"tutti.genericFormatExport.field.exportAccidentalCatch.help"}; +} + +#exportIndividualObservationCheckBox { + text: "tutti.genericFormatExport.field.exportIndividualObservation"; + selected: {model.isExportIndividualObservation()}; + toolTipText: "tutti.genericFormatExport.field.exportIndividualObservation.tip"; + _help: {"tutti.genericFormatExport.field.exportIndividualObservation.help"}; +} + +#exportButton { + actionIcon: export; + text: "tutti.genericFormatExport.action.export"; + toolTipText: "tutti.genericFormatExport.action.export.tip"; + i18nMnemonic: "tutti.genericFormatExport.action.export.mnemonic"; + _applicationAction: {fr.ifremer.tutti.ui.swing.content.genericformat.actions.GenericFormatExportAction.class}; + enabled: {model.isCanExport()}; + _help: {"tutti.genericFormatExport.action.export.help"}; +} + +#closeButton { + actionIcon: cancel; + text: "tutti.genericFormatExport.action.closeGenericFormatExport"; + toolTipText: "tutti.genericFormatExport.action.closeGenericFormatExport.tip"; + i18nMnemonic: "tutti.genericFormatExport.action.closeGenericFormatExport.mnemonic"; + _applicationAction: {fr.ifremer.tutti.ui.swing.content.actions.OpenHomeScreenAction.class}; + _help: {"tutti.genericFormatExport.action.closeGenericFormatExport.help"}; +} + +#selectAllButton { + actionIcon: select; + /*text: "tutti.genericFormatExport.action.selectAll";*/ + toolTipText: "tutti.genericFormatExport.action.selectAll.tip"; + enabled: {model.getProgram() != null}; + _simpleAction: {fr.ifremer.tutti.ui.swing.content.genericformat.actions.SelectAllDataAction.class}; + _help: {"tutti.genericFormatExport.action.selectAll.help"}; +} + +#unselectAllButton { + actionIcon: unselect; + /*text: "tutti.genericFormatExport.action.unselectAll";*/ + toolTipText: "tutti.genericFormatExport.action.unselectAll.tip"; + enabled: {model.getProgram() != null}; + _simpleAction: {fr.ifremer.tutti.ui.swing.content.genericformat.actions.UnselectAllDataAction.class}; + _help: {"tutti.genericFormatExport.action.unselectAll.help"}; +} + +#foldAllButton { + actionIcon: collapse; + /*text: "tutti.genericFormatExport.action.foldAll";*/ + toolTipText: "tutti.genericFormatExport.action.foldAll.tip"; + enabled: {model.getProgram() != null}; + _simpleAction: {fr.ifremer.tutti.ui.swing.content.genericformat.actions.FoldAllDataAction.class}; + _help: {"tutti.genericFormatExport.action.foldAll.help"}; +} + +#unfoldAllButton { + actionIcon: expand; + /*text: "tutti.genericFormatExport.action.unfoldAll";*/ + toolTipText: "tutti.genericFormatExport.action.unfoldAll.tip"; + enabled: {model.getProgram() != null}; + _simpleAction: {fr.ifremer.tutti.ui.swing.content.genericformat.actions.UnfoldAllDataAction.class}; + _help: {"tutti.genericFormatExport.action.unfoldAll.help"}; +} + diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUI.jaxx new file mode 100644 index 0000000..ab64dbe --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUI.jaxx @@ -0,0 +1,121 @@ +<!-- + #%L + Tutti :: UI + %% + Copyright (C) 2012 - 2014 Ifremer + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JPanel id='genericFormatImportTopPanel' layout='{new BorderLayout()}' decorator='help' + implements='fr.ifremer.tutti.ui.swing.util.TuttiUI<GenericFormatExportUIModel, GenericFormatExportUIHandler>'> + + <import> + fr.ifremer.tutti.persistence.entities.data.Program + + fr.ifremer.tutti.ui.swing.TuttiHelpBroker + + fr.ifremer.tutti.ui.swing.util.TuttiUI + fr.ifremer.tutti.ui.swing.util.TuttiUIUtil + fr.ifremer.tutti.ui.swing.content.genericformat.tree.DataSelectTreeCellEditor + fr.ifremer.tutti.ui.swing.content.genericformat.tree.DataSelectTreeCellRenderer + + jaxx.runtime.swing.editor.bean.BeanFilterableComboBox + + javax.swing.tree.DefaultTreeModel + + static org.nuiton.i18n.I18n.t + static jaxx.runtime.SwingUtil.getStringValue + </import> + + <script><![CDATA[ + + public GenericFormatExportUI(TuttiUI parentUI) { + TuttiUIUtil.setParentUI(this, parentUI); + } + ]]></script> + + <GenericFormatExportUIModel id='model' initializer='getContextValue(GenericFormatExportUIModel.class)'/> + + <TuttiHelpBroker id='broker' constructorParams='"tutti.genericFormatimport.help"'/> + + <BeanValidator id='validator' bean='model' context='edit' uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='program' component='programComboBox'/> + </BeanValidator> + + <Table fill='both' constraints='BorderLayout.NORTH'> + + <!-- select program --> + <row> + <cell> + <JLabel id='programLabel'/> + </cell> + <cell> + <BeanFilterableComboBox id='programComboBox' constructorParams='this' genericType='Program'/> + </cell> + </row> + + <!-- select data --> + <row> + <cell weightx='1' weighty='1' columns='2'> + <JPanel layout='{new BorderLayout()}'> + <JScrollPane id='dataSelectionPane' constraints='BorderLayout.CENTER'> + <JTree id='dataSelectionTree'/> + </JScrollPane> + <JPanel id='exportOptions' layout='{new BorderLayout()}' constraints='BorderLayout.EAST'> + <JPanel layout='{new GridLayout(0, 1)}' constraints='BorderLayout.NORTH'> + <JCheckBox id='exportAttachmentsCheckBox' onItemStateChanged='handler.setBoolean(event, "exportAttachments")'/> + <JCheckBox id='exportSpeciesCheckBox' onItemStateChanged='handler.setBoolean(event, "exportSpecies")'/> + <JCheckBox id='exportBenthosCheckBox' onItemStateChanged='handler.setBoolean(event, "exportBenthos")'/> + <JCheckBox id='exportMarineLitterCheckBox' onItemStateChanged='handler.setBoolean(event, "exportMarineLitter")'/> + <JCheckBox id='exportAccidentalCatchCheckBox' onItemStateChanged='handler.setBoolean(event, "exportAccidentalCatch")'/> + <JCheckBox id='exportIndividualObservationCheckBox' onItemStateChanged='handler.setBoolean(event, "exportIndividualObservation")'/> + </JPanel> + </JPanel> + </JPanel> + </cell> + </row> + + <row> + <cell fill='both' columns='2'> + <JPanel layout='{new GridLayout(1, 0)}'> + <JButton id='closeButton'/> + <JButton id='exportButton'/> + </JPanel> + </cell> + </row> + + </Table> + + <JToolBar id='dataSelectionTreeHeader'> + <JButton id='unfoldAllButton'/> + <JButton id='foldAllButton'/> + <JButton id='selectAllButton'/> + <JButton id='unselectAllButton'/> + </JToolBar> + + <!--Table fill='both' constraints='BorderLayout.SOUTH'> + + <row> + <cell fill='both' weightx="1"> + <JPanel layout='{new GridLayout(1, 0)}'> + <JButton id='closeButton'/> + <JButton id='exportButton'/> + </JPanel> + </cell> + </row> + </Table--> + +</JPanel> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUIHandler.java new file mode 100644 index 0000000..fd14a96 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUIHandler.java @@ -0,0 +1,154 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode; +import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; +import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.application.swing.util.CloseableUI; + +import javax.swing.JComponent; +import javax.swing.JTree; +import javax.swing.ToolTipManager; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Set; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class GenericFormatExportUIHandler extends AbstractTuttiUIHandler<GenericFormatExportUIModel, GenericFormatExportUI> implements CloseableUI { + + /** Logger. */ + private static final Log log = LogFactory.getLog(GenericFormatExportUIHandler.class); + + @Override + public void beforeInit(GenericFormatExportUI ui) { + + super.beforeInit(ui); + + getDataContext().resetValidationDataContext(); + + GenericFormatExportUIModel model = new GenericFormatExportUIModel(); + + ui.setContextValue(model); + + model.addPropertyChangeListener(new PropertyChangeListener() { + + final Set<String> propertyNamesToCanExport = Sets.newHashSet(GenericFormatExportUIModel.PROPERTY_PROGRAM); + + @Override + public void propertyChange(PropertyChangeEvent evt) { + GenericFormatExportUIModel source = (GenericFormatExportUIModel) evt.getSource(); + String propertyName = evt.getPropertyName(); + + if (propertyNamesToCanExport.contains(propertyName)) { + + boolean canExport = source.computeIsCanExport(); + source.setCanExport(canExport); + + } + + if (GenericFormatExportUIModel.PROPERTY_PROGRAM.equals(propertyName)) { + + // Reload data + remove selection + Program program = (Program) evt.getNewValue(); + onProgramChanged(program); + + } + + } + }); + + } + + @Override + public void afterInit(GenericFormatExportUI ui) { + + initUI(ui); + + GenericFormatExportUIModel model = getModel(); + initBeanFilterableComboBox(ui.getProgramComboBox(), + Lists.newArrayList(getPersistenceService().getAllProgram()), + model.getProgram()); + + SwingValidator validator = ui.getValidator(); + + registerValidators(validator); + + JTree tree = ui.getDataSelectionTree(); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + + ToolTipManager.sharedInstance().registerComponent(tree); + + if (getDataContext().isProgramFilled()) { + + Program program = getDataContext().getProgram(); + + if (log.isInfoEnabled()) { + log.info("Using selected program " + program); + } + + model.setProgram(program); + + } + + } + + @Override + protected JComponent getComponentToFocus() { + return getUI().getProgramComboBox(); + } + + @Override + public void onCloseUI() { + if (log.isDebugEnabled()) { + log.debug("closing: " + ui); + } + clearValidators(); + } + + @Override + public boolean quitUI() { + return true; + } + + @Override + public SwingValidator<GenericFormatExportUIModel> getValidator() { + return ui.getValidator(); + } + + protected void onProgramChanged(Program program) { + + if (log.isInfoEnabled()) { + log.info("Program changed: " + program); + } + + ProgramSelectTreeNode root; + if (program == null) { + + root = null; + + } else { + + ProgramDataModel dataModel = getPersistenceService().loadProgram(program.getId(), true); + root = new ProgramSelectTreeNode(dataModel); + + } + + DefaultTreeModel treeModel = (DefaultTreeModel) ui.getDataSelectionTree().getModel(); + treeModel.setRoot(root); + getModel().setRootNode(root); + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUIModel.java new file mode 100644 index 0000000..69ddefc --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/GenericFormatExportUIModel.java @@ -0,0 +1,156 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat; + +import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; +import fr.ifremer.tutti.service.genericformat.GenericFormatExportConfiguration; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode; +import org.jdesktop.beans.AbstractSerializableBean; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class GenericFormatExportUIModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_PROGRAM = "program"; + + public static final String PROPERTY_EXPORT_ATTACHMENTS = "exportAttachments"; + + public static final String PROPERTY_EXPORT_SPECIES = "exportSpecies"; + + public static final String PROPERTY_EXPORT_BENTHOS = "exportBenthos"; + + public static final String PROPERTY_EXPORT_MARINE_LITTER = "exportMarineLitter"; + + public static final String PROPERTY_EXPORT_ACCIDENTAL_CATCH = "exportAccidentalCatch"; + + public static final String PROPERTY_EXPORT_INDIVIDUAL_OBSERVATION = "exportIndividualObservation"; + + public static final String PROPERTY_CAN_EXPORT = "canExport"; + + private Program program; + + private boolean exportSpecies = true; + + private boolean exportBenthos = true; + + private boolean exportMarineLitter = true; + + private boolean exportAccidentalCatch = true; + + private boolean exportIndividualObservation = true; + + private boolean exportAttachments = true; + + private boolean canExport; + + private ProgramSelectTreeNode rootNode; + + public GenericFormatExportConfiguration toExportConfiguration() { + + GenericFormatExportConfiguration configuration = new GenericFormatExportConfiguration(); + + configuration.setExportSpecies(exportSpecies); + configuration.setExportBenthos(exportBenthos); + configuration.setExportMarineLitter(exportMarineLitter); + configuration.setExportAccidentalCatch(exportAccidentalCatch); + configuration.setExportIndividualObservation(exportIndividualObservation); + configuration.setExportAttachments(exportAttachments); + + ProgramDataModel selectedDataModel = rootNode.getSelectedDataModel(); + configuration.setDataToExport(selectedDataModel); + + return configuration; + + } + + public Program getProgram() { + return program; + } + + public void setProgram(Program program) { + Object oldValue = getProgram(); + this.program = program; + firePropertyChange(PROPERTY_PROGRAM, oldValue, program); + } + + public boolean isExportSpecies() { + return exportSpecies; + } + + public void setExportSpecies(boolean exportSpecies) { + this.exportSpecies = exportSpecies; + firePropertyChange(PROPERTY_EXPORT_SPECIES, null, exportSpecies); + } + + public boolean isExportBenthos() { + return exportBenthos; + } + + public void setExportBenthos(boolean exportBenthos) { + this.exportBenthos = exportBenthos; + firePropertyChange(PROPERTY_EXPORT_BENTHOS, null, exportBenthos); + } + + public boolean isExportMarineLitter() { + return exportMarineLitter; + } + + public void setExportMarineLitter(boolean exportMarineLitter) { + this.exportMarineLitter = exportMarineLitter; + firePropertyChange(PROPERTY_EXPORT_MARINE_LITTER, null, exportMarineLitter); + } + + public boolean isExportAccidentalCatch() { + return exportAccidentalCatch; + } + + public void setExportAccidentalCatch(boolean exportAccidentalCatch) { + this.exportAccidentalCatch = exportAccidentalCatch; + firePropertyChange(PROPERTY_EXPORT_ACCIDENTAL_CATCH, null, exportAccidentalCatch); + } + + public boolean isExportIndividualObservation() { + return exportIndividualObservation; + } + + public void setExportIndividualObservation(boolean exportIndividualObservation) { + this.exportIndividualObservation = exportIndividualObservation; + firePropertyChange(PROPERTY_EXPORT_INDIVIDUAL_OBSERVATION, null, exportIndividualObservation); + } + + public boolean isExportAttachments() { + return exportAttachments; + } + + public void setExportAttachments(boolean exportAttachments) { + this.exportAttachments = exportAttachments; + firePropertyChange(PROPERTY_EXPORT_ATTACHMENTS, null, exportAttachments); + } + + public boolean isCanExport() { + return canExport; + } + + public void setCanExport(boolean canExport) { + this.canExport = canExport; + firePropertyChange(PROPERTY_CAN_EXPORT, null, canExport); + } + + public boolean computeIsCanExport() { + //TODO select data + return getProgram() != null; + } + + public void setRootNode(ProgramSelectTreeNode rootNode) { + this.rootNode = rootNode; + } + + public ProgramSelectTreeNode getRootNode() { + return rootNode; + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/FoldAllDataAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/FoldAllDataAction.java new file mode 100644 index 0000000..cdca10c --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/FoldAllDataAction.java @@ -0,0 +1,41 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.actions; + +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUI; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.CruiseSelectTreeNode; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode; +import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; + +import javax.swing.JTree; +import javax.swing.tree.TreePath; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class FoldAllDataAction extends SimpleActionSupport<GenericFormatExportUI> { + + private static final long serialVersionUID = 1L; + + public FoldAllDataAction(GenericFormatExportUI ui) { + super(ui); + } + + @Override + protected void onActionPerformed(GenericFormatExportUI ui) { + + JTree tree = ui.getDataSelectionTree(); + + tree.getSelectionModel().clearSelection(); + + ProgramSelectTreeNode root = ui.getModel().getRootNode(); + TreePath rootPath = new TreePath(root); + + for (CruiseSelectTreeNode node : root) { + tree.collapsePath(rootPath.pathByAddingChild(node)); + } + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/GenericFormatExportAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/GenericFormatExportAction.java new file mode 100644 index 0000000..44e39dd --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/GenericFormatExportAction.java @@ -0,0 +1,113 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.actions; + +import com.google.common.base.Joiner; +import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.service.genericformat.GenericFormatExportConfiguration; +import fr.ifremer.tutti.service.genericformat.GenericFormatExportResult; +import fr.ifremer.tutti.service.genericformat.GenericFormatExportService; +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUI; +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUIHandler; +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUIModel; +import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.application.ApplicationBusinessException; + +import java.io.File; +import java.util.List; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class GenericFormatExportAction extends LongActionSupport<GenericFormatExportUIModel, GenericFormatExportUI, GenericFormatExportUIHandler> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(GenericFormatImportAction.class); + + private GenericFormatExportResult exportResult; + + private File exportFile; + + public GenericFormatExportAction(GenericFormatExportUIHandler handler) { + super(handler, false); + } + + @Override + public boolean prepareAction() throws Exception { + + boolean doAction = super.prepareAction(); + + if (doAction) { + + doAction = getModel().isCanExport(); + + } + + if (doAction) { + + Program program = getModel().getProgram(); + + // choose file to export + exportFile = saveFileWithStartDirectory( + getConfig().getExportBackupDirectory(), + false, + "exportProgram-" + program.getName(), + "zip", + t("tutti.genericFormat.title.choose.exportFile"), + t("tutti.genericFormat.action.chooseExportFile"), + "^.+\\.zip$", t("tutti.common.file.genericFormat") + ); + doAction = exportFile != null; + } + + return doAction; + + } + + @Override + public void doAction() throws Exception { + + GenericFormatExportConfiguration configuration = getModel().toExportConfiguration(); + configuration.setExportFile(exportFile); + + GenericFormatExportService service = getContext().getGenericFormatExportService(); + + int nbSteps = service.getExportNbSteps(configuration); + + if (log.isInfoEnabled()) { + log.info("Export nb steps: " + nbSteps); + } + createProgressionModelIfRequired(nbSteps); + + Program program = getModel().getProgram(); + + if (log.isInfoEnabled()) { + log.info("Do generic format export for program: " + program.getName() + " to file: " + exportFile); + } + + exportResult = service.export(configuration, getProgressionModel()); + + sendMessage(t("tutti.genericFormat.export.action.success", exportFile)); + + if (!exportResult.isSuccess()) { + + List<String> errorsByCruise = exportResult.getErrorsByCruise(); + String errorMessage = t("tutti.exportCruise.action.exportErrors", program.getName(), Joiner.on('\n').join(errorsByCruise)); + throw new ApplicationBusinessException(errorMessage); + } + + } + + @Override + public void releaseAction() { + exportFile = null; + exportResult = null; + super.releaseAction(); + } + +} \ No newline at end of file diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/SelectAllDataAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/SelectAllDataAction.java new file mode 100644 index 0000000..9e1d393 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/SelectAllDataAction.java @@ -0,0 +1,35 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.actions; + +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUI; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.CruiseSelectTreeNode; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode; +import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class SelectAllDataAction extends SimpleActionSupport<GenericFormatExportUI> { + + private static final long serialVersionUID = 1L; + + public SelectAllDataAction(GenericFormatExportUI ui) { + super(ui); + } + + @Override + protected void onActionPerformed(GenericFormatExportUI ui) { + + ProgramSelectTreeNode root = ui.getModel().getRootNode(); + + for (CruiseSelectTreeNode node : root) { + node.setSelected(true); + } + + ui.getDataSelectionTree().repaint(); + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/UnfoldAllDataAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/UnfoldAllDataAction.java new file mode 100644 index 0000000..b837dc4 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/UnfoldAllDataAction.java @@ -0,0 +1,39 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.actions; + +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUI; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.CruiseSelectTreeNode; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode; +import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; + +import javax.swing.JTree; +import javax.swing.tree.TreePath; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class UnfoldAllDataAction extends SimpleActionSupport<GenericFormatExportUI> { + + private static final long serialVersionUID = 1L; + + public UnfoldAllDataAction(GenericFormatExportUI ui) { + super(ui); + } + + @Override + protected void onActionPerformed(GenericFormatExportUI ui) { + + JTree tree = ui.getDataSelectionTree(); + + ProgramSelectTreeNode root = ui.getModel().getRootNode(); + TreePath rootPath = new TreePath(root); + + for (CruiseSelectTreeNode node : root) { + tree.expandPath(rootPath.pathByAddingChild(node)); + } + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/UnselectAllDataAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/UnselectAllDataAction.java new file mode 100644 index 0000000..e2589e0 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/actions/UnselectAllDataAction.java @@ -0,0 +1,35 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.actions; + +import fr.ifremer.tutti.ui.swing.content.genericformat.GenericFormatExportUI; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.CruiseSelectTreeNode; +import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode; +import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class UnselectAllDataAction extends SimpleActionSupport<GenericFormatExportUI> { + + private static final long serialVersionUID = 1L; + + public UnselectAllDataAction(GenericFormatExportUI ui) { + super(ui); + } + + @Override + protected void onActionPerformed(GenericFormatExportUI ui) { + + ProgramSelectTreeNode root = ui.getModel().getRootNode(); + + for (CruiseSelectTreeNode node : root) { + node.setSelected(false); + } + + ui.getDataSelectionTree().repaint(); + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/CruiseSelectTreeNode.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/CruiseSelectTreeNode.java new file mode 100644 index 0000000..23e6d85 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/CruiseSelectTreeNode.java @@ -0,0 +1,121 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.tree; + +import com.google.common.collect.Iterators; +import fr.ifremer.tutti.persistence.model.CruiseDataModel; +import fr.ifremer.tutti.persistence.model.OperationDataModel; + +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class CruiseSelectTreeNode extends DataSelectTreeNodeSupport<CruiseDataModel> implements Iterable<OperationSelectTreeNode> { + + private static final long serialVersionUID = 1L; + + private final int nbChilds; + + private int nbChildSelected; + + private boolean objectValueIsAdjusting; + + public CruiseSelectTreeNode(CruiseDataModel userObject) { + super(userObject); + + for (OperationDataModel operation : userObject) { + + OperationSelectTreeNode operationNode = new OperationSelectTreeNode(operation); + add(operationNode); + + } + + nbChilds = userObject.size(); + + } + + public boolean isPartialSelected() { + return nbChildSelected > 0 && nbChildSelected < nbChilds; + } + + public int getNbChilds() { + return nbChilds; + } + + public int getNbChildSelected() { + return nbChildSelected; + } + + @Override + public boolean isSelected() { + return nbChilds > 0 && nbChilds == nbChildSelected; + } + + @Override + public void setSelected(boolean selected) { + + objectValueIsAdjusting = true; + try { + + for (OperationSelectTreeNode o : this) { + o.setSelected(selected); + } + + } finally { + + objectValueIsAdjusting = false; + + } + + updateSelectedSate(); + + } + + @Override + public CruiseDataModel getSelectedDataModel() { + + Set<OperationDataModel> operations = new LinkedHashSet<>(); + + for (OperationSelectTreeNode o : this) { + OperationDataModel operation = o.getSelectedDataModel(); + if (operation != null) { + operations.add(operation); + } + } + + CruiseDataModel result; + if (operations.isEmpty()) { + result = null; + } else { + result = new CruiseDataModel(getId(), getLabel(), operations); + } + + return result; + + } + + @Override + public Iterator<OperationSelectTreeNode> iterator() { + return Iterators.forEnumeration(children()); + } + + public void updateSelectedSate() { + + if (!objectValueIsAdjusting) { + + nbChildSelected = 0; + for (OperationSelectTreeNode o : this) { + if (o.isSelected()) { + nbChildSelected++; + } + } + + } + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeCellEditor.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeCellEditor.java new file mode 100644 index 0000000..8662ac6 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeCellEditor.java @@ -0,0 +1,65 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.tree; + +import javax.swing.DefaultCellEditor; +import javax.swing.JCheckBox; +import javax.swing.JTree; +import javax.swing.SwingUtilities; +import javax.swing.tree.DefaultTreeCellEditor; +import java.awt.Component; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.util.EventObject; + +/** + * Created on 3/30/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class DataSelectTreeCellEditor extends DefaultTreeCellEditor { + + private final JCheckBox editor; + + public DataSelectTreeCellEditor(JTree tree) { + super(tree, null); + this.editor = new JCheckBox(); + this.realEditor = new DefaultCellEditor(editor); + } + + @Override + public Component getTreeCellEditorComponent(JTree tree, Object value, + boolean isSelected, boolean expanded, boolean leaf, int row) { + String text = null; + if (value instanceof DataSelectTreeNodeSupport) { + text = ((DataSelectTreeNodeSupport) value).getLabel(); + value = ((DataSelectTreeNodeSupport) value).isSelected(); + } + editor.setText(text); + + Component treeCellEditorComponent = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row); + return treeCellEditorComponent; + } + + @Override + protected boolean canEditImmediately(EventObject event) { + if ((event instanceof MouseEvent) && + SwingUtilities.isLeftMouseButton((MouseEvent) event)) { + MouseEvent me = (MouseEvent) event; + return inHitRegion(me.getX(), me.getY()); + } + return (event == null); + } + + @Override + protected boolean inHitRegion(int x, int y) { + if (lastRow != -1 && tree != null) { + Rectangle bounds = tree.getRowBounds(lastRow); + + if (bounds != null && x >= (bounds.x + offset) && (x - 12) <= (bounds.x + offset)) { + return true; + } + + } + return false; + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeCellRenderer.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeCellRenderer.java new file mode 100644 index 0000000..ae08858 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeCellRenderer.java @@ -0,0 +1,112 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.tree; + +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JTree; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.tree.DefaultTreeCellRenderer; +import java.awt.Component; +import java.awt.Font; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class DataSelectTreeCellRenderer extends DefaultTreeCellRenderer { + + private static final long serialVersionUID = 1L; + + private final JCheckBox normalCheckBox; + + private final JCheckBox partialCheckBox; + + private Font normalFont; + + private Font boldFont; + + public DataSelectTreeCellRenderer() { + + normalCheckBox = new JCheckBox(); + partialCheckBox = new JCheckBox(); + + Object iconPainter = UIManager.getDefaults().get("CheckBox[Disabled+Selected].iconPainter"); + UIDefaults defaults = new UIDefaults(); + defaults.put("CheckBox[Disabled].iconPainter", iconPainter); + partialCheckBox.putClientProperty("Nimbus.Overrides", defaults); + partialCheckBox.putClientProperty("Nimbus.Overrides.InheritDefaults", false); + partialCheckBox.setEnabled(false); + + normalFont = UIManager.getFont("CheckBox.font"); + boldFont = normalFont.deriveFont(Font.BOLD); + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { + + JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); + + String text = null; + String tip = null; + boolean filled = false; + + JCheckBox checkBox = normalCheckBox; + + if (value != null && value instanceof DataSelectTreeNodeSupport) { + + DataSelectTreeNodeSupport node = (DataSelectTreeNodeSupport) value; + + text = node.getLabel(); + filled = node.isSelected(); + + if (node instanceof CruiseSelectTreeNode) { + + CruiseSelectTreeNode cruiseSelectTreeNode = (CruiseSelectTreeNode) node; + + if (filled) { + + tip = t("tutti.selectNode.cruiseSelected", cruiseSelectTreeNode.getNbChildSelected()); + + } else if (cruiseSelectTreeNode.isPartialSelected()) { + + checkBox = partialCheckBox; + + text += String.format(" ( %d / %d )", cruiseSelectTreeNode.getNbChildSelected(), cruiseSelectTreeNode.getNbChilds()); + + tip = t("tutti.selectNode.cruisePartialSelected", cruiseSelectTreeNode.getNbChildSelected(), cruiseSelectTreeNode.getNbChilds()); + } + + } else if (node instanceof OperationSelectTreeNode) { + + text = t("tutti.selectNode.operation", text); + + if (filled) { + + tip = t("tutti.selectNode.operationSelected", text); + } + } + } + + Font font; + if (filled) { + font = this.boldFont; + } else { + font = normalFont; + } + + checkBox.setFont(font); + checkBox.setSelected(filled); + checkBox.setBackground(label.getBackground()); + checkBox.setForeground(label.getForeground()); + checkBox.setText(text); + checkBox.setToolTipText(tip); + + return checkBox; + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeNodeSupport.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeNodeSupport.java new file mode 100644 index 0000000..4b905d7 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/DataSelectTreeNodeSupport.java @@ -0,0 +1,49 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.tree; + +import fr.ifremer.tutti.persistence.model.DataModelSupport; + +import javax.swing.tree.DefaultMutableTreeNode; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public abstract class DataSelectTreeNodeSupport<O extends DataModelSupport> extends DefaultMutableTreeNode { + + private static final long serialVersionUID = 1L; + + public abstract boolean isSelected(); + + public abstract void setSelected(boolean selected); + + public abstract O getSelectedDataModel(); + + public DataSelectTreeNodeSupport(O userObject) { + super(userObject); + } + + public String getId() { + return getUserObject().getId(); + } + + public String getLabel() { + return getUserObject().getLabel(); + } + + @Override + public O getUserObject() { + return (O) super.getUserObject(); + } + + @Override + public void setUserObject(Object userObject) { + if (userObject instanceof Boolean) { + setSelected((boolean) userObject); + } else { + super.setUserObject(userObject); + } + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/OperationSelectTreeNode.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/OperationSelectTreeNode.java new file mode 100644 index 0000000..607f5b3 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/OperationSelectTreeNode.java @@ -0,0 +1,51 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.tree; + +import fr.ifremer.tutti.persistence.model.OperationDataModel; + +/** + * Created on 3/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class OperationSelectTreeNode extends DataSelectTreeNodeSupport<OperationDataModel> { + + private static final long serialVersionUID = 1L; + + private boolean selected; + + public OperationSelectTreeNode(OperationDataModel userObject) { + super(userObject); + setAllowsChildren(false); + } + + @Override + public boolean isSelected() { + return selected; + } + + @Override + public void setSelected(boolean selected) { + this.selected = selected; + getParent().updateSelectedSate(); + } + + @Override + public OperationDataModel getSelectedDataModel() { + + OperationDataModel result; + if (isSelected()) { + result = new OperationDataModel(getId(), getLabel()); + } else { + result = null; + } + return result; + + } + + @Override + public CruiseSelectTreeNode getParent() { + return (CruiseSelectTreeNode) super.getParent(); + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/ProgramSelectTreeNode.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/ProgramSelectTreeNode.java new file mode 100644 index 0000000..5e14bea --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/genericformat/tree/ProgramSelectTreeNode.java @@ -0,0 +1,64 @@ +package fr.ifremer.tutti.ui.swing.content.genericformat.tree; + +import com.google.common.collect.Iterators; +import fr.ifremer.tutti.persistence.model.CruiseDataModel; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * Created on 3/30/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class ProgramSelectTreeNode extends DataSelectTreeNodeSupport<ProgramDataModel> implements Iterable<CruiseSelectTreeNode> { + + private static final long serialVersionUID = 1L; + + public ProgramSelectTreeNode(ProgramDataModel userObject) { + super(userObject); + + for (CruiseDataModel cruise : userObject) { + + CruiseSelectTreeNode cruiseNode = new CruiseSelectTreeNode(cruise); + add(cruiseNode); + + } + } + + @Override + public boolean isSelected() { + //Not use here + return false; + } + + @Override + public void setSelected(boolean selected) { + //Not use here + } + + @Override + public ProgramDataModel getSelectedDataModel() { + + Set<CruiseDataModel> cruises = new HashSet<CruiseDataModel>(); + + for (CruiseSelectTreeNode o : this) { + CruiseDataModel cruise = o.getSelectedDataModel(); + if (cruise != null) { + cruises.add(cruise); + } + } + + ProgramDataModel result = new ProgramDataModel(getId(), getLabel(), cruises); + return result; + } + + @Override + public Iterator<CruiseSelectTreeNode> iterator() { + return Iterators.forEnumeration(children()); + } + +} diff --git a/tutti-ui-swing/src/main/resources/icons/action-collapse.png b/tutti-ui-swing/src/main/resources/icons/action-collapse.png new file mode 100644 index 0000000..f88a24a Binary files /dev/null and b/tutti-ui-swing/src/main/resources/icons/action-collapse.png differ diff --git a/tutti-ui-swing/src/main/resources/icons/action-expand.png b/tutti-ui-swing/src/main/resources/icons/action-expand.png new file mode 100644 index 0000000..3c19e48 Binary files /dev/null and b/tutti-ui-swing/src/main/resources/icons/action-expand.png differ diff --git a/tutti-ui-swing/src/main/resources/icons/action-select.png b/tutti-ui-swing/src/main/resources/icons/action-select.png new file mode 100644 index 0000000..bbee129 Binary files /dev/null and b/tutti-ui-swing/src/main/resources/icons/action-select.png differ diff --git a/tutti-ui-swing/src/main/resources/icons/action-unselect.png b/tutti-ui-swing/src/main/resources/icons/action-unselect.png new file mode 100644 index 0000000..3b49008 Binary files /dev/null and b/tutti-ui-swing/src/main/resources/icons/action-unselect.png differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.