r105 - in trunk/tutti-ui-swing/src: main/java/fr/ifremer/tutti/ui/swing/content/operation main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos main/java/fr/ifremer/tutti/ui/swing/content/operation/catches main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste m
Author: tchemit Date: 2012-12-21 21:51:46 +0100 (Fri, 21 Dec 2012) New Revision: 105 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/105 Log: move barches to correct package Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeNode.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIModel.java Removed: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIModel.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModelTest.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -319,6 +319,7 @@ " was modified, will save it."); } + fishingOperationMonitor.clearModified(); // persist current fishingOperation parentUi.getHandler().saveFishingOperation(toSave); } @@ -339,6 +340,9 @@ model.fromBean(bean); + // to be sure saisisseurs are updated + model.setSaisisseur(Lists.newArrayList(bean.getSaisisseur())); + // to be sure combo list will be reloaded model.setStrata(null); model.setSubStrata(null); @@ -361,7 +365,7 @@ // update saisissuer selection List<Person> saisisseur = model.getSaisisseur(); if (log.isInfoEnabled()) { - log.info("Selected saisisseurs: " + saisisseur.size()); + log.info("Selected saisisseurs: " + (saisisseur == null ? 0 : saisisseur.size())); } ui.getSaisisseurList().getModel().setSelected(saisisseur); Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchRowModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,138 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.accidental; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * Define a benthos batch row. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class AccidentalBatchRowModel extends AbstractTuttiBeanUIModel<AccidentalBatch, AccidentalBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_SPECIES = "species"; - - public static final String PROPERTY_WEIGHT = "weight"; - - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - - /** - * Species observed. - * - * @since 0.2 - */ - protected Species species; - - /** - * Observed weight. - * - * @since 0.2 - */ - protected Float weight; - - /** - * Comment on this catches. - * - * @since 0.2 - */ - protected String comment; - - /** - * Attachments - * - * @since 0.2 - */ - protected List<Attachment> attachments; - - protected static final Binder<AccidentalBatch, AccidentalBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(AccidentalBatch.class, - AccidentalBatchRowModel.class); - - protected static final Binder<AccidentalBatchRowModel, AccidentalBatch> toBeanBinder = - BinderFactory.newBinder(AccidentalBatchRowModel.class, - AccidentalBatch.class); - - public AccidentalBatchRowModel() { - super(AccidentalBatch.class, fromBeanBinder, toBeanBinder); - } - - public AccidentalBatchRowModel(AccidentalBatch aBatch) { - this(); - fromBean(aBatch); - } - - public Species getSpecies() { - return species; - } - - public void setSpecies(Species species) { - Object oldValue = getSpecies(); - this.species = species; - firePropertyChange(PROPERTY_SPECIES, oldValue, species); - } - - public Float getWeight() { - return weight; - } - - public void setWeight(Float weight) { - Object oldValue = getWeight(); - this.weight = weight; - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - Object oldValue = getComment(); - this.comment = comment; - firePropertyChange(PROPERTY_COMMENT, oldValue, comment); - } - - public List<Attachment> getAttachments() { - return attachments; - } - - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchTableModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,115 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.accidental; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.benthos.BenthosBatchRowModel; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; - -import javax.swing.table.TableColumnModel; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class AccidentalBatchTableModel extends AbstractTuttiTableModel<AccidentalBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final ColumnIdentifier<AccidentalBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.accidental.batch.header.speciesByCode"), - n_("tutti.table.accidental.batch.header.speciesByCode")); - - public static final ColumnIdentifier<AccidentalBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.accidental.batch.header.speciesByGenusCode"), - n_("tutti.table.accidental.batch.header.speciesByGenusCode")); - - public static final ColumnIdentifier<AccidentalBatchRowModel> WEIGHT = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_WEIGHT, - n_("tutti.table.accidental.batch.header.weight"), - n_("tutti.table.accidental.batch.header.weight")); - - public static final ColumnIdentifier<AccidentalBatchRowModel> COMMENT = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_COMMENT, - n_("tutti.table.accidental.batch.header.comment"), - n_("tutti.table.accidental.batch.header.comment")); - - public static final ColumnIdentifier<AccidentalBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - AccidentalBatchRowModel.PROPERTY_ATTACHMENTS, - n_("tutti.table.accidental.batch.header.file"), - n_("tutti.table.accidental.batch.header.file")); - - - public AccidentalBatchTableModel(TableColumnModel columnModel) { - super(columnModel); - - setNoneEditableCols(); - } - - @Override - protected AccidentalBatchRowModel createNewRow() { - AccidentalBatchRowModel result = new AccidentalBatchRowModel(); - - // by default empty row is not valid - result.setValid(false); - return result; - } - - @Override - public void setValueAt(Object aValue, - int rowIndex, - int columnIndex, - ColumnIdentifier<AccidentalBatchRowModel> propertyName, - AccidentalBatchRowModel entry) { - super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); - - if (propertyName == SPECIES_BY_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, SPECIES_BY_GENUS_CODE); - - } else if (propertyName == SPECIES_BY_GENUS_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, SPECIES_BY_CODE); - } - } - - @Override - protected boolean isCellEditable(int rowIndex, - int columnIndex, - ColumnIdentifier<AccidentalBatchRowModel> propertyName) { - - boolean result = super.isCellEditable(rowIndex, - columnIndex, - propertyName); - - return result; - } -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.css 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -1,37 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -NumberEditor { - autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; - bean: {model}; - showReset: true; -} - -#table { - selectionMode: {ListSelectionModel.SINGLE_SELECTION}; - selectionBackground: {null}; - selectionForeground: {Color.BLACK}; - sortable: false; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -1,71 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<AccidentalBatchUIModel, AccidentalBatchUIHandler>'> - - <import> - fr.ifremer.tutti.ui.swing.TuttiUI - fr.ifremer.tutti.ui.swing.TuttiUIContext - - fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI - - jaxx.runtime.swing.editor.NumberEditor - - org.jdesktop.swingx.JXTable - - javax.swing.ListSelectionModel - - java.awt.Color - - static org.nuiton.i18n.I18n._ - </import> - - <script><![CDATA[ - -public AccidentalBatchUI(TuttiUI<?,?> parentUI) { - JAXXUtil.initContext(this, parentUI); - AccidentalBatchUIHandler handler = new AccidentalBatchUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <AccidentalBatchUIHandler id='handler' - initializer='getContextValue(AccidentalBatchUIHandler.class)'/> - - <AccidentalBatchUIModel id='model' - initializer='getContextValue(AccidentalBatchUIModel.class)'/> - - <LongTextEditorUI id='longTextEditor'/> - - <AttachmentEditorUI id='attachmentEditor'/> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JXTable id='table' onFocusLost='handler.saveSelectedRowIfRequired(event)'/> - </JScrollPane> - -</JPanel> \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,368 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.accidental; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; -import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.table.TableColumnModel; -import java.util.List; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class AccidentalBatchUIHandler extends AbstractTuttiBatchTableUIHandler<AccidentalBatchRowModel, AccidentalBatchUIModel> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AccidentalBatchUIHandler.class); - - /** - * UI. - * - * @since 0.2 - */ - private final AccidentalBatchUI ui; - - public AccidentalBatchUIHandler(TuttiUI<?, ?> parentUi, - AccidentalBatchUI ui) { - super(parentUi, - AccidentalBatchRowModel.PROPERTY_SPECIES, - AccidentalBatchRowModel.PROPERTY_WEIGHT, - AccidentalBatchRowModel.PROPERTY_COMMENT); - this.ui = ui; - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - protected AccidentalBatchUIModel getModel() { - return ui.getModel(); - } - - @Override - protected AccidentalBatchTableModel getTableModel() { - return (AccidentalBatchTableModel) getTable().getModel(); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - List<Species> allSpecies = persistenceService.getAllSpecies(); - - { - // Species (by code) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_CODE); - - addComboDataColumnToModel(columnModel, - AccidentalBatchTableModel.SPECIES_BY_CODE, - decorator, allSpecies); - } - - { - // Species (by genusCode) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_GENUS); - - addComboDataColumnToModel(columnModel, - AccidentalBatchTableModel.SPECIES_BY_GENUS_CODE, - decorator, allSpecies); - - } - - { // Weight column - - addFloatColumnToModel(columnModel, - AccidentalBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Comment column - - addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), - AccidentalBatchTableModel.COMMENT); - } - - { // File column - - addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - AccidentalBatchTableModel.ATTACHMENTS); - } - return columnModel; - } - - @Override - protected void onRowModified(AccidentalBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - - boolean wasValid = row.isValid(); - - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); - } - row.setValid(valid); - } - - @Override - protected void onRowValidStateChanged(AccidentalBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); - - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - - @Override - protected void onRowModifyStateChanged(AccidentalBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onModelRowsChanged(List<AccidentalBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (AccidentalBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } - } - - @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<AccidentalBatchRowModel> rowMonitor = getRowMonitor(); - - AccidentalBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - AccidentalBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteAccidentalBatch(catchBean.getId()); - } - } - } - } - - @Override - protected boolean isRowValid(AccidentalBatchRowModel row) { - boolean result = row.getSpecies() != null && row.getWeight() != null; - return result; - } - - @Override - protected void saveRow(AccidentalBatchRowModel row) { - - AccidentalBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createAccidentalBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.saveAccidentalBatch(catchBean); - } - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - JXTable table = getTable(); - - if (table.isEditing()) { - - // make sure to stop editor - table.editingCanceled(null); - } - - // make sure selection is empty (will remove bean from monitor) - table.clearSelection(); - - boolean empty = bean == null; - - AccidentalBatchUIModel model = getModel(); - - List<AccidentalBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get accidental batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<AccidentalBatch> catches = - persistenceService.getAllAccidentalBatch(bean.getId()); - for (AccidentalBatch aBatch : catches) { - AccidentalBatchRowModel entry = - new AccidentalBatchRowModel(aBatch); - rows.add(entry); - } - } - - } - model.setRows(rows); - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInitUI() { - - if (log.isInfoEnabled()) { - log.info("beforeInit: " + ui); - } - - EditCatchesUIModel catchesUIModel = - ui.getContextValue(EditCatchesUIModel.class); - - AccidentalBatchUIModel model = new AccidentalBatchUIModel(catchesUIModel); - ui.setContextValue(model); - } - - @Override - public void afterInitUI() { - - if (log.isInfoEnabled()) { - log.info("afterInit: " + ui); - } - - initUI(ui); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - // create table model - AccidentalBatchTableModel tableModel = - new AccidentalBatchTableModel(columnModel); - - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initBatchTable(table, columnModel, tableModel); - } - - @Override - public void onCloseUI() { - if (log.isInfoEnabled()) { - log.info("closing: " + ui); - } - } - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,42 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.accidental; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class AccidentalBatchUIModel extends AbstractTuttiBatchUIModel<AccidentalBatchRowModel, AccidentalBatchUIModel> { - - private static final long serialVersionUID = 1L; - - public AccidentalBatchUIModel(EditCatchesUIModel catchesUIModel) { - super(catchesUIModel); - } - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchRowModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,196 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.benthos; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * Define a benthos batch row. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, BenthosBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_SPECIES = "species"; - - public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; - - public static final String PROPERTY_WEIGHT = "weight"; - - public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; - - public static final String PROPERTY_SAMPLING_RATIO = "samplingRatio"; - - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - - /** - * Species observed. - * - * @since 0.2 - */ - protected Species species; - - /** - * Is the species need to be confirmed?. - * - * @since 0.2 - */ - protected boolean speciesToConfirm; - - /** - * Observed weight. - * - * @since 0.2 - */ - protected Float weight; - - /** - * Sample weight. - * - * @since 0.2 - */ - protected Float sampleWeight; - - /** - * Sampling ratio. - * - * @since 0.2 - */ - protected Float samplingRatio; - - /** - * Comment on this catches. - * - * @since 0.2 - */ - protected String comment; - - /** - * Attachments - * - * @since 0.2 - */ - protected List<Attachment> attachments; - - protected static final Binder<BenthosBatch, BenthosBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(BenthosBatch.class, - BenthosBatchRowModel.class); - - protected static final Binder<BenthosBatchRowModel, BenthosBatch> toBeanBinder = - BinderFactory.newBinder(BenthosBatchRowModel.class, - BenthosBatch.class); - - public BenthosBatchRowModel() { - super(BenthosBatch.class, fromBeanBinder, toBeanBinder); - } - - public BenthosBatchRowModel(BenthosBatch aBatch) { - this(); - fromBean(aBatch); - } - - public Species getSpecies() { - return species; - } - - public void setSpecies(Species species) { - Object oldValue = getSpecies(); - this.species = species; - firePropertyChange(PROPERTY_SPECIES, oldValue, species); - } - - public Boolean getSpeciesToConfirm() { - return speciesToConfirm; - } - - public void setSpeciesToConfirm(Boolean speciesToConfirm) { - Object oldValue = getSpeciesToConfirm(); - this.speciesToConfirm = speciesToConfirm; - firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); - } - - public Float getWeight() { - return weight; - } - - public void setWeight(Float weight) { - Object oldValue = getWeight(); - this.weight = weight; - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); - } - - public Float getSampleWeight() { - return sampleWeight; - } - - public void setSampleWeight(Float sampleWeight) { - Object oldValue = getSampleWeight(); - this.sampleWeight = sampleWeight; - firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); - } - - public Float getSamplingRatio() { - return samplingRatio; - } - - public void setSamplingRatio(Float samplingRatio) { - Object oldValue = getSamplingRatio(); - this.samplingRatio = samplingRatio; - firePropertyChange(PROPERTY_SAMPLING_RATIO, oldValue, samplingRatio); - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - Object oldValue = getComment(); - this.comment = comment; - firePropertyChange(PROPERTY_COMMENT, oldValue, comment); - } - - public List<Attachment> getAttachments() { - return attachments; - } - - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); - } - -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchTableModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,143 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.benthos; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesBatchRowModel; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; - -import javax.swing.table.TableColumnModel; -import java.util.Set; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class BenthosBatchTableModel extends AbstractTuttiTableModel<BenthosBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.benthos.batch.header.speciesByCode"), - n_("tutti.table.benthos.batch.header.speciesByCode")); - - public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.benthos.batch.header.speciesByGenusCode"), - n_("tutti.table.benthos.batch.header.speciesByGenusCode")); - - public static final ColumnIdentifier<BenthosBatchRowModel> WEIGHT = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_WEIGHT, - n_("tutti.table.benthos.batch.header.weight"), - n_("tutti.table.benthos.batch.header.weight")); - - public static final ColumnIdentifier<BenthosBatchRowModel> SAMPLE_WEIGHT = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - n_("tutti.table.benthos.batch.header.sampleWeight"), - n_("tutti.table.benthos.batch.header.sampleWeight")); - - public static final ColumnIdentifier<BenthosBatchRowModel> SAMPLING_RATIO = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SAMPLING_RATIO, - n_("tutti.table.benthos.batch.header.samplingRatio"), - n_("tutti.table.benthos.batch.header.samplingRatio")); - - public static final ColumnIdentifier<BenthosBatchRowModel> COMMENT = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_COMMENT, - n_("tutti.table.benthos.batch.header.comment"), - n_("tutti.table.benthos.batch.header.comment")); - - public static final ColumnIdentifier<BenthosBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, - n_("tutti.table.benthos.batch.header.file"), - n_("tutti.table.benthos.batch.header.file")); - - public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES_TO_CONFIRM = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - n_("tutti.table.benthos.batch.header.toConfirm"), - n_("tutti.table.benthos.batch.header.toConfirm")); - - public BenthosBatchTableModel(TableColumnModel columnModel) { - super(columnModel); - - setNoneEditableCols(SAMPLE_WEIGHT, SAMPLING_RATIO); - } - - @Override - protected BenthosBatchRowModel createNewRow() { - BenthosBatchRowModel result = new BenthosBatchRowModel(); - - // by default empty row is not valid - result.setValid(false); - return result; - } - - @Override - public void setValueAt(Object aValue, - int rowIndex, - int columnIndex, - ColumnIdentifier<BenthosBatchRowModel> propertyName, - BenthosBatchRowModel entry) { - super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); - - if (propertyName == SPECIES_BY_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, - SPECIES_BY_GENUS_CODE); - - } else if (propertyName == SPECIES_BY_GENUS_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, - SPECIES_BY_CODE); - } - } - - public void updateSamplingRatio(Set<BenthosBatchRowModel> rows) { - for (BenthosBatchRowModel row : rows) { - int rowIndex = getRows().indexOf(row); - fireTableCellUpdated(rowIndex, - SAMPLE_WEIGHT, - SAMPLING_RATIO); - } - - - } - - @Override - protected boolean isCellEditable(int rowIndex, - int columnIndex, - ColumnIdentifier<BenthosBatchRowModel> propertyName) { - - boolean result = super.isCellEditable(rowIndex, - columnIndex, - propertyName); - - return result; - } -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.css 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -1,83 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -NumberEditor { - autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; - bean: {model}; - showReset: true; -} - -#benthosTotalWeightLabel { - text: "tutti.label.catches.benthosTotalWeight"; - labelFor: {benthosTotalWeightField}; -} - -#benthosTotalWeightField { - property: "benthosTotalWeight"; - model: {model.getBenthosTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#benthosTotalSortedWeightLabel { - text: "tutti.label.catches.benthosTotalSortedWeight"; - labelFor: {benthosTotalSortedWeightField}; -} - -#benthosTotalSortedWeightField { - property: "benthosTotalSortedWeight"; - model: {model.getBenthosTotalSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#benthosTotalSampleSortedWeightLabel { - text: "tutti.label.catches.benthosTotalSampleSortedWeight"; - labelFor: {benthosTotalSampleSortedWeightField}; -} - -#benthosTotalSampleSortedWeightField { - property: "benthosTotalSampleSortedWeight"; - model: {model.getBenthosTotalSampleSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#benthosTotalUnsortedWeightLabel { - text: "tutti.label.catches.benthosTotalUnsortedWeight"; - labelFor: {benthosTotalUnsortedWeightField}; -} - -#benthosTotalUnsortedWeightField { - text: {getStringValue(model.getBenthosTotalUnsortedWeight())}; - editable: false; -} - -#table { - selectionMode: {ListSelectionModel.SINGLE_SELECTION}; - selectionBackground: {null}; - selectionForeground: {Color.BLACK}; - sortable: false; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -1,126 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<BenthosBatchUIModel, BenthosBatchUIHandler>'> - - <import> - fr.ifremer.tutti.ui.swing.TuttiUI - fr.ifremer.tutti.ui.swing.TuttiUIContext - - fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI - - jaxx.runtime.swing.editor.NumberEditor - - jaxx.runtime.validator.swing.SwingValidatorUtil - jaxx.runtime.validator.swing.SwingValidatorMessageTableModel - - org.jdesktop.swingx.JXTable - - javax.swing.ListSelectionModel - - java.awt.Color - - static org.nuiton.i18n.I18n._ - static jaxx.runtime.SwingUtil.getStringValue - </import> - - <script><![CDATA[ - -public BenthosBatchUI(TuttiUI<?,?> parentUI) { - JAXXUtil.initContext(this, parentUI); - BenthosBatchUIHandler handler = new BenthosBatchUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <BenthosBatchUIHandler id='handler' - initializer='getContextValue(BenthosBatchUIHandler.class)'/> - - <BenthosBatchUIModel id='model' - initializer='getContextValue(BenthosBatchUIModel.class)'/> - - <SwingValidatorMessageTableModel id='errorTableModel'/> - - <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' - uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='benthosTotalWeight' component='benthosTotalWeightField'/> - <field name='benthosTotalSortedWeight' - component='benthosTotalSortedWeightField'/> - <field name='benthosTotalSampleSortedWeight' - component='benthosTotalSampleSortedWeightField'/> - <field name='benthosTotalUnsortedWeight' - component='benthosTotalUnsortedWeightField'/> - </BeanValidator> - - <LongTextEditorUI id='longTextEditor'/> - - <AttachmentEditorUI id='attachmentEditor'/> - - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> - - <!-- Poids total / Poids total vrac --> - <row> - <cell anchor='west'> - <JLabel id='benthosTotalWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='benthosTotalWeightField' constructorParams='this'/> - </cell> - <cell anchor='west'> - <JLabel id='benthosTotalSortedWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='benthosTotalSortedWeightField' - constructorParams='this'/> - </cell> - </row> - - <!-- Poids échantillonné vrac / Poids total hors vrac --> - <row> - <cell> - <JLabel id='benthosTotalSampleSortedWeightLabel'/> - </cell> - <cell> - <NumberEditor id='benthosTotalSampleSortedWeightField' - constructorParams='this'/> - </cell> - <cell> - <JLabel id='benthosTotalUnsortedWeightLabel'/> - </cell> - <cell> - <JTextField id='benthosTotalUnsortedWeightField'/> - </cell> - </row> - </Table> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JXTable id='table' - onFocusLost='handler.saveSelectedRowIfRequired(event);'/> - </JScrollPane> - -</JPanel> Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,400 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.benthos; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; -import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.table.TableColumnModel; -import java.util.List; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<BenthosBatchRowModel, BenthosBatchUIModel> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(BenthosBatchUIHandler.class); - - /** - * UI. - * - * @since 0.2 - */ - private final BenthosBatchUI ui; - - public BenthosBatchUIHandler(TuttiUI<?, ?> parentUi, - BenthosBatchUI ui) { - super(parentUi, - BenthosBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - BenthosBatchRowModel.PROPERTY_SPECIES, - BenthosBatchRowModel.PROPERTY_WEIGHT, - BenthosBatchRowModel.PROPERTY_COMMENT); - this.ui = ui; - - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - protected BenthosBatchUIModel getModel() { - return ui.getModel(); - } - - @Override - protected BenthosBatchTableModel getTableModel() { - return (BenthosBatchTableModel) getTable().getModel(); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } - - @Override - protected String[] getRowPropertiesToIgnore() { - return new String[]{ - BenthosBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - BenthosBatchRowModel.PROPERTY_SAMPLING_RATIO - }; - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - List<Species> allSpecies = persistenceService.getAllSpecies(); - - { - // Species (by code) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_CODE); - - addComboDataColumnToModel(columnModel, - BenthosBatchTableModel.SPECIES_BY_CODE, - decorator, allSpecies); - } - - { - // Species (by genusCode) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_GENUS); - - addComboDataColumnToModel(columnModel, - BenthosBatchTableModel.SPECIES_BY_GENUS_CODE, - decorator, allSpecies); - - } - - { // Weight column - - addFloatColumnToModel(columnModel, - BenthosBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Sample weight column - - addColumnToModel(columnModel, - BenthosBatchTableModel.SAMPLE_WEIGHT); - } - - { // SamplingRatio column - - addColumnToModel(columnModel, - BenthosBatchTableModel.SAMPLING_RATIO); - } - - { // Comment column - - addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), - BenthosBatchTableModel.COMMENT); - } - - { // File column - - addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - BenthosBatchTableModel.ATTACHMENTS); - } - - { // Species to confirm column - - addBooleanColumnToModel(columnModel, - BenthosBatchTableModel.SPECIES_TO_CONFIRM, - getTable()); - } - return columnModel; - } - - @Override - protected void onRowModified(BenthosBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - - boolean wasValid = row.isValid(); - - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); - } - row.setValid(valid); - } - - @Override - protected void onRowValidStateChanged(BenthosBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); - - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - - @Override - protected void onRowModifyStateChanged(BenthosBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onModelRowsChanged(List<BenthosBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (BenthosBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } - } - - @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<BenthosBatchRowModel> rowMonitor = getRowMonitor(); - - BenthosBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - BenthosBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteBenthosBatch(catchBean.getId()); - } - } - } - } - - @Override - protected boolean isRowValid(BenthosBatchRowModel row) { - boolean result = row.getSpecies() != null && row.getWeight() != null; - return result; - } - - @Override - protected void saveRow(BenthosBatchRowModel row) { - - BenthosBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createBenthosBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.saveBenthosBatch(catchBean); - } - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - JXTable table = getTable(); - - if (table.isEditing()) { - - // make sure to stop editor - table.editingCanceled(null); - } - - // make sure selection is empty (will remove bean from monitor) - table.clearSelection(); - - boolean empty = bean == null; - - BenthosBatchUIModel model = getModel(); - - List<BenthosBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get species batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<BenthosBatch> catches = - persistenceService.getAllBenthosBatch(bean.getId()); - for (BenthosBatch aBatch : catches) { - BenthosBatchRowModel entry = - new BenthosBatchRowModel(aBatch); - rows.add(entry); - } - } - } - - model.setRows(rows); - } - - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInitUI() { - - if (log.isInfoEnabled()) { - log.info("beforeInit: " + ui); - } - - EditCatchesUIModel catchesUIModel = - ui.getContextValue(EditCatchesUIModel.class); - - BenthosBatchUIModel model = new BenthosBatchUIModel(catchesUIModel); - ui.setContextValue(model); - -// fishingOperationMonitor.setBean(model); - } - - @Override - public void afterInitUI() { - - if (log.isInfoEnabled()) { - log.info("afterInit: " + ui); - } - - initUI(ui); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - // create table model - BenthosBatchTableModel tableModel = - new BenthosBatchTableModel(columnModel); - - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initBatchTable(table, columnModel, tableModel); - } - - @Override - public void onCloseUI() { - if (log.isInfoEnabled()) { - log.info("closing: " + ui); - } - } - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,77 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.benthos; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class BenthosBatchUIModel extends AbstractTuttiBatchUIModel<BenthosBatchRowModel, BenthosBatchUIModel> { - - private static final long serialVersionUID = 1L; - - public BenthosBatchUIModel(EditCatchesUIModel catchesUIModel) { - super(catchesUIModel, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_WEIGHT, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_UNSORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_WEIGHT); - } - - public Float getBenthosTotalWeight() { - return catchesUIModel.getBenthosTotalWeight(); - } - - public void setBenthosTotalWeight(Float benthosTotalWeight) { - catchesUIModel.setBenthosTotalWeight(benthosTotalWeight); - } - - public Float getBenthosTotalSampleSortedWeight() { - return catchesUIModel.getBenthosTotalSampleSortedWeight(); - } - - public void setBenthosTotalSampleSortedWeight(Float benthosTotalSampleSortedWeight) { - catchesUIModel.setBenthosTotalSampleSortedWeight(benthosTotalSampleSortedWeight); - } - - public Float getBenthosTotalSortedWeight() { - return catchesUIModel.getBenthosTotalSortedWeight(); - } - - public void setBenthosTotalSortedWeight(Float benthosTotalSortedWeight) { - catchesUIModel.setBenthosTotalSortedWeight(benthosTotalSortedWeight); - } - - public Float getBenthosTotalUnsortedWeight() { - return catchesUIModel.getBenthosTotalUnsortedWeight(); - } - - public void setBenthosTotalUnsortedWeight(Float benthosTotalUnsortedWeight) { - catchesUIModel.setBenthosTotalUnsortedWeight(benthosTotalUnsortedWeight); - } -} \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -26,11 +26,11 @@ <import> fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI - fr.ifremer.tutti.ui.swing.content.operation.accidental.AccidentalBatchUI - fr.ifremer.tutti.ui.swing.content.operation.benthos.BenthosBatchUI - fr.ifremer.tutti.ui.swing.content.operation.macrowaste.MacroWasteBatchUI - fr.ifremer.tutti.ui.swing.content.operation.plankton.PlanktonBatchUI - fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesBatchUI + fr.ifremer.tutti.ui.swing.content.operation.catches.accidental.AccidentalBatchUI + fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchUI + fr.ifremer.tutti.ui.swing.content.operation.catches.macrowaste.MacroWasteBatchUI + fr.ifremer.tutti.ui.swing.content.operation.catches.plankton.PlanktonBatchUI + fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI org.jdesktop.swingx.JXTitledPanel Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,138 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.accidental; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.List; + +/** + * Define a benthos batch row. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class AccidentalBatchRowModel extends AbstractTuttiBeanUIModel<AccidentalBatch, AccidentalBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_SPECIES = "species"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_COMMENT = "comment"; + + public static final String PROPERTY_ATTACHMENTS = "attachments"; + + /** + * Species observed. + * + * @since 0.2 + */ + protected Species species; + + /** + * Observed weight. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + + /** + * Attachments + * + * @since 0.2 + */ + protected List<Attachment> attachments; + + protected static final Binder<AccidentalBatch, AccidentalBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(AccidentalBatch.class, + AccidentalBatchRowModel.class); + + protected static final Binder<AccidentalBatchRowModel, AccidentalBatch> toBeanBinder = + BinderFactory.newBinder(AccidentalBatchRowModel.class, + AccidentalBatch.class); + + public AccidentalBatchRowModel() { + super(AccidentalBatch.class, fromBeanBinder, toBeanBinder); + } + + public AccidentalBatchRowModel(AccidentalBatch aBatch) { + this(); + fromBean(aBatch); + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + Object oldValue = getSpecies(); + this.species = species; + firePropertyChange(PROPERTY_SPECIES, oldValue, species); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + public List<Attachment> getAttachments() { + return attachments; + } + + public void setAttachments(List<Attachment> attachments) { + Object oldValue = getAttachments(); + this.attachments = attachments; + firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,115 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.accidental; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class AccidentalBatchTableModel extends AbstractTuttiTableModel<AccidentalBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<AccidentalBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.accidental.batch.header.speciesByCode"), + n_("tutti.table.accidental.batch.header.speciesByCode")); + + public static final ColumnIdentifier<AccidentalBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.accidental.batch.header.speciesByGenusCode"), + n_("tutti.table.accidental.batch.header.speciesByGenusCode")); + + public static final ColumnIdentifier<AccidentalBatchRowModel> WEIGHT = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_WEIGHT, + n_("tutti.table.accidental.batch.header.weight"), + n_("tutti.table.accidental.batch.header.weight")); + + public static final ColumnIdentifier<AccidentalBatchRowModel> COMMENT = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_COMMENT, + n_("tutti.table.accidental.batch.header.comment"), + n_("tutti.table.accidental.batch.header.comment")); + + public static final ColumnIdentifier<AccidentalBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + AccidentalBatchRowModel.PROPERTY_ATTACHMENTS, + n_("tutti.table.accidental.batch.header.file"), + n_("tutti.table.accidental.batch.header.file")); + + + public AccidentalBatchTableModel(TableColumnModel columnModel) { + super(columnModel); + + setNoneEditableCols(); + } + + @Override + protected AccidentalBatchRowModel createNewRow() { + AccidentalBatchRowModel result = new AccidentalBatchRowModel(); + + // by default empty row is not valid + result.setValid(false); + return result; + } + + @Override + public void setValueAt(Object aValue, + int rowIndex, + int columnIndex, + ColumnIdentifier<AccidentalBatchRowModel> propertyName, + AccidentalBatchRowModel entry) { + super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); + + if (propertyName == SPECIES_BY_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, SPECIES_BY_GENUS_CODE); + + } else if (propertyName == SPECIES_BY_GENUS_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, SPECIES_BY_CODE); + } + } + + @Override + protected boolean isCellEditable(int rowIndex, + int columnIndex, + ColumnIdentifier<AccidentalBatchRowModel> propertyName) { + + boolean result = super.isCellEditable(rowIndex, + columnIndex, + propertyName); + + return result; + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.css (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,37 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +NumberEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + bean: {model}; + showReset: true; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,71 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<AccidentalBatchUIModel, AccidentalBatchUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + + fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI + fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI + + jaxx.runtime.swing.editor.NumberEditor + + org.jdesktop.swingx.JXTable + + javax.swing.ListSelectionModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + </import> + + <script><![CDATA[ + +public AccidentalBatchUI(TuttiUI<?,?> parentUI) { + JAXXUtil.initContext(this, parentUI); + AccidentalBatchUIHandler handler = new AccidentalBatchUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <AccidentalBatchUIHandler id='handler' + initializer='getContextValue(AccidentalBatchUIHandler.class)'/> + + <AccidentalBatchUIModel id='model' + initializer='getContextValue(AccidentalBatchUIModel.class)'/> + + <LongTextEditorUI id='longTextEditor'/> + + <AttachmentEditorUI id='attachmentEditor'/> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table' onFocusLost='handler.saveSelectedRowIfRequired(event)'/> + </JScrollPane> + +</JPanel> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,368 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.accidental; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.table.TableColumnModel; +import java.util.List; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class AccidentalBatchUIHandler extends AbstractTuttiBatchTableUIHandler<AccidentalBatchRowModel, AccidentalBatchUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AccidentalBatchUIHandler.class); + + /** + * UI. + * + * @since 0.2 + */ + private final AccidentalBatchUI ui; + + public AccidentalBatchUIHandler(TuttiUI<?, ?> parentUi, + AccidentalBatchUI ui) { + super(parentUi, + AccidentalBatchRowModel.PROPERTY_SPECIES, + AccidentalBatchRowModel.PROPERTY_WEIGHT, + AccidentalBatchRowModel.PROPERTY_COMMENT); + this.ui = ui; + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected AccidentalBatchUIModel getModel() { + return ui.getModel(); + } + + @Override + protected AccidentalBatchTableModel getTableModel() { + return (AccidentalBatchTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected FishingOperation getFishingOperation() { + return getModel().getFishingOperation(); + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + List<Species> allSpecies = persistenceService.getAllSpecies(); + + { + // Species (by code) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_CODE); + + addComboDataColumnToModel(columnModel, + AccidentalBatchTableModel.SPECIES_BY_CODE, + decorator, allSpecies); + } + + { + // Species (by genusCode) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_GENUS); + + addComboDataColumnToModel(columnModel, + AccidentalBatchTableModel.SPECIES_BY_GENUS_CODE, + decorator, allSpecies); + + } + + { // Weight column + + addFloatColumnToModel(columnModel, + AccidentalBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Comment column + + addColumnToModel(columnModel, + LongTextCellComponent.newEditor(ui.getLongTextEditor()), + LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + AccidentalBatchTableModel.COMMENT); + } + + { // File column + + addColumnToModel(columnModel, + AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), + AttachmentCellComponent.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")), + AccidentalBatchTableModel.ATTACHMENTS); + } + return columnModel; + } + + @Override + protected void onRowModified(AccidentalBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + boolean wasValid = row.isValid(); + + boolean valid = isRowValid(row); + + if (log.isInfoEnabled()) { + log.info("Was valid / Is valid: " + wasValid + " / " + valid); + } + row.setValid(valid); + } + + @Override + protected void onRowValidStateChanged(AccidentalBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + int rowIndex = getTableModel().getRowIndex(row); + + if (rowIndex > -1) { + getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); + } + } + + @Override + protected void onRowModifyStateChanged(AccidentalBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void onModelRowsChanged(List<AccidentalBatchRowModel> rows) { + super.onModelRowsChanged(rows); + + // set valid flag + for (AccidentalBatchRowModel row : rows) { + boolean valid = isRowValid(row); + row.setValid(valid); + } + } + + @Override + protected void saveSelectedRowIfRequired() { + + TuttiBeanMonitor<AccidentalBatchRowModel> rowMonitor = getRowMonitor(); + + AccidentalBatchRowModel bean = rowMonitor.getBean(); + if (bean != null) { + + if (bean.isValid()) { + // there is a valid bean attached to the monitor + + if (rowMonitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + bean + " was modified, will save it"); + } + + saveRow(bean); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } + } else { + + // row is not valid can not save it + + AccidentalBatch catchBean = bean.toBean(); + + if (!TuttiEntities.isNew(catchBean)) { + + // remove this + persistenceService.deleteAccidentalBatch(catchBean.getId()); + } + } + } + } + + @Override + protected boolean isRowValid(AccidentalBatchRowModel row) { + boolean result = row.getSpecies() != null && row.getWeight() != null; + return result; + } + + @Override + protected void saveRow(AccidentalBatchRowModel row) { + + AccidentalBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createAccidentalBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveAccidentalBatch(catchBean); + } + } + + @Override + public void selectFishingOperation(FishingOperation bean) { + + JXTable table = getTable(); + + if (table.isEditing()) { + + // make sure to stop editor + table.editingCanceled(null); + } + + // make sure selection is empty (will remove bean from monitor) + table.clearSelection(); + + boolean empty = bean == null; + + AccidentalBatchUIModel model = getModel(); + + List<AccidentalBatchRowModel> rows; + + if (empty) { + rows = null; + } else { + + if (log.isInfoEnabled()) { + log.info("Get accidental batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); + + if (!TuttiEntities.isNew(bean)) { + List<AccidentalBatch> catches = + persistenceService.getAllAccidentalBatch(bean.getId()); + for (AccidentalBatch aBatch : catches) { + AccidentalBatchRowModel entry = + new AccidentalBatchRowModel(aBatch); + rows.add(entry); + } + } + + } + model.setRows(rows); + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + if (log.isInfoEnabled()) { + log.info("beforeInit: " + ui); + } + + EditCatchesUIModel catchesUIModel = + ui.getContextValue(EditCatchesUIModel.class); + + AccidentalBatchUIModel model = new AccidentalBatchUIModel(catchesUIModel); + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + if (log.isInfoEnabled()) { + log.info("afterInit: " + ui); + } + + initUI(ui); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + // create table model + AccidentalBatchTableModel tableModel = + new AccidentalBatchTableModel(columnModel); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + initBatchTable(table, columnModel, tableModel); + } + + @Override + public void onCloseUI() { + if (log.isInfoEnabled()) { + log.info("closing: " + ui); + } + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/accidental/AccidentalBatchUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,42 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.accidental; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class AccidentalBatchUIModel extends AbstractTuttiBatchUIModel<AccidentalBatchRowModel, AccidentalBatchUIModel> { + + private static final long serialVersionUID = 1L; + + public AccidentalBatchUIModel(EditCatchesUIModel catchesUIModel) { + super(catchesUIModel); + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,196 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.List; + +/** + * Define a benthos batch row. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, BenthosBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_SPECIES = "species"; + + public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + + public static final String PROPERTY_SAMPLING_RATIO = "samplingRatio"; + + public static final String PROPERTY_COMMENT = "comment"; + + public static final String PROPERTY_ATTACHMENTS = "attachments"; + + /** + * Species observed. + * + * @since 0.2 + */ + protected Species species; + + /** + * Is the species need to be confirmed?. + * + * @since 0.2 + */ + protected boolean speciesToConfirm; + + /** + * Observed weight. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Sample weight. + * + * @since 0.2 + */ + protected Float sampleWeight; + + /** + * Sampling ratio. + * + * @since 0.2 + */ + protected Float samplingRatio; + + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + + /** + * Attachments + * + * @since 0.2 + */ + protected List<Attachment> attachments; + + protected static final Binder<BenthosBatch, BenthosBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(BenthosBatch.class, + BenthosBatchRowModel.class); + + protected static final Binder<BenthosBatchRowModel, BenthosBatch> toBeanBinder = + BinderFactory.newBinder(BenthosBatchRowModel.class, + BenthosBatch.class); + + public BenthosBatchRowModel() { + super(BenthosBatch.class, fromBeanBinder, toBeanBinder); + } + + public BenthosBatchRowModel(BenthosBatch aBatch) { + this(); + fromBean(aBatch); + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + Object oldValue = getSpecies(); + this.species = species; + firePropertyChange(PROPERTY_SPECIES, oldValue, species); + } + + public Boolean getSpeciesToConfirm() { + return speciesToConfirm; + } + + public void setSpeciesToConfirm(Boolean speciesToConfirm) { + Object oldValue = getSpeciesToConfirm(); + this.speciesToConfirm = speciesToConfirm; + firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } + + public Float getSamplingRatio() { + return samplingRatio; + } + + public void setSamplingRatio(Float samplingRatio) { + Object oldValue = getSamplingRatio(); + this.samplingRatio = samplingRatio; + firePropertyChange(PROPERTY_SAMPLING_RATIO, oldValue, samplingRatio); + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + public List<Attachment> getAttachments() { + return attachments; + } + + public void setAttachments(List<Attachment> attachments) { + Object oldValue = getAttachments(); + this.attachments = attachments; + firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,143 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; +import java.util.Set; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class BenthosBatchTableModel extends AbstractTuttiTableModel<BenthosBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.benthos.batch.header.speciesByCode"), + n_("tutti.table.benthos.batch.header.speciesByCode")); + + public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.benthos.batch.header.speciesByGenusCode"), + n_("tutti.table.benthos.batch.header.speciesByGenusCode")); + + public static final ColumnIdentifier<BenthosBatchRowModel> WEIGHT = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_WEIGHT, + n_("tutti.table.benthos.batch.header.weight"), + n_("tutti.table.benthos.batch.header.weight")); + + public static final ColumnIdentifier<BenthosBatchRowModel> SAMPLE_WEIGHT = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + n_("tutti.table.benthos.batch.header.sampleWeight"), + n_("tutti.table.benthos.batch.header.sampleWeight")); + + public static final ColumnIdentifier<BenthosBatchRowModel> SAMPLING_RATIO = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SAMPLING_RATIO, + n_("tutti.table.benthos.batch.header.samplingRatio"), + n_("tutti.table.benthos.batch.header.samplingRatio")); + + public static final ColumnIdentifier<BenthosBatchRowModel> COMMENT = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_COMMENT, + n_("tutti.table.benthos.batch.header.comment"), + n_("tutti.table.benthos.batch.header.comment")); + + public static final ColumnIdentifier<BenthosBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, + n_("tutti.table.benthos.batch.header.file"), + n_("tutti.table.benthos.batch.header.file")); + + public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES_TO_CONFIRM = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + n_("tutti.table.benthos.batch.header.toConfirm"), + n_("tutti.table.benthos.batch.header.toConfirm")); + + public BenthosBatchTableModel(TableColumnModel columnModel) { + super(columnModel); + + setNoneEditableCols(SAMPLE_WEIGHT, SAMPLING_RATIO); + } + + @Override + protected BenthosBatchRowModel createNewRow() { + BenthosBatchRowModel result = new BenthosBatchRowModel(); + + // by default empty row is not valid + result.setValid(false); + return result; + } + + @Override + public void setValueAt(Object aValue, + int rowIndex, + int columnIndex, + ColumnIdentifier<BenthosBatchRowModel> propertyName, + BenthosBatchRowModel entry) { + super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); + + if (propertyName == SPECIES_BY_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, + SPECIES_BY_GENUS_CODE); + + } else if (propertyName == SPECIES_BY_GENUS_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, + SPECIES_BY_CODE); + } + } + + public void updateSamplingRatio(Set<BenthosBatchRowModel> rows) { + for (BenthosBatchRowModel row : rows) { + int rowIndex = getRows().indexOf(row); + fireTableCellUpdated(rowIndex, + SAMPLE_WEIGHT, + SAMPLING_RATIO); + } + + + } + + @Override + protected boolean isCellEditable(int rowIndex, + int columnIndex, + ColumnIdentifier<BenthosBatchRowModel> propertyName) { + + boolean result = super.isCellEditable(rowIndex, + columnIndex, + propertyName); + + return result; + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,83 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +NumberEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + bean: {model}; + showReset: true; +} + +#benthosTotalWeightLabel { + text: "tutti.label.catches.benthosTotalWeight"; + labelFor: {benthosTotalWeightField}; +} + +#benthosTotalWeightField { + property: "benthosTotalWeight"; + model: {model.getBenthosTotalWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#benthosTotalSortedWeightLabel { + text: "tutti.label.catches.benthosTotalSortedWeight"; + labelFor: {benthosTotalSortedWeightField}; +} + +#benthosTotalSortedWeightField { + property: "benthosTotalSortedWeight"; + model: {model.getBenthosTotalSortedWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#benthosTotalSampleSortedWeightLabel { + text: "tutti.label.catches.benthosTotalSampleSortedWeight"; + labelFor: {benthosTotalSampleSortedWeightField}; +} + +#benthosTotalSampleSortedWeightField { + property: "benthosTotalSampleSortedWeight"; + model: {model.getBenthosTotalSampleSortedWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#benthosTotalUnsortedWeightLabel { + text: "tutti.label.catches.benthosTotalUnsortedWeight"; + labelFor: {benthosTotalUnsortedWeightField}; +} + +#benthosTotalUnsortedWeightField { + text: {getStringValue(model.getBenthosTotalUnsortedWeight())}; + editable: false; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,126 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<BenthosBatchUIModel, BenthosBatchUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + + fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI + fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI + + jaxx.runtime.swing.editor.NumberEditor + + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + + org.jdesktop.swingx.JXTable + + javax.swing.ListSelectionModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + static jaxx.runtime.SwingUtil.getStringValue + </import> + + <script><![CDATA[ + +public BenthosBatchUI(TuttiUI<?,?> parentUI) { + JAXXUtil.initContext(this, parentUI); + BenthosBatchUIHandler handler = new BenthosBatchUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <BenthosBatchUIHandler id='handler' + initializer='getContextValue(BenthosBatchUIHandler.class)'/> + + <BenthosBatchUIModel id='model' + initializer='getContextValue(BenthosBatchUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='benthosTotalWeight' component='benthosTotalWeightField'/> + <field name='benthosTotalSortedWeight' + component='benthosTotalSortedWeightField'/> + <field name='benthosTotalSampleSortedWeight' + component='benthosTotalSampleSortedWeightField'/> + <field name='benthosTotalUnsortedWeight' + component='benthosTotalUnsortedWeightField'/> + </BeanValidator> + + <LongTextEditorUI id='longTextEditor'/> + + <AttachmentEditorUI id='attachmentEditor'/> + + <Table id='form' fill='both' constraints='BorderLayout.NORTH'> + + <!-- Poids total / Poids total vrac --> + <row> + <cell anchor='west'> + <JLabel id='benthosTotalWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='benthosTotalWeightField' constructorParams='this'/> + </cell> + <cell anchor='west'> + <JLabel id='benthosTotalSortedWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='benthosTotalSortedWeightField' + constructorParams='this'/> + </cell> + </row> + + <!-- Poids échantillonné vrac / Poids total hors vrac --> + <row> + <cell> + <JLabel id='benthosTotalSampleSortedWeightLabel'/> + </cell> + <cell> + <NumberEditor id='benthosTotalSampleSortedWeightField' + constructorParams='this'/> + </cell> + <cell> + <JLabel id='benthosTotalUnsortedWeightLabel'/> + </cell> + <cell> + <JTextField id='benthosTotalUnsortedWeightField'/> + </cell> + </row> + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table' + onFocusLost='handler.saveSelectedRowIfRequired(event);'/> + </JScrollPane> + +</JPanel> Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,400 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.table.TableColumnModel; +import java.util.List; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<BenthosBatchRowModel, BenthosBatchUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(BenthosBatchUIHandler.class); + + /** + * UI. + * + * @since 0.2 + */ + private final BenthosBatchUI ui; + + public BenthosBatchUIHandler(TuttiUI<?, ?> parentUi, + BenthosBatchUI ui) { + super(parentUi, + BenthosBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + BenthosBatchRowModel.PROPERTY_SPECIES, + BenthosBatchRowModel.PROPERTY_WEIGHT, + BenthosBatchRowModel.PROPERTY_COMMENT); + this.ui = ui; + + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected BenthosBatchUIModel getModel() { + return ui.getModel(); + } + + @Override + protected BenthosBatchTableModel getTableModel() { + return (BenthosBatchTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected FishingOperation getFishingOperation() { + return getModel().getFishingOperation(); + } + + @Override + protected String[] getRowPropertiesToIgnore() { + return new String[]{ + BenthosBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + BenthosBatchRowModel.PROPERTY_SAMPLING_RATIO + }; + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + List<Species> allSpecies = persistenceService.getAllSpecies(); + + { + // Species (by code) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_CODE); + + addComboDataColumnToModel(columnModel, + BenthosBatchTableModel.SPECIES_BY_CODE, + decorator, allSpecies); + } + + { + // Species (by genusCode) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_GENUS); + + addComboDataColumnToModel(columnModel, + BenthosBatchTableModel.SPECIES_BY_GENUS_CODE, + decorator, allSpecies); + + } + + { // Weight column + + addFloatColumnToModel(columnModel, + BenthosBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Sample weight column + + addColumnToModel(columnModel, + BenthosBatchTableModel.SAMPLE_WEIGHT); + } + + { // SamplingRatio column + + addColumnToModel(columnModel, + BenthosBatchTableModel.SAMPLING_RATIO); + } + + { // Comment column + + addColumnToModel(columnModel, + LongTextCellComponent.newEditor(ui.getLongTextEditor()), + LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + BenthosBatchTableModel.COMMENT); + } + + { // File column + + addColumnToModel(columnModel, + AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), + AttachmentCellComponent.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")), + BenthosBatchTableModel.ATTACHMENTS); + } + + { // Species to confirm column + + addBooleanColumnToModel(columnModel, + BenthosBatchTableModel.SPECIES_TO_CONFIRM, + getTable()); + } + return columnModel; + } + + @Override + protected void onRowModified(BenthosBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + boolean wasValid = row.isValid(); + + boolean valid = isRowValid(row); + + if (log.isInfoEnabled()) { + log.info("Was valid / Is valid: " + wasValid + " / " + valid); + } + row.setValid(valid); + } + + @Override + protected void onRowValidStateChanged(BenthosBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + int rowIndex = getTableModel().getRowIndex(row); + + if (rowIndex > -1) { + getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); + } + } + + @Override + protected void onRowModifyStateChanged(BenthosBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void onModelRowsChanged(List<BenthosBatchRowModel> rows) { + super.onModelRowsChanged(rows); + + // set valid flag + for (BenthosBatchRowModel row : rows) { + boolean valid = isRowValid(row); + row.setValid(valid); + } + } + + @Override + protected void saveSelectedRowIfRequired() { + + TuttiBeanMonitor<BenthosBatchRowModel> rowMonitor = getRowMonitor(); + + BenthosBatchRowModel bean = rowMonitor.getBean(); + if (bean != null) { + + if (bean.isValid()) { + // there is a valid bean attached to the monitor + + if (rowMonitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + bean + " was modified, will save it"); + } + + saveRow(bean); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } + } else { + + // row is not valid can not save it + + BenthosBatch catchBean = bean.toBean(); + + if (!TuttiEntities.isNew(catchBean)) { + + // remove this + persistenceService.deleteBenthosBatch(catchBean.getId()); + } + } + } + } + + @Override + protected boolean isRowValid(BenthosBatchRowModel row) { + boolean result = row.getSpecies() != null && row.getWeight() != null; + return result; + } + + @Override + protected void saveRow(BenthosBatchRowModel row) { + + BenthosBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createBenthosBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveBenthosBatch(catchBean); + } + } + + @Override + public void selectFishingOperation(FishingOperation bean) { + + JXTable table = getTable(); + + if (table.isEditing()) { + + // make sure to stop editor + table.editingCanceled(null); + } + + // make sure selection is empty (will remove bean from monitor) + table.clearSelection(); + + boolean empty = bean == null; + + BenthosBatchUIModel model = getModel(); + + List<BenthosBatchRowModel> rows; + + if (empty) { + rows = null; + } else { + + if (log.isInfoEnabled()) { + log.info("Get species batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); + + if (!TuttiEntities.isNew(bean)) { + List<BenthosBatch> catches = + persistenceService.getAllBenthosBatch(bean.getId()); + for (BenthosBatch aBatch : catches) { + BenthosBatchRowModel entry = + new BenthosBatchRowModel(aBatch); + rows.add(entry); + } + } + } + + model.setRows(rows); + } + + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + if (log.isInfoEnabled()) { + log.info("beforeInit: " + ui); + } + + EditCatchesUIModel catchesUIModel = + ui.getContextValue(EditCatchesUIModel.class); + + BenthosBatchUIModel model = new BenthosBatchUIModel(catchesUIModel); + ui.setContextValue(model); + +// fishingOperationMonitor.setBean(model); + } + + @Override + public void afterInitUI() { + + if (log.isInfoEnabled()) { + log.info("afterInit: " + ui); + } + + initUI(ui); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + // create table model + BenthosBatchTableModel tableModel = + new BenthosBatchTableModel(columnModel); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + initBatchTable(table, columnModel, tableModel); + } + + @Override + public void onCloseUI() { + if (log.isInfoEnabled()) { + log.info("closing: " + ui); + } + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/benthos/BenthosBatchUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,77 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class BenthosBatchUIModel extends AbstractTuttiBatchUIModel<BenthosBatchRowModel, BenthosBatchUIModel> { + + private static final long serialVersionUID = 1L; + + public BenthosBatchUIModel(EditCatchesUIModel catchesUIModel) { + super(catchesUIModel, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_UNSORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_WEIGHT); + } + + public Float getBenthosTotalWeight() { + return catchesUIModel.getBenthosTotalWeight(); + } + + public void setBenthosTotalWeight(Float benthosTotalWeight) { + catchesUIModel.setBenthosTotalWeight(benthosTotalWeight); + } + + public Float getBenthosTotalSampleSortedWeight() { + return catchesUIModel.getBenthosTotalSampleSortedWeight(); + } + + public void setBenthosTotalSampleSortedWeight(Float benthosTotalSampleSortedWeight) { + catchesUIModel.setBenthosTotalSampleSortedWeight(benthosTotalSampleSortedWeight); + } + + public Float getBenthosTotalSortedWeight() { + return catchesUIModel.getBenthosTotalSortedWeight(); + } + + public void setBenthosTotalSortedWeight(Float benthosTotalSortedWeight) { + catchesUIModel.setBenthosTotalSortedWeight(benthosTotalSortedWeight); + } + + public Float getBenthosTotalUnsortedWeight() { + return catchesUIModel.getBenthosTotalUnsortedWeight(); + } + + public void setBenthosTotalUnsortedWeight(Float benthosTotalUnsortedWeight) { + catchesUIModel.setBenthosTotalUnsortedWeight(benthosTotalUnsortedWeight); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,138 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.macrowaste; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.MacroWasteBatch; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.List; + +/** + * Define a benthos batch row. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MacroWasteBatchRowModel extends AbstractTuttiBeanUIModel<MacroWasteBatch, MacroWasteBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_MACRO_WASTE_CATEGORY = "macroWasteCategory"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_COMMENT = "comment"; + + public static final String PROPERTY_ATTACHMENTS = "attachments"; + + /** + * macroWaste category. + * + * @since 0.2 + */ + protected CaracteristicQualitativeValue macroWasteCategory; + + /** + * Observed weight. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Comment on this batch. + * + * @since 0.2 + */ + protected String comment; + + /** + * Attachments. + * + * @since 0.2 + */ + protected List<Attachment> attachments; + + protected static final Binder<MacroWasteBatch, MacroWasteBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(MacroWasteBatch.class, + MacroWasteBatchRowModel.class); + + protected static final Binder<MacroWasteBatchRowModel, MacroWasteBatch> toBeanBinder = + BinderFactory.newBinder(MacroWasteBatchRowModel.class, + MacroWasteBatch.class); + + public MacroWasteBatchRowModel() { + super(MacroWasteBatch.class, fromBeanBinder, toBeanBinder); + } + + public MacroWasteBatchRowModel(MacroWasteBatch aBatch) { + this(); + fromBean(aBatch); + } + + public CaracteristicQualitativeValue getMacroWasteCategory() { + return macroWasteCategory; + } + + public void setMacroWasteCategory(CaracteristicQualitativeValue macroWasteCategory) { + Object oldValue = getMacroWasteCategory(); + this.macroWasteCategory = macroWasteCategory; + firePropertyChange(PROPERTY_MACRO_WASTE_CATEGORY, oldValue, macroWasteCategory); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + public List<Attachment> getAttachments() { + return attachments; + } + + public void setAttachments(List<Attachment> attachments) { + Object oldValue = getAttachments(); + this.attachments = attachments; + firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,77 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.macrowaste; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MacroWasteBatchTableModel extends AbstractTuttiTableModel<MacroWasteBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<MacroWasteBatchRowModel> MACRO_WASTE_CATEGORY = ColumnIdentifier.newId( + MacroWasteBatchRowModel.PROPERTY_MACRO_WASTE_CATEGORY, + n_("tutti.table.macrowaste.batch.header.macroWasteCategory"), + n_("tutti.table.macrowaste.batch.header.macroWasteCategory")); + + public static final ColumnIdentifier<MacroWasteBatchRowModel> WEIGHT = ColumnIdentifier.newId( + MacroWasteBatchRowModel.PROPERTY_WEIGHT, + n_("tutti.table.macrowaste.batch.header.weight"), + n_("tutti.table.macrowaste.batch.header.weight")); + + public static final ColumnIdentifier<MacroWasteBatchRowModel> COMMENT = ColumnIdentifier.newId( + MacroWasteBatchRowModel.PROPERTY_COMMENT, + n_("tutti.table.macrowaste.batch.header.comment"), + n_("tutti.table.macrowaste.batch.header.comment")); + + public static final ColumnIdentifier<MacroWasteBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + MacroWasteBatchRowModel.PROPERTY_ATTACHMENTS, + n_("tutti.table.macrowaste.batch.header.file"), + n_("tutti.table.macrowaste.batch.header.file")); + + public MacroWasteBatchTableModel(TableColumnModel columnModel) { + super(columnModel); + + setNoneEditableCols(); + } + + @Override + protected MacroWasteBatchRowModel createNewRow() { + MacroWasteBatchRowModel result = new MacroWasteBatchRowModel(); + + // by default empty row is not valid + result.setValid(false); + return result; + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,49 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +NumberEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + bean: {model}; + showReset: true; +} + +#macroWasteTotalWeightLabel { + text: "tutti.label.catches.macroWasteTotalWeight"; + labelFor: {macroWasteTotalWeightField}; +} + +#macroWasteTotalWeightField { + property: "macroWasteTotalWeight"; + model: {model.getMacroWasteTotalWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,95 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<MacroWasteBatchUIModel, MacroWasteBatchUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + + fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI + fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI + + jaxx.runtime.swing.editor.NumberEditor + + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + + org.jdesktop.swingx.JXTable + + javax.swing.ListSelectionModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + </import> + + <script><![CDATA[ + +public MacroWasteBatchUI(TuttiUI<?,?> parentUI) { + JAXXUtil.initContext(this, parentUI); + MacroWasteBatchUIHandler handler = new MacroWasteBatchUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <MacroWasteBatchUIHandler id='handler' + initializer='getContextValue(MacroWasteBatchUIHandler.class)'/> + + <MacroWasteBatchUIModel id='model' + initializer='getContextValue(MacroWasteBatchUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='macroWasteTotalWeight' component='macroWasteTotalWeightField'/> + </BeanValidator> + + <LongTextEditorUI id='longTextEditor'/> + + <AttachmentEditorUI id='attachmentEditor'/> + + <Table id='form' fill='both' constraints='BorderLayout.NORTH'> + + <!-- Poids total --> + <row> + <cell anchor='west'> + <JLabel id='macroWasteTotalWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='macroWasteTotalWeightField' constructorParams='this'/> + </cell> + </row> + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table' + onFocusLost='handler.saveSelectedRowIfRequired(event);'/> + </JScrollPane> + +</JPanel> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,353 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.macrowaste; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.MacroWasteBatch; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.table.TableColumnModel; +import java.util.List; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MacroWasteBatchUIHandler extends AbstractTuttiBatchTableUIHandler<MacroWasteBatchRowModel, MacroWasteBatchUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(MacroWasteBatchUIHandler.class); + + /** + * UI. + * + * @since 0.2 + */ + private final MacroWasteBatchUI ui; + + public MacroWasteBatchUIHandler(TuttiUI<?, ?> parentUi, MacroWasteBatchUI ui) { + super(parentUi, + MacroWasteBatchRowModel.PROPERTY_MACRO_WASTE_CATEGORY, + MacroWasteBatchRowModel.PROPERTY_WEIGHT, + MacroWasteBatchRowModel.PROPERTY_COMMENT); + this.ui = ui; + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected MacroWasteBatchUIModel getModel() { + return ui.getModel(); + } + + @Override + protected MacroWasteBatchTableModel getTableModel() { + return (MacroWasteBatchTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected FishingOperation getFishingOperation() { + return getModel().getFishingOperation(); + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + { + // MacroWaste Category column + + Decorator<CaracteristicQualitativeValue> decorator = getDecorator( + CaracteristicQualitativeValue.class, null); + + addComboDataColumnToModel(columnModel, + MacroWasteBatchTableModel.MACRO_WASTE_CATEGORY, + decorator, persistenceService.getMacroWasteCategoryCaracteristic().getQualitativeValue()); + } + + { // Weight column + + addFloatColumnToModel(columnModel, + MacroWasteBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Comment column + + addColumnToModel(columnModel, + LongTextCellComponent.newEditor(ui.getLongTextEditor()), + LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + MacroWasteBatchTableModel.COMMENT); + } + + { // File column + + addColumnToModel(columnModel, + AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), + AttachmentCellComponent.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")), + MacroWasteBatchTableModel.ATTACHMENTS); + } + return columnModel; + } + + @Override + protected void onRowModified(MacroWasteBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + boolean wasValid = row.isValid(); + + boolean valid = isRowValid(row); + + if (log.isInfoEnabled()) { + log.info("Was valid / Is valid: " + wasValid + " / " + valid); + } + row.setValid(valid); + } + + @Override + protected void onRowValidStateChanged(MacroWasteBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + int rowIndex = getTableModel().getRowIndex(row); + + if (rowIndex > -1) { + getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); + } + } + + @Override + protected void onRowModifyStateChanged(MacroWasteBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void onModelRowsChanged(List<MacroWasteBatchRowModel> rows) { + super.onModelRowsChanged(rows); + + // set valid flag + for (MacroWasteBatchRowModel row : rows) { + boolean valid = isRowValid(row); + row.setValid(valid); + } + } + + @Override + protected void saveSelectedRowIfRequired() { + + TuttiBeanMonitor<MacroWasteBatchRowModel> rowMonitor = getRowMonitor(); + + MacroWasteBatchRowModel bean = rowMonitor.getBean(); + if (bean != null) { + + if (bean.isValid()) { + // there is a valid bean attached to the monitor + + if (rowMonitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + bean + " was modified, will save it"); + } + + saveRow(bean); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } + } else { + + // row is not valid can not save it + + MacroWasteBatch catchBean = bean.toBean(); + + if (!TuttiEntities.isNew(catchBean)) { + + // remove this + persistenceService.deleteMacroWasteBatch(catchBean.getId()); + } + } + } + } + + @Override + protected boolean isRowValid(MacroWasteBatchRowModel row) { + boolean result = row.getMacroWasteCategory() != null && + row.getWeight() != null; + return result; + } + + @Override + protected void saveRow(MacroWasteBatchRowModel row) { + + MacroWasteBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createMacroWasteBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveMacroWasteBatch(catchBean); + } + } + + @Override + public void selectFishingOperation(FishingOperation bean) { + + JXTable table = getTable(); + + if (table.isEditing()) { + + // make sure to stop editor + table.editingCanceled(null); + } + + // make sure selection is empty (will remove bean from monitor) + table.clearSelection(); + + boolean empty = bean == null; + + MacroWasteBatchUIModel model = getModel(); + + List<MacroWasteBatchRowModel> rows; + + if (empty) { + rows = null; + } else { + + if (log.isInfoEnabled()) { + log.info("Get species batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); + + if (!TuttiEntities.isNew(bean)) { + List<MacroWasteBatch> catches = + persistenceService.getAllMacroWasteBatch(bean.getId()); + for (MacroWasteBatch aBatch : catches) { + MacroWasteBatchRowModel entry = + new MacroWasteBatchRowModel(aBatch); + rows.add(entry); + } + } + } + + model.setRows(rows); + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + if (log.isInfoEnabled()) { + log.info("beforeInit: " + ui); + } + + EditCatchesUIModel catchesUIModel = + ui.getContextValue(EditCatchesUIModel.class); + + MacroWasteBatchUIModel model = new MacroWasteBatchUIModel(catchesUIModel); + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + if (log.isInfoEnabled()) { + log.info("afterInit: " + ui); + } + + initUI(ui); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + // create table model + MacroWasteBatchTableModel tableModel = + new MacroWasteBatchTableModel(columnModel); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + initBatchTable(table, columnModel, tableModel); + } + + @Override + public void onCloseUI() { + if (log.isInfoEnabled()) { + log.info("closing: " + ui); + } + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,50 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.macrowaste; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MacroWasteBatchUIModel extends AbstractTuttiBatchUIModel<MacroWasteBatchRowModel, MacroWasteBatchUIModel> { + + private static final long serialVersionUID = 1L; + + public MacroWasteBatchUIModel(EditCatchesUIModel catchesUIModel) { + super(catchesUIModel, + EditCatchesUIModel.PROPERTY_MACRO_WASTE_TOTAL_WEIGHT); + } + + public Float getMacroWasteTotalWeight() { + return catchesUIModel.getMacroWasteTotalWeight(); + } + + public void setMacroWasteTotalWeight(Float macroWasteTotalWeight) { + catchesUIModel.setMacroWasteTotalWeight(macroWasteTotalWeight); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,195 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.plankton; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.List; + +/** + * Define a benthos batch row. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class PlanktonBatchRowModel extends AbstractTuttiBeanUIModel<PlanktonBatch, PlanktonBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_SPECIES = "species"; + + public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + + public static final String PROPERTY_SAMPLING_RATIO = "samplingRatio"; + + public static final String PROPERTY_COMMENT = "comment"; + + public static final String PROPERTY_ATTACHMENTS = "attachments"; + + /** + * Species observed. + * + * @since 0.2 + */ + protected Species species; + + /** + * Is the species need to be confirmed?. + * + * @since 0.2 + */ + protected boolean speciesToConfirm; + + /** + * Observed weight. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Sample weight. + * + * @since 0.2 + */ + protected Float sampleWeight; + + /** + * Sampling ratio. + * + * @since 0.2 + */ + protected Float samplingRatio; + + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + + /** + * Attachments + * + * @since 0.2 + */ + protected List<Attachment> attachments; + + protected static final Binder<PlanktonBatch, PlanktonBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(PlanktonBatch.class, + PlanktonBatchRowModel.class); + + protected static final Binder<PlanktonBatchRowModel, PlanktonBatch> toBeanBinder = + BinderFactory.newBinder(PlanktonBatchRowModel.class, + PlanktonBatch.class); + + public PlanktonBatchRowModel() { + super(PlanktonBatch.class, fromBeanBinder, toBeanBinder); + } + + public PlanktonBatchRowModel(PlanktonBatch aBatch) { + this(); + fromBean(aBatch); + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + Object oldValue = getSpecies(); + this.species = species; + firePropertyChange(PROPERTY_SPECIES, oldValue, species); + } + + public Boolean getSpeciesToConfirm() { + return speciesToConfirm; + } + + public void setSpeciesToConfirm(Boolean speciesToConfirm) { + Object oldValue = getSpeciesToConfirm(); + this.speciesToConfirm = speciesToConfirm; + firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } + + public Float getSamplingRatio() { + return samplingRatio; + } + + public void setSamplingRatio(Float samplingRatio) { + Object oldValue = getSamplingRatio(); + this.samplingRatio = samplingRatio; + firePropertyChange(PROPERTY_SAMPLING_RATIO, oldValue, samplingRatio); + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + public List<Attachment> getAttachments() { + return attachments; + } + + public void setAttachments(List<Attachment> attachments) { + Object oldValue = getAttachments(); + this.attachments = attachments; + firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,117 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.plankton; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class PlanktonBatchTableModel extends AbstractTuttiTableModel<PlanktonBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<PlanktonBatchRowModel> SPECIES_TO_CONFIRM = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + n_("tutti.table.plankton.batch.header.toConfirm"), + n_("tutti.table.plankton.batch.header.toConfirm")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.plankton.batch.header.speciesByCode"), + n_("tutti.table.plankton.batch.header.speciesByCode")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.plankton.batch.header.speciesByGenusCode"), + n_("tutti.table.plankton.batch.header.speciesByGenusCode")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> WEIGHT = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_WEIGHT, + n_("tutti.table.plankton.batch.header.weight"), + n_("tutti.table.plankton.batch.header.weight")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> SAMPLE_WEIGHT = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + n_("tutti.table.plankton.batch.header.sampleWeight"), + n_("tutti.table.plankton.batch.header.sampleWeight")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> SAMPLING_RATIO = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_SAMPLING_RATIO, + n_("tutti.table.plankton.batch.header.elevationRate"), + n_("tutti.table.plankton.batch.header.elevationRate")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> COMMENT = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_COMMENT, + n_("tutti.table.plankton.batch.header.comment"), + n_("tutti.table.plankton.batch.header.comment")); + + public static final ColumnIdentifier<PlanktonBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_ATTACHMENTS, + n_("tutti.table.plankton.batch.header.file"), + n_("tutti.table.plankton.batch.header.file")); + + public PlanktonBatchTableModel(TableColumnModel columnModel) { + super(columnModel); + + setNoneEditableCols(SAMPLE_WEIGHT, SAMPLING_RATIO); + } + + @Override + protected PlanktonBatchRowModel createNewRow() { + PlanktonBatchRowModel result = new PlanktonBatchRowModel(); + + // by default empty row is not valid + result.setValid(false); + return result; + } + + @Override + public void setValueAt(Object aValue, + int rowIndex, + int columnIndex, + ColumnIdentifier<PlanktonBatchRowModel> propertyName, + PlanktonBatchRowModel entry) { + super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); + + if (propertyName == SPECIES_BY_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, SPECIES_BY_GENUS_CODE); + + } else if (propertyName == SPECIES_BY_GENUS_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, SPECIES_BY_CODE); + } + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,61 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +NumberEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + bean: {model}; + showReset: true; +} + +#planktonTotalWeightLabel { + text: "tutti.label.catches.planktonTotalWeight"; + labelFor: {planktonTotalWeightField}; +} + +#planktonTotalWeightField { + property: "planktonTotalWeight"; + model: {model.getPlanktonTotalWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#planktonTotalSampleWeightLabel { + text: "tutti.label.catches.planktonTotalSampleWeight"; + labelFor: {planktonTotalSampleWeightField}; +} + +#planktonTotalSampleWeightField { + property: "planktonTotalSampleWeight"; + model: {model.getPlanktonTotalSampleWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,107 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<PlanktonBatchUIModel, PlanktonBatchUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI + fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI + + jaxx.runtime.swing.editor.NumberEditor + + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + + org.jdesktop.swingx.JXTable + + javax.swing.ListSelectionModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + </import> + + <script><![CDATA[ + +public PlanktonBatchUI(TuttiUI<?,?> parentUI) { + JAXXUtil.initContext(this, parentUI); + PlanktonBatchUIHandler handler = new PlanktonBatchUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <PlanktonBatchUIHandler id='handler' + initializer='getContextValue(PlanktonBatchUIHandler.class)'/> + + <PlanktonBatchUIModel id='model' + initializer='getContextValue(PlanktonBatchUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='planktonTotalWeight' component='planktonTotalWeightField'/> + <field name='planktonTotalSampleWeight' + component='planktonTotalSampleWeightField'/> + </BeanValidator> + + <LongTextEditorUI id='longTextEditor'/> + + <AttachmentEditorUI id='attachmentEditor'/> + + <Table id='form' fill='both' constraints='BorderLayout.NORTH'> + + <!-- Poids total --> + <row> + <cell anchor='west'> + <JLabel id='planktonTotalWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='planktonTotalWeightField' constructorParams='this'/> + </cell> + </row> + + <!-- Poids total échantillonné --> + <row> + <cell> + <JLabel id='planktonTotalSampleWeightLabel'/> + </cell> + <cell> + <NumberEditor id='planktonTotalSampleWeightField' + constructorParams='this'/> + </cell> + </row> + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table' + onFocusLost='handler.saveSelectedRowIfRequired(event);'/> + </JScrollPane> + +</JPanel> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,397 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.plankton; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.table.TableColumnModel; +import java.util.List; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class PlanktonBatchUIHandler extends AbstractTuttiBatchTableUIHandler<PlanktonBatchRowModel, PlanktonBatchUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(PlanktonBatchUIHandler.class); + + /** + * UI. + * + * @since 0.2 + */ + private final PlanktonBatchUI ui; + + public PlanktonBatchUIHandler(TuttiUI<?, ?> parentUi, PlanktonBatchUI ui) { + super(parentUi, + PlanktonBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + PlanktonBatchRowModel.PROPERTY_SPECIES, + PlanktonBatchRowModel.PROPERTY_WEIGHT, + PlanktonBatchRowModel.PROPERTY_COMMENT); + this.ui = ui; + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected PlanktonBatchUIModel getModel() { + return ui.getModel(); + } + + @Override + protected PlanktonBatchTableModel getTableModel() { + return (PlanktonBatchTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected FishingOperation getFishingOperation() { + return getModel().getFishingOperation(); + } + + @Override + protected String[] getRowPropertiesToIgnore() { + return new String[]{ + PlanktonBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + PlanktonBatchRowModel.PROPERTY_SAMPLING_RATIO + }; + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + { + // Species to confirm column + + addBooleanColumnToModel(columnModel, + PlanktonBatchTableModel.SPECIES_TO_CONFIRM, + getTable()); + } + + List<Species> allSpecies = persistenceService.getAllSpecies(); + + { + // Species (by code) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_CODE); + + addComboDataColumnToModel(columnModel, + PlanktonBatchTableModel.SPECIES_BY_CODE, + decorator, allSpecies); + } + + { + // Species (by genusCode) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_GENUS); + + addComboDataColumnToModel(columnModel, + PlanktonBatchTableModel.SPECIES_BY_GENUS_CODE, + decorator, allSpecies); + + } + + { // Weight column + + addFloatColumnToModel(columnModel, + PlanktonBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Sample weight column + + addColumnToModel(columnModel, + PlanktonBatchTableModel.SAMPLE_WEIGHT); + } + + { // SamplingRatio column + + addColumnToModel(columnModel, + PlanktonBatchTableModel.SAMPLING_RATIO); + } + + { // Comment column + + addColumnToModel(columnModel, + LongTextCellComponent.newEditor(ui.getLongTextEditor()), + LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + PlanktonBatchTableModel.COMMENT); + } + + { // File column + + addColumnToModel(columnModel, + AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), + AttachmentCellComponent.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")), + PlanktonBatchTableModel.ATTACHMENTS); + } + return columnModel; + } + + @Override + protected void onRowModified(PlanktonBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + boolean wasValid = row.isValid(); + + boolean valid = isRowValid(row); + + if (log.isInfoEnabled()) { + log.info("Was valid / Is valid: " + wasValid + " / " + valid); + } + row.setValid(valid); + } + + @Override + protected void onRowValidStateChanged(PlanktonBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + int rowIndex = getTableModel().getRowIndex(row); + + if (rowIndex > -1) { + getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); + } + } + + @Override + protected void onRowModifyStateChanged(PlanktonBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void onModelRowsChanged(List<PlanktonBatchRowModel> rows) { + super.onModelRowsChanged(rows); + + // set valid flag + for (PlanktonBatchRowModel row : rows) { + boolean valid = isRowValid(row); + row.setValid(valid); + } + } + + @Override + protected void saveSelectedRowIfRequired() { + + TuttiBeanMonitor<PlanktonBatchRowModel> rowMonitor = getRowMonitor(); + + PlanktonBatchRowModel bean = rowMonitor.getBean(); + if (bean != null) { + + if (bean.isValid()) { + // there is a valid bean attached to the monitor + + if (rowMonitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + bean + " was modified, will save it"); + } + + saveRow(bean); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } + } else { + + // row is not valid can not save it + + PlanktonBatch catchBean = bean.toBean(); + + if (!TuttiEntities.isNew(catchBean)) { + + // remove this + persistenceService.deletePlanktonBatch(catchBean.getId()); + } + } + } + } + + @Override + protected boolean isRowValid(PlanktonBatchRowModel row) { + boolean result = row.getSpecies() != null && row.getWeight() != null; + return result; + } + + @Override + protected void saveRow(PlanktonBatchRowModel row) { + + PlanktonBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createPlanktonBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.savePlanktonBatch(catchBean); + } + } + + @Override + public void selectFishingOperation(FishingOperation bean) { + + JXTable table = getTable(); + + if (table.isEditing()) { + + // make sure to stop editor + table.editingCanceled(null); + } + + // make sure selection is empty (will remove bean from monitor) + table.clearSelection(); + + boolean empty = bean == null; + + PlanktonBatchUIModel model = getModel(); + + List<PlanktonBatchRowModel> rows; + + if (empty) { + rows = null; + } else { + + + if (log.isInfoEnabled()) { + log.info("Get species batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); + + if (!TuttiEntities.isNew(bean)) { + List<PlanktonBatch> catches = + persistenceService.getAllPlanktonBatch(bean.getId()); + for (PlanktonBatch aBatch : catches) { + PlanktonBatchRowModel entry = + new PlanktonBatchRowModel(aBatch); + rows.add(entry); + } + } + } + + model.setRows(rows); + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + if (log.isInfoEnabled()) { + log.info("beforeInit: " + ui); + } + + EditCatchesUIModel catchesUIModel = + ui.getContextValue(EditCatchesUIModel.class); + + PlanktonBatchUIModel model = new PlanktonBatchUIModel(catchesUIModel); + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + if (log.isInfoEnabled()) { + log.info("afterInit: " + ui); + } + + initUI(ui); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + // create table model + PlanktonBatchTableModel tableModel = + new PlanktonBatchTableModel(columnModel); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + initBatchTable(table, columnModel, tableModel); + } + + @Override + public void onCloseUI() { + if (log.isInfoEnabled()) { + log.info("closing: " + ui); + } + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIModel.java (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,59 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.plankton; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class PlanktonBatchUIModel extends AbstractTuttiBatchUIModel<PlanktonBatchRowModel, PlanktonBatchUIModel> { + + private static final long serialVersionUID = 1L; + + public PlanktonBatchUIModel(EditCatchesUIModel catchesUIModel) { + super(catchesUIModel, + EditCatchesUIModel.PROPERTY_PLANKTON_TOTAL_WEIGHT, + EditCatchesUIModel.PROPERTY_PLANKTON_TOTAL_SAMPLE_WEIGHT); + } + + public Float getPlanktonTotalWeight() { + return catchesUIModel.getPlanktonTotalWeight(); + } + + public void setPlanktonTotalWeight(Float planktonTotalWeight) { + catchesUIModel.setPlanktonTotalWeight(planktonTotalWeight); + } + + public Float getPlanktonTotalSampleWeight() { + return catchesUIModel.getPlanktonTotalSampleWeight(); + } + + public void setPlanktonTotalSampleWeight(Float planktonTotalSampleWeight) { + catchesUIModel.setPlanktonTotalSampleWeight(planktonTotalSampleWeight); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/FrequencyCellComponent.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/FrequencyCellComponent.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/FrequencyCellComponent.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,257 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractCellEditor; +import javax.swing.JButton; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.Color; +import java.awt.Component; +import java.awt.Frame; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Component to render and edit frequency stuff from batch table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class FrequencyCellComponent extends JButton { + + private static final long serialVersionUID = 1L; + + public static final String ROW_INDEX = "rowIndex"; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(FrequencyCellComponent.class); + + public FrequencyCellComponent() { + setContentAreaFilled(false); + setOpaque(false); + setIcon(SwingUtil.createActionIcon("show-frequency")); + } + + public static TableCellRenderer newRender() { + return new FrequencyCellRenderer(); + } + + public static TableCellEditor newEditor(SpeciesFrequencyUI ui) { + return new FrequencyCellEditor(ui); + } + + public static class FrequencyCellEditor extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 1L; + + protected final FrequencyCellComponent component; + + protected final SpeciesFrequencyUI ui; + + protected Frame frame; + + protected JTable table; + + protected SpeciesBatchTableModel tableModel; + + protected ColumnIdentifier<SpeciesBatchRowModel> columnIdentifier; + + protected SpeciesBatchRowModel editRow; + + protected Integer rowIndex; + + protected Integer columnIndex; + + public FrequencyCellEditor(SpeciesFrequencyUI ui) { + this.ui = ui; + component = new FrequencyCellComponent(); + component.setBorder(new LineBorder(Color.BLACK)); + component.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER || + e.getKeyCode() == KeyEvent.VK_SPACE) { + e.consume(); + startEdit(); + } + } + }); + + component.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + e.consume(); + startEdit(); + } + }); + } + + protected void startEdit() { + + Preconditions.checkNotNull(tableModel, "No table model assigned."); + + // open frequency dialog + + Preconditions.checkNotNull(editRow, "No editRow found."); + + if (log.isInfoEnabled()) { + log.info("Will edit frequencies for row: " + rowIndex); + } + + if (frame == null) { + frame = SwingUtil.getParentContainer(ui, Frame.class); + } + + ui.editBatch(editRow); + + // open frequency dialog + TuttiUIUtil.openInDialog( + ui, frame, _("tutti.title.frequency"), true, null); + + // at close, synch back frequencies + + editRow.updateTotalFromFrequencies(); + + int r = rowIndex; + int c = columnIndex; + + // stop edition + stopCellEditing(); + + // reselect this cell + AbstractSelectTableAction.doSelectCell(table, r, c); + table.requestFocus(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + if (tableModel == null) { + tableModel = (SpeciesBatchTableModel) table.getModel(); + this.table = table; + columnIdentifier = tableModel.getPropertyName(column); + } + String text; + if (value == null) { + text = " - "; + } else { + text = String.valueOf(value); + } + component.setText(text); + + rowIndex = row; + columnIndex = column; + + editRow = tableModel.getEntry(row); + + return component; + } + + @Override + public Object getCellEditorValue() { + + Preconditions.checkNotNull(editRow, "No editRow found in editor."); + + Object result; + if (columnIdentifier == SpeciesBatchTableModel.COMPUTED_NUMBER) { + result = editRow.getComputedNumber(); + } else { + result = editRow.getComputedWeight(); + } + if (log.isInfoEnabled()) { + log.info("editor value (" + columnIdentifier + "): " + result); + } + + return result; + } + + @Override + public boolean stopCellEditing() { + boolean b = super.stopCellEditing(); + if (b) { + rowIndex = null; + editRow = null; + columnIndex = null; + } + return b; + } + + @Override + public void cancelCellEditing() { + super.cancelCellEditing(); + rowIndex = null; + columnIndex = null; + editRow = null; + } + } + + public static class FrequencyCellRenderer implements TableCellRenderer { + + protected final FrequencyCellComponent component; + + public FrequencyCellRenderer() { + component = new FrequencyCellComponent(); + } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + String text; + if (value == null) { + text = " - "; + } else { + text = String.valueOf(value); + } + boolean editable = table.isCellEditable(row, column); + component.setEnabled(editable); + component.setText(text); + return component; + } + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/FrequencyCellComponent.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,390 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.apache.commons.collections.CollectionUtils; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.Collections; +import java.util.List; + +/** + * Represents a species batch (i.e a row in the batch table). + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, SpeciesBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_SPECIES = "species"; + + public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; + + public static final String PROPERTY_SORTED_UNSORTED_CATEGORY = "sortedUnsortedCategory"; + + public static final String PROPERTY_SIZE_CATEGORY = "sizeCategory"; + + public static final String PROPERTY_SEX_CATEGORY = "sexCategory"; + + public static final String PROPERTY_MATURITY_CATEGORY = "maturityCategory"; + + public static final String PROPERTY_AGE = "age"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + + public static final String PROPERTY_SAMPLING_RATIO = "samplingRatio"; + + public static final String PROPERTY_COMMENT = "comment"; + + public static final String PROPERTY_FREQUENCY = "frequency"; + + public static final String PROPERTY_COMPUTED_NUMBER = "computedNumber"; + + public static final String PROPERTY_COMPUTED_WEIGHT = "computedWeight"; + + public static final String PROPERTY_ATTACHMENTS = "attachments"; + + /** + * Species observed. + * + * @since 0.2 + */ + protected Species species; + + /** + * Is the species need to be confirmed?. + * + * @since 0.2 + */ + protected boolean speciesToConfirm; + + /** + * Is catch is vrac or horsVrac?. + * + * @since 0.2 + */ + protected CaracteristicQualitativeValue sortedUnsortedCategory; + + /** + * Weight category (can be null). + * + * @since 0.2 + */ + protected CaracteristicQualitativeValue sizeCategory; + + /** + * Sex (can be null). + * + * @since 0.2 + */ + protected CaracteristicQualitativeValue sexCategory; + + /** + * Maturity (can be null). + * + * @since 0.2 + */ + protected CaracteristicQualitativeValue maturityCategory; + + /** + * Age (can be null). + * + * @since 0.2 + */ + protected Float age; + + /** + * Observed weight. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Total computed weight (from frequencies). + * + * @since 0.2 + */ + protected Float computedWeight; + + /** + * Total computed number (from frequencies). + * + * @since 0.2 + */ + protected Float computedNumber; + + /** + * Sample weight. + * + * @since 0.2 + */ + protected Float sampleWeight; + + /** + * Sampling ratio. + * + * @since 0.2 + */ + protected Float samplingRatio; + + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + + /** + * Attachments + * + * @since 0.2 + */ + protected List<Attachment> attachments; + + /** + * List of frequencies observed for this batch. + * + * @since 0.2 + */ + protected List<SpeciesFrequencyRowModel> frequency; + + protected static final Binder<SpeciesBatch, SpeciesBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(SpeciesBatch.class, + SpeciesBatchRowModel.class); + + protected static final Binder<SpeciesBatchRowModel, SpeciesBatch> toBeanBinder = + BinderFactory.newBinder(SpeciesBatchRowModel.class, + SpeciesBatch.class); + + public SpeciesBatchRowModel() { + super(SpeciesBatch.class, fromBeanBinder, toBeanBinder); + frequency = Lists.newArrayList(); + } + + public SpeciesBatchRowModel(SpeciesBatch aBatch, + List<SpeciesBatchFrequency> frequencies) { + this(); + fromBean(aBatch); + List<SpeciesFrequencyRowModel> frequencyRows = + SpeciesFrequencyRowModel.fromBeans(frequencies); + frequency.addAll(frequencyRows); + Collections.sort(frequency); + updateTotalFromFrequencies(); + } + + public void updateTotalFromFrequencies() { + Float totalNumber = null; + Float totalWeight = null; + if (CollectionUtils.isNotEmpty(frequency)) { + totalNumber = 0f; + totalWeight = 0f; + for (SpeciesFrequencyRowModel frequencyModel : frequency) { + totalNumber += frequencyModel.getNumber(); + Float w = frequencyModel.getWeight(); + if (w == null) { + + // can't sum when a null value appears + totalWeight = null; + } else if (totalWeight != null) { + + // still can sum weights + totalWeight += w; + } + } + } + + setComputedNumber(totalNumber); + setComputedWeight(totalWeight); + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + Object oldValue = getSpecies(); + this.species = species; + firePropertyChange(PROPERTY_SPECIES, oldValue, species); + } + + public Boolean getSpeciesToConfirm() { + return speciesToConfirm; + } + + public void setSpeciesToConfirm(Boolean speciesToConfirm) { + Object oldValue = getSpeciesToConfirm(); + this.speciesToConfirm = speciesToConfirm; + firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); + } + + public CaracteristicQualitativeValue getSortedUnsortedCategory() { + return sortedUnsortedCategory; + } + + public void setSortedUnsortedCategory(CaracteristicQualitativeValue sortedUnsortedCategory) { + Object oldValue = getSortedUnsortedCategory(); + this.sortedUnsortedCategory = sortedUnsortedCategory; + firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY, oldValue, sortedUnsortedCategory); + } + + public CaracteristicQualitativeValue getSizeCategory() { + return sizeCategory; + } + + public void setSizeCategory(CaracteristicQualitativeValue sizeCategory) { + Object oldValue = getSizeCategory(); + this.sizeCategory = sizeCategory; + firePropertyChange(PROPERTY_SIZE_CATEGORY, oldValue, sizeCategory); + } + + public CaracteristicQualitativeValue getSexCategory() { + return sexCategory; + } + + public void setSexCategory(CaracteristicQualitativeValue sexCategory) { + Object oldValue = getSexCategory(); + this.sexCategory = sexCategory; + firePropertyChange(PROPERTY_SEX_CATEGORY, oldValue, sexCategory); + } + + public CaracteristicQualitativeValue getMaturityCategory() { + return maturityCategory; + } + + public void setMaturityCategory(CaracteristicQualitativeValue maturityCategory) { + Object oldValue = getMaturityCategory(); + this.maturityCategory = maturityCategory; + firePropertyChange(PROPERTY_MATURITY_CATEGORY, oldValue, maturityCategory); + } + + public Float getAge() { + return age; + } + + public void setAge(Float age) { + Object oldValue = getAge(); + this.age = age; + firePropertyChange(PROPERTY_AGE, oldValue, age); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } + + public Float getSamplingRatio() { + return samplingRatio; + } + + public void setSamplingRatio(Float samplingRatio) { + Object oldValue = getSamplingRatio(); + this.samplingRatio = samplingRatio; + firePropertyChange(PROPERTY_SAMPLING_RATIO, oldValue, samplingRatio); + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + public List<Attachment> getAttachments() { + return attachments; + } + + public void setAttachments(List<Attachment> attachments) { + Object oldValue = getAttachments(); + this.attachments = attachments; + firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + } + + public List<SpeciesFrequencyRowModel> getFrequency() { + return frequency; + } + + public void setFrequency(List<SpeciesFrequencyRowModel> frequency) { + Object oldValue = getFrequency(); + this.frequency = frequency; + firePropertyChange(PROPERTY_FREQUENCY, oldValue, frequency); + } + + public Float getComputedWeight() { + return computedWeight; + } + + public void setComputedWeight(Float computedWeight) { + Object oldValue = getComputedWeight(); + this.computedWeight = computedWeight; + firePropertyChange(PROPERTY_COMPUTED_WEIGHT, oldValue, + computedWeight); + } + + public Float getComputedNumber() { + return computedNumber; + } + + public void setComputedNumber(Float computedNumber) { + Object oldValue = getComputedNumber(); + this.computedNumber = computedNumber; + firePropertyChange(PROPERTY_COMPUTED_NUMBER, oldValue, + computedNumber); + } + + public int getRowCount() { + return frequency == null ? 0 : frequency.size(); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,202 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Sets; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; +import java.util.Set; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesBatchTableModel extends AbstractTuttiTableModel<SpeciesBatchRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.species.batch.header.speciesByCode"), + n_("tutti.table.species.batch.header.speciesByCode")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SPECIES, + n_("tutti.table.species.batch.header.speciesByGenusCode"), + n_("tutti.table.species.batch.header.speciesByGenusCode")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SORTED_UNSORTED_CATEGORY = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, + n_("tutti.table.species.batch.header.sortedUnsortedCategory"), + n_("tutti.table.species.batch.header.sortedUnsortedCategory")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SIZE_CATEGORY = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, + n_("tutti.table.species.batch.header.sizeCategory"), + n_("tutti.table.species.batch.header.sizeCategory")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SEX_CATEGORY = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, + n_("tutti.table.species.batch.header.sexCategory"), + n_("tutti.table.species.batch.header.sexCategory")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> MATURITY_CATEGORY = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, + n_("tutti.table.species.batch.header.maturityCategory"), + n_("tutti.table.species.batch.header.maturityCategory")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> AGE = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_AGE, + n_("tutti.table.species.batch.header.age"), + n_("tutti.table.species.batch.header.age")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> WEIGHT = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_WEIGHT, + n_("tutti.table.species.batch.header.weight"), + n_("tutti.table.species.batch.header.weight")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> COMPUTED_WEIGHT = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_COMPUTED_WEIGHT, + n_("tutti.table.species.batch.header.computedWeight"), + n_("tutti.table.species.batch.header.computedWeight")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> COMPUTED_NUMBER = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_COMPUTED_NUMBER, + n_("tutti.table.species.batch.header.computedNumber"), + n_("tutti.table.species.batch.header.computedNumber")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SAMPLE_WEIGHT = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + n_("tutti.table.species.batch.header.sampleWeight"), + n_("tutti.table.species.batch.header.sampleWeight")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SAMPLING_RATIO = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO, + n_("tutti.table.species.batch.header.elevationRate"), + n_("tutti.table.species.batch.header.elevationRate")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> COMMENT = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_COMMENT, + n_("tutti.table.species.batch.header.comment"), + n_("tutti.table.species.batch.header.comment")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, + n_("tutti.table.species.batch.header.file"), + n_("tutti.table.species.batch.header.file")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES_TO_CONFIRM = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + n_("tutti.table.species.batch.header.toConfirm"), + n_("tutti.table.species.batch.header.toConfirm")); + + protected final Set<ColumnIdentifier<SpeciesBatchRowModel>> noneEditableColIfNoSpecies; + + public SpeciesBatchTableModel(TableColumnModel columnModel) { + super(columnModel); + + setNoneEditableCols(SAMPLE_WEIGHT, SAMPLING_RATIO); + noneEditableColIfNoSpecies = Sets.newHashSet(); + noneEditableColIfNoSpecies.add(COMPUTED_NUMBER); + noneEditableColIfNoSpecies.add(COMPUTED_WEIGHT); + } + + @Override + protected SpeciesBatchRowModel createNewRow() { + SpeciesBatchRowModel result = new SpeciesBatchRowModel(); + + // by default empty row is not valid + result.setValid(false); + return result; + } + + @Override + public void setValueAt(Object aValue, + int rowIndex, + int columnIndex, + ColumnIdentifier<SpeciesBatchRowModel> propertyName, + SpeciesBatchRowModel entry) { + super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); + + if (propertyName == SPECIES_BY_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, + SPECIES_BY_GENUS_CODE, + COMPUTED_NUMBER, + COMPUTED_WEIGHT); + + } else if (propertyName == SPECIES_BY_GENUS_CODE) { + + // update also other columns + fireTableCellUpdated(rowIndex, + SPECIES_BY_CODE, + COMPUTED_NUMBER, + COMPUTED_WEIGHT); + } else if (propertyName == COMPUTED_NUMBER) { + + // update also other columns + fireTableCellUpdated(rowIndex, COMPUTED_WEIGHT); + + } else if (propertyName == COMPUTED_WEIGHT) { + + // update also other columns + fireTableCellUpdated(rowIndex, COMPUTED_NUMBER); + } + } + + public void updateSamplingRatio(Set<SpeciesBatchRowModel> rows) { + for (SpeciesBatchRowModel row : rows) { + int rowIndex = getRows().indexOf(row); + fireTableCellUpdated(rowIndex, SAMPLE_WEIGHT, SAMPLING_RATIO); + } + + + } + + @Override + protected boolean isCellEditable(int rowIndex, + int columnIndex, + ColumnIdentifier<SpeciesBatchRowModel> propertyName) { + + boolean result = super.isCellEditable(rowIndex, + columnIndex, + propertyName); + if (result) { + + if (noneEditableColIfNoSpecies.contains(propertyName)) { + + // must have filled a species to edit this column + SpeciesBatchRowModel entry = getEntry(rowIndex); + result = entry.getSpecies() != null; + } + } + return result; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,297 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import org.apache.commons.collections.CollectionUtils; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesBatchTreeModel implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Root node (with no sampling on it. + * + * @since 0.2 + */ + protected final SpeciesBatchTreeNode root; + + /** + * Property which are used to sub sampling. + * + * @since 0.2 + */ + protected String[] samplingOrder; + + /** + * Mapping from row to node. + * + * @since 0.2 + */ + protected final Map<SpeciesBatchRowModel, SpeciesBatchTreeNode> rowToNode; + + /** + * Mapping from node to row. + * + * @since 0.2 + */ + protected final Multimap<SpeciesBatchTreeNode, SpeciesBatchRowModel> nodeToRow; + + public SpeciesBatchTreeModel(String... samplingOrder) { + this.samplingOrder = samplingOrder; + root = new SpeciesBatchTreeNode(); + rowToNode = Maps.newHashMap(); + nodeToRow = HashMultimap.create(); + } + + public void populate(List<SpeciesBatchRowModel> rows) { + + clear(); + + for (SpeciesBatchRowModel row : rows) { + + SpeciesBatchTreeNode node = getSamplingNode(row); + + // check if row is valid + boolean rowIsValid = isValid(row, node); + + // set it in row + row.setValid(rowIsValid); + } + } + + public String[] getSamplingOrder() { + return samplingOrder; + } + + public void setSamplingOrder(String... samplingOrder) { + this.samplingOrder = samplingOrder; + clear(); + } + + protected void clear() { + // clear tree representation + root.removeAllChildren(); + + // clear mappings + rowToNode.clear(); + nodeToRow.clear(); + } + + public SpeciesBatchTreeNode removeNodeFromCache(SpeciesBatchRowModel row) { + SpeciesBatchTreeNode result = rowToNode.remove(row); + if (result != null) { + + nodeToRow.remove(result, row); + } + return result; + } + + public SpeciesBatchTreeNode getSamplingNode(SpeciesBatchRowModel row) { + + // search frist in cache + SpeciesBatchTreeNode result = rowToNode.get(row); + + if (result == null) { + + // not in cache must build the path + result = getSamplingNode(root, 0, row); + + if (result == root) { + + // this means an empty row, so no node for it + result = null; + + } else { + + // found a row with a sampling, add it in cache + rowToNode.put(row, result); + nodeToRow.put(result, row); + } + } + return result; + } + + protected SpeciesBatchTreeNode getSamplingNode(SpeciesBatchTreeNode node, + int samplingIndex, + SpeciesBatchRowModel row) { + + String samplingKey = samplingOrder[samplingIndex]; + + Serializable samplingValue = (Serializable) + TuttiUIUtil.getProperty(row, samplingKey); + + SpeciesBatchTreeNode result; + + if (samplingValue == null) { + + // was already on last sampling node + result = node; + } else { + + result = node.getChild(samplingValue); + + if (result == null) { + + // new node, creates it and add it as child of current node + result = new SpeciesBatchTreeNode(samplingKey, samplingValue); + node.add(result); + } + + if (samplingIndex < samplingOrder.length) { + + // can try to find yet another sampling level + result = getSamplingNode(result, samplingIndex + 1, row); + } + } + + return result; + } + + public SamplingContext createSamplingContext(SpeciesBatchTreeNode rootNode) { + + Set<SpeciesBatchRowModel> childRows = Sets.newHashSet(); + + SpeciesBatchRowModel superSamplingRow = getNodeToRow(rootNode); + + float totalWeight = 0f; + for (int i = 0, nbChildren = rootNode.getChildCount(); i < nbChildren; i++) { + SpeciesBatchTreeNode node = rootNode.getChildAt(i); + + SpeciesBatchRowModel row = getNodeToRow(node); + if (row != null) { + CaracteristicQualitativeValue sortedUnsortedCategory = + row.getSortedUnsortedCategory(); + if (sortedUnsortedCategory != null && + "unsorted".equals(sortedUnsortedCategory.getName())) { + + // never take account of a such child + + } else { + + childRows.add(row); + Float weight = row.getWeight(); + if (weight != null) { + totalWeight += weight; + } + } + } + } + SamplingContext result = new SamplingContext(rootNode, + superSamplingRow, + childRows, + totalWeight); + return result; + } + + public SpeciesBatchRowModel getNodeToRow(SpeciesBatchTreeNode node) { + Collection<SpeciesBatchRowModel> rows = nodeToRow.get(node); + + SpeciesBatchRowModel result = null; + if (CollectionUtils.isNotEmpty(rows)) { + for (SpeciesBatchRowModel next : rows) { + if (next.isValid()) { + result = next; + break; + } + } + } + return result; + } + + public boolean isValid(SpeciesBatchRowModel row, SpeciesBatchTreeNode newNode) { + + // row must be on a sampling and having a weight + boolean result = row.getWeight() != null && newNode != null; + + // make sure there is not already another row for this node + if (result && CollectionUtils.size(nodeToRow.get(newNode)) > 1) { + result = false; + } + + return result; + } + + public static class SamplingContext { + + private final SpeciesBatchTreeNode rootNode; + + private final SpeciesBatchRowModel superSamplingRow; + + private final Set<SpeciesBatchRowModel> samplingRows; + + private final float totalWeight; + + public SamplingContext(SpeciesBatchTreeNode rootNode, + SpeciesBatchRowModel superSamplingRow, + Set<SpeciesBatchRowModel> samplingRows, + float totalWeight) { + this.rootNode = rootNode; + this.superSamplingRow = superSamplingRow; + this.samplingRows = samplingRows; + this.totalWeight = totalWeight; + } + + public SpeciesBatchTreeNode getRootNode() { + return rootNode; + } + + public SpeciesBatchRowModel getSuperSamplingRow() { + return superSamplingRow; + } + + public Set<SpeciesBatchRowModel> getSamplingRows() { + return samplingRows; + } + + public float getTotalWeight() { + return totalWeight; + } + + public void applyNewSampleValues(float samplingWeight, + Float samplingRatio) { + + for (SpeciesBatchRowModel row : samplingRows) { + row.setSampleWeight(samplingWeight); + row.setSamplingRatio(samplingRatio); + } + } + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeNode.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeNode.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeNode.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,175 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import org.apache.commons.lang3.ObjectUtils; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeNode; +import java.io.Serializable; +import java.util.Arrays; + +/** + * Defines a node of a species catches sampling. + * <p/> + * A path in the tree gives a sampling path. + * <p/> + * UserObject is the {@code samplingValue}. It can be null only on root node. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesBatchTreeNode extends DefaultMutableTreeNode { + + private static final long serialVersionUID = 1L; + + /** + * Property name defining the sampling. + * <p/> + * <strong>Note:</strong> can be null (only for root node). + * + * @since 0.2 + */ + protected final String samplingKey; + + public SpeciesBatchTreeNode() { + this(null, null); + } + + public SpeciesBatchTreeNode(String samplingKey, + Serializable samplingValue) { + this.samplingKey = samplingKey; + setUserObject(samplingValue); + } + + public String getSamplingPropertyKey() { + return samplingKey; + } + + public boolean matchSamplingValue(Serializable value) { + Serializable samplingValue = getUserObject(); + + boolean result = ObjectUtils.equals(value, samplingValue); + return result; + } + + public SpeciesBatchTreeNode getChild(Serializable samplingValue) { + SpeciesBatchTreeNode result = null; + + for (int i = 0, max = getChildCount(); i < max; i++) { + SpeciesBatchTreeNode child = getChildAt(i); + if (child.matchSamplingValue(samplingValue)) { + + // found matching child + result = child; + break; + } + } + return result; + } + + @Override + public Serializable getUserObject() { + return (Serializable) super.getUserObject(); + } + + @Override + public SpeciesBatchTreeNode getChildAt(int index) { + return (SpeciesBatchTreeNode) super.getChildAt(index); + } + + @Override + public SpeciesBatchTreeNode getParent() { + return (SpeciesBatchTreeNode) super.getParent(); + } + + @Override + public SpeciesBatchTreeNode getRoot() { + return (SpeciesBatchTreeNode) super.getRoot(); + } + + @Override + public SpeciesBatchTreeNode getFirstChild() { + return (SpeciesBatchTreeNode) super.getFirstChild(); + } + + @Override + public SpeciesBatchTreeNode getLastChild() { + return (SpeciesBatchTreeNode) super.getLastChild(); + } + + @Override + public SpeciesBatchTreeNode getChildAfter(TreeNode aChild) { + return (SpeciesBatchTreeNode) super.getChildAfter(aChild); + } + + @Override + public SpeciesBatchTreeNode getChildBefore(TreeNode aChild) { + return (SpeciesBatchTreeNode) super.getChildBefore(aChild); + } + + @Override + public SpeciesBatchTreeNode getNextSibling() { + return (SpeciesBatchTreeNode) super.getNextSibling(); + } + + @Override + public SpeciesBatchTreeNode getPreviousSibling() { + return (SpeciesBatchTreeNode) super.getPreviousSibling(); + } + + @Override + public SpeciesBatchTreeNode getFirstLeaf() { + return (SpeciesBatchTreeNode) super.getFirstLeaf(); + } + + @Override + public SpeciesBatchTreeNode getLastLeaf() { + return (SpeciesBatchTreeNode) super.getLastLeaf(); + } + + @Override + public SpeciesBatchTreeNode getNextLeaf() { + return (SpeciesBatchTreeNode) super.getNextLeaf(); + } + + @Override + public SpeciesBatchTreeNode getPreviousLeaf() { + return (SpeciesBatchTreeNode) super.getPreviousLeaf(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SpeciesBatchTreeNode)) return false; + + SpeciesBatchTreeNode that = (SpeciesBatchTreeNode) o; + + Object[] path = getUserObjectPath(); + Object[] path2 = that.getUserObjectPath(); + return Arrays.equals(path, path2); + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTreeNode.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,83 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +NumberEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + bean: {model}; + showReset: true; +} + +#speciesTotalWeightLabel { + text: "tutti.label.catches.speciesTotalWeight"; + labelFor: {speciesTotalWeightField}; +} + +#speciesTotalWeightField { + property: "speciesTotalWeight"; + model: {model.getSpeciesTotalWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#speciesTotalSortedWeightLabel { + text: "tutti.label.catches.speciesTotalSortedWeight"; + labelFor: {speciesTotalSortedWeightField}; +} + +#speciesTotalSortedWeightField { + property: "speciesTotalSortedWeight"; + model: {model.getSpeciesTotalSortedWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#speciesTotalSampleSortedWeightLabel { + text: "tutti.label.catches.speciesTotalSampleSortedWeight"; + labelFor: {speciesTotalSampleSortedWeightField}; +} + +#speciesTotalSampleSortedWeightField { + property: "speciesTotalSampleSortedWeight"; + model: {model.getSpeciesTotalSampleSortedWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#speciesTotalUnsortedWeightLabel { + text: "tutti.label.catches.speciesTotalUnsortedWeight"; + labelFor: {speciesTotalUnsortedWeightField}; +} + +#speciesTotalUnsortedWeightField { + text: {getStringValue(model.getSpeciesTotalUnsortedWeight())}; + editable: false; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,127 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<SpeciesBatchUIModel, SpeciesBatchUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + + fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI + fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI + + org.jdesktop.swingx.JXTable + + jaxx.runtime.swing.editor.NumberEditor + + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + + javax.swing.ListSelectionModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + static jaxx.runtime.SwingUtil.getStringValue + </import> + + <script><![CDATA[ + +public SpeciesBatchUI(TuttiUI<?,?> parentUI) { + JAXXUtil.initContext(this, parentUI); + SpeciesBatchUIHandler handler = new SpeciesBatchUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <SpeciesBatchUIHandler id='handler' + initializer='getContextValue(SpeciesBatchUIHandler.class)'/> + + <SpeciesBatchUIModel id='model' + initializer='getContextValue(SpeciesBatchUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='speciesTotalWeight' component='speciesTotalWeightField'/> + <field name='speciesTotalSortedWeight' + component='speciesTotalSortedWeightField'/> + <field name='speciesTotalSampleSortedWeight' + component='speciesTotalSampleSortedWeightField'/> + <field name='speciesTotalUnsortedWeight' + component='speciesTotalUnsortedWeightField'/> + </BeanValidator> + + <SpeciesFrequencyUI id='frequencyEditor' + constructorParams='handler.getContext()'/> + + <LongTextEditorUI id='longTextEditor'/> + + <AttachmentEditorUI id='attachmentEditor'/> + <Table id='form' fill='both' constraints='BorderLayout.NORTH'> + + <!-- Poids total / Poids total vrac --> + <row> + <cell anchor='west'> + <JLabel id='speciesTotalWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='speciesTotalWeightField' constructorParams='this'/> + </cell> + <cell anchor='west'> + <JLabel id='speciesTotalSortedWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='speciesTotalSortedWeightField' + constructorParams='this'/> + </cell> + </row> + + <!-- Poids échantillonné vrac / Poids total hors vrac --> + <row> + <cell> + <JLabel id='speciesTotalSampleSortedWeightLabel'/> + </cell> + <cell> + <NumberEditor id='speciesTotalSampleSortedWeightField' + constructorParams='this'/> + </cell> + <cell> + <JLabel id='speciesTotalUnsortedWeightLabel'/> + </cell> + <cell> + <JTextField id='speciesTotalUnsortedWeightField'/> + </cell> + </row> + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table' onFocusLost='handler.saveSelectedRowIfRequired(event)'/> + </JScrollPane> + +</JPanel> Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,683 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.table.TableColumnModel; +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.n_; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<SpeciesBatchRowModel, SpeciesBatchUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SpeciesBatchUIHandler.class); + + public static final Set<String> RECOMPUTE_TOTAL_WEIGHT = Sets.newHashSet( + SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, + SpeciesBatchRowModel.PROPERTY_WEIGHT); + + public static final Set<String> SAMPLING_PROPERTIES = Sets.newHashSet( + SpeciesBatchRowModel.PROPERTY_SPECIES, + SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, + SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, + SpeciesBatchRowModel.PROPERTY_AGE); + + /** + * UI. + * + * @since 0.2 + */ + private final SpeciesBatchUI ui; + + public SpeciesBatchUIHandler(TuttiUI<?, ?> parentUi, + SpeciesBatchUI ui) { + super(parentUi, + SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + SpeciesBatchRowModel.PROPERTY_SPECIES, + SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, + SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, + SpeciesBatchRowModel.PROPERTY_AGE, + SpeciesBatchRowModel.PROPERTY_WEIGHT, + SpeciesBatchRowModel.PROPERTY_COMMENT, + SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, + SpeciesBatchRowModel.PROPERTY_FREQUENCY); + this.ui = ui; + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected SpeciesBatchUIModel getModel() { + return ui.getModel(); + } + + @Override + protected SpeciesBatchTableModel getTableModel() { + return (SpeciesBatchTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected FishingOperation getFishingOperation() { + return getModel().getFishingOperation(); + } + + @Override + protected void onModelRowsChanged(List<SpeciesBatchRowModel> rows) { + super.onModelRowsChanged(rows); + + // build the new sampling tree from the new rows to edit + getModel().getSamplingTreeModel().populate(rows); + } + + @Override + protected String[] getRowPropertiesToIgnore() { + return new String[]{ + SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO, + SpeciesBatchRowModel.PROPERTY_FREQUENCY}; + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + Decorator<CaracteristicQualitativeValue> caracteristicDecorator = + getDecorator(CaracteristicQualitativeValue.class, null); + + List<Species> allSpecies = persistenceService.getAllSpecies(); + + { + // Species (by code) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_CODE); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_BY_CODE, + decorator, allSpecies); + } + + { + // Species (by genusCode) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_GENUS); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_BY_GENUS_CODE, + decorator, allSpecies); + + } + + { + + // SortedUnsortedCategory column + + Caracteristic data = + persistenceService.getSortedUnsortedCaracteristic(); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SORTED_UNSORTED_CATEGORY, + caracteristicDecorator, + data.getQualitativeValue()); + } + + { + + // SizeCategory column + + Caracteristic data = + persistenceService.getSizeCategoryCaracteristic(); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SIZE_CATEGORY, + caracteristicDecorator, + data.getQualitativeValue()); + } + + { + + // SexCategory column + + Caracteristic data = persistenceService.getSexCaracteristic(); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SEX_CATEGORY, + caracteristicDecorator, + data.getQualitativeValue()); + } + + { + + // MaturityCategory column + + Caracteristic data = + persistenceService.getMaturityCaracteristic(); + + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.MATURITY_CATEGORY, + caracteristicDecorator, + data.getQualitativeValue()); + } + + { + + // Age column + + addFloatColumnToModel(columnModel, + SpeciesBatchTableModel.AGE, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Weight column + + addFloatColumnToModel(columnModel, + SpeciesBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Computed weight column (from frequencies) + + addColumnToModel(columnModel, + FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), + FrequencyCellComponent.newRender(), + SpeciesBatchTableModel.COMPUTED_WEIGHT); + } + + { // Computed number column (from frequencies) + + addColumnToModel(columnModel, + FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), + FrequencyCellComponent.newRender(), + SpeciesBatchTableModel.COMPUTED_NUMBER); + } + + { // Sample weight column + + addColumnToModel(columnModel, + SpeciesBatchTableModel.SAMPLE_WEIGHT); + } + + { // SamplingRatio column + + addColumnToModel(columnModel, + SpeciesBatchTableModel.SAMPLING_RATIO); + } + + { // Comment column + + addColumnToModel(columnModel, + LongTextCellComponent.newEditor(ui.getLongTextEditor()), + LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + SpeciesBatchTableModel.COMMENT); + } + + { // File column + + addColumnToModel(columnModel, + AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), + AttachmentCellComponent.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")), + SpeciesBatchTableModel.ATTACHMENTS); + } + + { // Species to confirm column + + addBooleanColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_TO_CONFIRM, + getTable()); + } + return columnModel; + } + + @Override + protected void onRowModified(SpeciesBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + if (RECOMPUTE_TOTAL_WEIGHT.contains(propertyName)) { + + // Need to recompute totalHorsVracWeight + recomputeTotalHorsVrac(); + } + + SpeciesBatchUIModel model = getModel(); + + SpeciesBatchTreeModel samplingTreeModel = model.getSamplingTreeModel(); + + if (SAMPLING_PROPERTIES.contains(propertyName)) { + + // Need to rebuilt this row sampling tree path (and then recompute + // old super - samplingRatio and new super - samplingRatio) + + // old node of the previous sampling def for this row + // and remove it from any cache + SpeciesBatchTreeNode oldNode = samplingTreeModel.removeNodeFromCache(row); + + boolean rowWasValid = row.isValid(); + if (oldNode != null && rowWasValid) { + + // remove this row from his super sampling + recomputeSuperSamplingRatio(samplingTreeModel, oldNode); + } + + // get new sampling node + SpeciesBatchTreeNode newNode = samplingTreeModel.getSamplingNode(row); + + // check this row is valid + boolean rowValid = samplingTreeModel.isValid(row, newNode); + + // push this state back to the row + row.setValid(rowValid); + + if (rowValid) { + + // can add it to his super-sampling + recomputeSuperSamplingRatio(samplingTreeModel, newNode); + } else { + + if (rowWasValid) { + + row.setSampleWeight(null); + row.setSamplingRatio(null); + + getTableModel().updateSamplingRatio(Sets.newHashSet(row)); + } + } + } + + if (SpeciesBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { + + // Need to recompute the super - samplingRatio + + SpeciesBatchTreeNode node = samplingTreeModel.getSamplingNode(row); + + boolean rowWasValid = row.isValid(); + + // check this row is valid + boolean rowValid = samplingTreeModel.isValid(row, node); + + // push this state back to the row + row.setValid(rowValid); + + if (rowValid) { + recomputeSuperSamplingRatio(samplingTreeModel, node); + } else { + if (rowWasValid) { + + // must remove this row from his super-sampling + recomputeSuperSamplingRatio(samplingTreeModel, node); + + row.setSampleWeight(null); + row.setSamplingRatio(null); + + getTableModel().updateSamplingRatio(Sets.newHashSet(row)); + } + } + } + } + + @Override + protected void onRowValidStateChanged(SpeciesBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + int rowIndex = getTableModel().getRowIndex(row); + + if (rowIndex > -1) { + getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); + } + } + + @Override + protected void onRowModifyStateChanged(SpeciesBatchRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void saveSelectedRowIfRequired() { + + TuttiBeanMonitor<SpeciesBatchRowModel> rowMonitor = getRowMonitor(); + + SpeciesBatchRowModel bean = rowMonitor.getBean(); + if (bean != null) { + + if (bean.isValid()) { + // there is a valid bean attached to the monitor + + if (rowMonitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + bean + " was modified, will save it"); + } + + saveRow(bean); + + // clear modified flag on the monitor + rowMonitor.clearModified(); + } + } else { + + // row is not valid can not save it + + SpeciesBatch catchBean = bean.toBean(); + + if (!TuttiEntities.isNew(catchBean)) { + + // remove this + persistenceService.deleteSpeciesBatch(catchBean.getId()); + } + } + } + } + + @Override + protected boolean isRowValid(SpeciesBatchRowModel row) { + + SpeciesBatchUIModel model = getModel(); + + SpeciesBatchTreeModel samplingTreeModel = model.getSamplingTreeModel(); + SpeciesBatchTreeNode node = samplingTreeModel.getSamplingNode(row); + boolean rowValid = samplingTreeModel.isValid(row, node); + return rowValid; + } + + @Override + protected void saveRow(SpeciesBatchRowModel row) { + + SpeciesBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getFishingOperation(); + catchBean.setFishingOperation(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Selected fishingOperation: " + fishingOperation.getId()); + } + + if (TuttiEntities.isNew(catchBean)) { + + catchBean = persistenceService.createSpeciesBatch(catchBean); + row.setId(catchBean.getId()); + } else { + persistenceService.saveSpeciesBatch(catchBean); + } + + List<SpeciesFrequencyRowModel> frequencyRows = row.getFrequency(); + + List<SpeciesBatchFrequency> frequency = + SpeciesFrequencyRowModel.toBeans(frequencyRows, catchBean); + + if (log.isInfoEnabled()) { + log.info("Will save " + frequency.size() + " frequencies."); + } + frequency = persistenceService.saveSpeciesBatchFrequency( + catchBean.getId(), frequency); + + // push it back to row model + frequencyRows = SpeciesFrequencyRowModel.fromBeans(frequency); + row.setFrequency(frequencyRows); + } + + @Override + public void selectFishingOperation(FishingOperation bean) { + + JXTable table = ui.getTable(); + + if (table.isEditing()) { + + // make sure to stop editor + table.editingCanceled(null); + } + + // make sure selection is empty (will remove bean from monitor) + table.clearSelection(); + + boolean empty = bean == null; + + SpeciesBatchUIModel model = getModel(); + + List<SpeciesBatchRowModel> rows; + + if (empty) { + rows = null; + } else { + + if (log.isInfoEnabled()) { + log.info("Get species batch for fishingOperation: " + + bean.getId()); + } + rows = Lists.newArrayList(); + + if (!TuttiEntities.isNew(bean)) { + List<SpeciesBatch> catches = + persistenceService.getAllSpeciesBatch(bean.getId()); + for (SpeciesBatch aBatch : catches) { + List<SpeciesBatchFrequency> frequencies = + persistenceService.getAllSpeciesBatchFrequency(aBatch.getId()); + SpeciesBatchRowModel entry = + new SpeciesBatchRowModel(aBatch, frequencies); + rows.add(entry); + } + } + } + model.setRows(rows); + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + if (log.isInfoEnabled()) { + log.info("beforeInit: " + ui); + } + + EditCatchesUIModel catchesUIModel = + ui.getContextValue(EditCatchesUIModel.class); + + SpeciesBatchUIModel model = new SpeciesBatchUIModel(catchesUIModel); + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + if (log.isInfoEnabled()) { + log.info("afterInit: " + ui); + } + + initUI(ui); + + //TODO Will come from protocol + List<String> samplingOrder = Lists.newArrayList( + SpeciesBatchRowModel.PROPERTY_SPECIES, + SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, + SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, + SpeciesBatchRowModel.PROPERTY_AGE + ); + + getModel().setSamplingOrder(samplingOrder); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + // create table model + SpeciesBatchTableModel tableModel = + new SpeciesBatchTableModel(columnModel); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + initBatchTable(table, columnModel, tableModel); + } + + @Override + public void onCloseUI() { + if (log.isInfoEnabled()) { + log.info("closing: " + ui); + } + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void recomputeSuperSamplingRatio(SpeciesBatchTreeModel samplingTreeModel, + SpeciesBatchTreeNode node) { + + SpeciesBatchTreeNode superSamplingNode = node.getParent(); + + Preconditions.checkNotNull(superSamplingNode, + "Super sampling node can't be null"); + + SpeciesBatchTreeModel.SamplingContext samplingContext = + samplingTreeModel.createSamplingContext(superSamplingNode); + + float samplingTotalWeight = samplingContext.getTotalWeight(); + Float superSamplingTotalWeight; + SpeciesBatchRowModel superSamplingRow = + samplingContext.getSuperSamplingRow(); + if (superSamplingRow == null) { + + // Use directly the batch total weight (means no super-sampling) + + superSamplingTotalWeight = getModel().getSpeciesTotalWeight(); + } else { + superSamplingTotalWeight = superSamplingRow.getWeight(); + } + + if (log.isInfoEnabled()) { + log.info("Super sampling total weight: " + + superSamplingTotalWeight); + } + + Float samplingRatio = null; + if (superSamplingTotalWeight != null) { + samplingRatio = samplingTotalWeight / superSamplingTotalWeight; + } + + if (log.isInfoEnabled()) { + log.info("Sampling ratio: " + samplingRatio); + } + + samplingContext.applyNewSampleValues(samplingTotalWeight, + samplingRatio); + + getTableModel().updateSamplingRatio(samplingContext.getSamplingRows()); + } + + protected void recomputeTotalHorsVrac() { + + // recompute total hors vrac + Float totalHorsVrac = 0f; + Float totalVrac = 0f; + + for (SpeciesBatchRowModel batch : getModel().getRows()) { + CaracteristicQualitativeValue vracHorsVrac = + batch.getSortedUnsortedCategory(); + + if (vracHorsVrac == null) { + + // can't sum anything + } else { + boolean unsorted = "unsorted".equals(vracHorsVrac.getName()); + if (unsorted) { + Float weight = batch.getWeight(); + if (weight != null) { + totalHorsVrac += weight; + } + } else { + Float weight = batch.getWeight(); + if (weight != null) { + totalVrac += weight; + } + } + } + } + if (log.isInfoEnabled()) { + log.info("New total vrac / hors vrac: " + + totalVrac + " / " + totalHorsVrac); + } + getModel().setSpeciesTotalUnsortedWeight(totalHorsVrac); + //TODO Should we also set the total vrac weight ? +// getModel().setTotalVracWeight(totalVrac); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java (from rev 104, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,108 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; + +import java.util.List; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel> { + + private static final long serialVersionUID = 1L; + + /** + * Sampling order (sets by protocol). + * + * @since 0.2 + */ + protected List<String> samplingOrder; + + /** + * Tree of sampling for batch rows. + * + * @since 0.2 + */ + protected final SpeciesBatchTreeModel samplingTreeModel; + + public SpeciesBatchUIModel(EditCatchesUIModel catchesUIModel) { + super(catchesUIModel, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_WEIGHT, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT); + this.samplingTreeModel = new SpeciesBatchTreeModel(); + } + + public Float getSpeciesTotalWeight() { + return catchesUIModel.getSpeciesTotalWeight(); + } + + public void setSpeciesTotalWeight(Float speciesTotalWeight) { + catchesUIModel.setSpeciesTotalWeight(speciesTotalWeight); + } + + public Float getSpeciesTotalSortedWeight() { + return catchesUIModel.getSpeciesTotalSortedWeight(); + } + + public void setSpeciesTotalSortedWeight(Float speciesTotalSortedWeight) { + catchesUIModel.setSpeciesTotalSortedWeight(speciesTotalSortedWeight); + } + + public Float getSpeciesTotalSampleSortedWeight() { + return catchesUIModel.getSpeciesTotalSampleSortedWeight(); + } + + public void setSpeciesTotalSampleSortedWeight(Float speciesSampleSortedWeight) { + catchesUIModel.setSpeciesTotalSampleSortedWeight(speciesSampleSortedWeight); + } + + public Float getSpeciesTotalUnsortedWeight() { + return catchesUIModel.getSpeciesTotalUnsortedWeight(); + } + + public void setSpeciesTotalUnsortedWeight(Float speciesTotalUnsortedWeight) { + catchesUIModel.setSpeciesTotalUnsortedWeight(speciesTotalUnsortedWeight); + } + + public SpeciesBatchTreeModel getSamplingTreeModel() { + return samplingTreeModel; + } + + public List<String> getSamplingOrder() { + return samplingOrder; + } + + public void setSamplingOrder(List<String> samplingOrder) { + this.samplingOrder = samplingOrder; + samplingTreeModel.setSamplingOrder(samplingOrder.toArray(new String[samplingOrder.size()])); + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyRowModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,169 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.List; + +/** + * Represents a batch frequency row. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBatchFrequency, SpeciesFrequencyRowModel> implements Comparable<SpeciesFrequencyRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_LENGTH_STEP = "lengthStep"; + + public static final String PROPERTY_NUMBER = "number"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_COMPUTED_WEIGHT = "computedWeight"; + + /** + * Length step. + * + * @since 0.2 + */ + protected Float lengthStep; + + /** + * Count of fishes for this lengthStep. + * + * @since 0.2 + */ + protected Integer number; + + /** + * Weight of fishes observed. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Computed weight from number + relation taille-poids. + * + * @since 0.2 + */ + protected Float computedWeight; + + protected static final Binder<SpeciesBatchFrequency, SpeciesFrequencyRowModel> fromBeanBinder = + BinderFactory.newBinder(SpeciesBatchFrequency.class, + SpeciesFrequencyRowModel.class); + + protected static final Binder<SpeciesFrequencyRowModel, SpeciesBatchFrequency> toBeanBinder = + BinderFactory.newBinder(SpeciesFrequencyRowModel.class, + SpeciesBatchFrequency.class); + + private static final Ordering<Float> ordering = Ordering.natural().nullsFirst(); + + public static List<SpeciesFrequencyRowModel> fromBeans(List<SpeciesBatchFrequency> frequency) { + List<SpeciesFrequencyRowModel> result = Lists.newArrayList(); + for (SpeciesBatchFrequency b : frequency) { + SpeciesFrequencyRowModel model = new SpeciesFrequencyRowModel(); + fromBeanBinder.copy(b, model); + result.add(model); + } + return result; + } + + public static List<SpeciesBatchFrequency> toBeans(List<SpeciesFrequencyRowModel> frequency, SpeciesBatch batch) { + List<SpeciesBatchFrequency> result = Lists.newArrayList(); + for (SpeciesFrequencyRowModel b : frequency) { + SpeciesBatchFrequency model = new SpeciesBatchFrequency(); + toBeanBinder.copy(b, model); + model.setBatch(batch); + result.add(model); + } + return result; + } + + public SpeciesFrequencyRowModel() { + super(SpeciesBatchFrequency.class, fromBeanBinder, toBeanBinder); + } + + public Float getLengthStep() { + return lengthStep; + } + + public void setLengthStep(Float lengthStep) { + Object oldValue = getLengthStep(); + this.lengthStep = lengthStep; + firePropertyChange(PROPERTY_LENGTH_STEP, oldValue, lengthStep); + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + Object oldValue = getNumber(); + this.number = number; + firePropertyChange(PROPERTY_NUMBER, oldValue, number); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public Float getComputedWeight() { + return computedWeight; + } + + public void setComputedWeight(Float computedWeight) { + Object oldValue = getComputedWeight(); + this.computedWeight = computedWeight; + firePropertyChange(PROPERTY_COMPUTED_WEIGHT, oldValue, computedWeight); + } + + //TODO Use validator + @Override + public boolean isValid() { + return lengthStep != null && number != null; + } + + @Override + public int compareTo(SpeciesFrequencyRowModel o) { + int result = ordering.compare(lengthStep, o.lengthStep); + return result; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyTableModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,146 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; +import java.util.List; +import java.util.Map; + +import static org.nuiton.i18n.I18n.n_; + +/** + * Model of the species frequency table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesFrequencyTableModel extends AbstractTuttiTableModel<SpeciesFrequencyRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<SpeciesFrequencyRowModel> LENGTH_STEP = ColumnIdentifier.newId( + SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP, + n_("tutti.table.species.frequency.header.lengthStep"), + n_("tutti.table.species.frequency.header.lengthStep")); + + public static final ColumnIdentifier<SpeciesFrequencyRowModel> NUMBER = ColumnIdentifier.newId( + SpeciesFrequencyRowModel.PROPERTY_NUMBER, + n_("tutti.table.species.frequency.header.number"), + n_("tutti.table.species.frequency.header.number")); + + public static final ColumnIdentifier<SpeciesFrequencyRowModel> WEIGHT = ColumnIdentifier.newId( + SpeciesFrequencyRowModel.PROPERTY_WEIGHT, + n_("tutti.table.species.frequency.header.weight"), + n_("tutti.table.species.frequency.header.weight")); + + public static final ColumnIdentifier<SpeciesFrequencyRowModel> COMPUTED_WEIGHT = ColumnIdentifier.newId( + SpeciesFrequencyRowModel.PROPERTY_COMPUTED_WEIGHT, + n_("tutti.table.species.frequency.header.computedWeight"), + n_("tutti.table.species.frequency.header.computedWeight")); + + private final SpeciesFrequencyUIModel uiModel; + + private final Map<Float, SpeciesFrequencyRowModel> rowCache; + + public SpeciesFrequencyTableModel(TableColumnModel columnModel, + SpeciesFrequencyUIModel uiModel) { + super(columnModel); + this.uiModel = uiModel; + this.rowCache = Maps.newTreeMap(); + setNoneEditableCols(COMPUTED_WEIGHT); + } + + @Override + protected SpeciesFrequencyRowModel createNewRow() { + Float defaultStep = null; + + int rowCount = getRowCount(); + if (rowCount > 0) { + + SpeciesFrequencyRowModel rowModel = getEntry(rowCount - 1); + Float lengthStep = rowModel.getLengthStep(); + if (lengthStep != null) { + defaultStep = uiModel.getLengthStep( + lengthStep + uiModel.getStep()); + } + } + SpeciesFrequencyRowModel result = new SpeciesFrequencyRowModel(); + result.setLengthStep(defaultStep); + result.setValid(false); + return result; + } + + @Override + public void setValueAt(Object aValue, + int rowIndex, + int columnIndex, + ColumnIdentifier<SpeciesFrequencyRowModel> propertyName, + SpeciesFrequencyRowModel entry) { + super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); + // TODO Rebuild the computedWeight if possible... + } + + public Map<Float, SpeciesFrequencyRowModel> getRowCache() { + return rowCache; + } + + @Override + protected void onRowsChanged(List<SpeciesFrequencyRowModel> data) { + + // rebuild row cache + rowCache.clear(); + + for (SpeciesFrequencyRowModel row : data) { + Float lengthStep = row.getLengthStep(); + if (lengthStep != null) { + rowCache.put(lengthStep, row); + } + } + } + + @Override + protected void onRowAdded(int rowIndex, SpeciesFrequencyRowModel newValue) { + + Preconditions.checkNotNull(newValue, "can't add a null row"); + + // add new row to cache + Float lengthStep = newValue.getLengthStep(); + + Preconditions.checkNotNull(lengthStep, + "can't add a null lengthStep row"); + + float roundLenghtValue = uiModel.getLengthStep(lengthStep); + + if (!rowCache.containsKey(roundLenghtValue)) { + + rowCache.put(roundLenghtValue, newValue); + } + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.css (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,142 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +NumberEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; +} + +#stepLabel { + text: "tutti.label.frequencyConfiguration.step"; + labelFor: {stepField}; +} + +#stepField { + property: "step"; + model: {model.getStep()}; + useFloat: true; + numberPattern: {DECIMAL1_PATTERN}; + bean: {model}; +} + +#minStepLabel { + text: "tutti.label.frequencyConfiguration.minStep"; + labelFor: {minStepField}; +} + +#minStepField { + property: "minStep"; + model: {model.getMinStep()}; + useFloat: true; + showReset: true; + numberPattern: {DECIMAL1_PATTERN}; + bean: {model}; +} + +#maxStepLabel { + text: "tutti.label.frequencyConfiguration.maxStep"; + labelFor: {maxStepField}; +} + +#maxStepField { + property: "maxStep"; + model: {model.getMaxStep()}; + useFloat: true; + showReset: true; + numberPattern: {DECIMAL1_PATTERN}; + bean: {model}; +} + +#rafaleStepLabel { + text: "tutti.label.frequencyConfiguration.rafaleStep"; + labelFor: {rafaleStepField}; +} + +#rafaleStepField { + modelType: {Float.class}; + useFloat: true; + showReset: true; + numberPattern: {DECIMAL1_PATTERN}; +} + +#generateButton { + actionIcon: "generate"; + text: "tutti.action.generate"; + enabled: {model.isCanGenerate()}; +} + +#configurationPanel { + border: {new TitledBorder(null, _("tutti.legend.frequencyConfiguration"))}; +} + +#modeConfigurationLayout { + selected: {String.valueOf(mode.getSelectedValue())}; +} + +#modeConfigurationPanel { + layout: {modeConfigurationLayout}; +} + +#simpleModeButton { + text: "tutti.label.frequencyConfiguration.mode.simple"; + toolTipText: "tutti.label.frequencyConfiguration.mode.simple.tip"; + value: "simpleMode"; + selected: {model.isSimpleMode()}; + buttonGroup: "mode"; +} + +#simpleModeLabel { + text: "tutti.label.frequencyConfiguration.no.configuration"; + horizontalAlignment: {JLabel.CENTER}; + enabled: false; +} + +#autoGenModeButton { + text: "tutti.label.frequencyConfiguration.mode.autoGen"; + toolTipText: "tutti.label.frequencyConfiguration.mode.autoGen.tip"; + value: "autoGenMode"; + selected: {model.isAutoGenMode()}; + buttonGroup: "mode"; +} + +#rafaleModeButton { + text: "tutti.label.frequencyConfiguration.mode.rafale"; + toolTipText: "tutti.label.frequencyConfiguration.mode.rafale.tip"; + value: "rafaleMode"; + selected: {model.isRafaleMode()}; + buttonGroup: "mode"; +} + +#closeButton { + actionIcon: "close"; + text: "tutti.action.close"; + mnemonic: F; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.jaxx (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,167 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<SpeciesFrequencyUIModel, SpeciesFrequencyUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel + + jaxx.runtime.swing.CardLayout2Ext + jaxx.runtime.swing.editor.bean.BeanComboBox + jaxx.runtime.swing.editor.NumberEditor + + org.jdesktop.swingx.JXTable + + javax.swing.ListSelectionModel + javax.swing.SwingConstants + + java.awt.Color + java.awt.Dimension + + static org.nuiton.i18n.I18n._ + static jaxx.runtime.SwingUtil.getStringValue + </import> + + <script><![CDATA[ + + public SpeciesFrequencyUI(TuttiUIContext context) { + SpeciesFrequencyUIHandler handler = new SpeciesFrequencyUIHandler(context, this); + setContextValue(handler); + handler.beforeInitUI(); + } + + public void editBatch(SpeciesBatchRowModel row) { + handler.editBatch(row); + } + + protected void $afterCompleteSetup() { + handler.afterInitUI(); + } + ]]></script> + + <SpeciesFrequencyUIHandler id='handler' + initializer='getContextValue(SpeciesFrequencyUIHandler.class)'/> + + <SpeciesFrequencyUIModel id='model' + initializer='getContextValue(SpeciesFrequencyUIModel.class)'/> + + <CardLayout2Ext id='modeConfigurationLayout' + constructorParams='this, "modeConfigurationPanel"'/> + + <JPanel id='configurationPanel' layout='{new BorderLayout()}' constraints='BorderLayout.NORTH'> + + <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.CENTER'> + <VBox id='modePanel' constraints='BorderLayout.WEST' + verticalAlignment='{SwingConstants.CENTER}'> + <JRadioButton id='simpleModeButton' + onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE)'/> + <JRadioButton id='autoGenModeButton' + onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.AUTO_GEN)'/> + <JRadioButton id='rafaleModeButton' + onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.RAFALE)'/> + </VBox> + + <JPanel id='modeConfigurationPanel' constraints='BorderLayout.CENTER'> + <JPanel id='simpleModePanel' constraints='"simpleMode"' + layout='{new BorderLayout()}'> + <JLabel id='simpleModeLabel' constraints='BorderLayout.CENTER'/> + </JPanel> + <JPanel id='autoGenModePanel' constraints='"autoGenMode"'> + <Table fill='both' constraints='BorderLayout.SOUTH'> + <!-- Min step--> + <row> + <cell anchor='west'> + <JLabel id='minStepLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='minStepField' constructorParams='this'/> + </cell> + </row> + <!-- Max step--> + <row> + <cell anchor='west'> + <JLabel id='maxStepLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='maxStepField' constructorParams='this'/> + </cell> + </row> + <!-- Actions --> + <row> + <cell columns='2'> + <JPanel layout='{new GridLayout(1, 0)}'> + <JButton id='generateButton' + onActionPerformed='handler.generateLengthSteps()'/> + </JPanel> + </cell> + </row> + </Table> + </JPanel> + <JPanel id='rafaleModePanel' constraints='"rafaleMode"'> + <Table fill='both' constraints='BorderLayout.SOUTH'> + <!-- Rafale step--> + <row> + <cell weightx='1.0'> + <JLabel id='rafaleStepLabel'/> + </cell> + </row> + <row> + <cell weightx='1.0'> + <NumberEditor id='rafaleStepField' constructorParams='this'/> + </cell> + </row> + </Table> + </JPanel> + </JPanel> + </JPanel> + <Table fill='both' constraints='BorderLayout.SOUTH'> + <row> + <cell columns='2'> + <JSeparator/> + </cell> + </row> + <!-- Step --> + <row> + <cell anchor='west'> + <JLabel id='stepLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='stepField' constructorParams='this'/> + </cell> + </row> + </Table> + </JPanel> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table'/> + </JScrollPane> + + <!-- actions --> + <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}' + constraints='BorderLayout.SOUTH'> + <JButton id='closeButton' onActionPerformed='handler.close()'/> + </JPanel> + +</JPanel> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIHandler.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,362 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; +import jaxx.runtime.SwingUtil; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; + +import javax.swing.JDialog; +import javax.swing.table.TableColumnModel; +import java.awt.Color; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<SpeciesFrequencyRowModel, SpeciesFrequencyUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SpeciesFrequencyUIHandler.class); + + private final SpeciesFrequencyUI ui; + + public SpeciesFrequencyUIHandler(TuttiUIContext context, + SpeciesFrequencyUI ui) { + super(context, + SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP, + SpeciesFrequencyRowModel.PROPERTY_NUMBER, + SpeciesFrequencyRowModel.PROPERTY_WEIGHT, + SpeciesFrequencyRowModel.PROPERTY_COMPUTED_WEIGHT); + this.ui = ui; + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected SpeciesFrequencyUIModel getModel() { + return ui.getModel(); + } + + @Override + protected SpeciesFrequencyTableModel getTableModel() { + return (SpeciesFrequencyTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); + + { // LengthStep + + addFloatColumnToModel(columnModel, + SpeciesFrequencyTableModel.LENGTH_STEP, + TuttiUI.DECIMAL1_PATTERN); + } + + { // Number + + addIntegerColumnToModel(columnModel, + SpeciesFrequencyTableModel.NUMBER, + TuttiUI.INT_6_DIGITS_PATTERN); + } + + { // Weight + + addFloatColumnToModel(columnModel, + SpeciesFrequencyTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // ComputedWeight + + addFloatColumnToModel(columnModel, + SpeciesFrequencyTableModel.COMPUTED_WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + return columnModel; + } + + @Override + protected void onRowModified(SpeciesFrequencyRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + if (SpeciesFrequencyRowModel.PROPERTY_NUMBER.equals(propertyName)) { + + // Need to recompute the computedWeight + computeComputedWeight(row); + } + } + + @Override + protected void onRowValidStateChanged(SpeciesFrequencyRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void onRowModifyStateChanged(SpeciesFrequencyRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + SpeciesFrequencyUIModel model = new SpeciesFrequencyUIModel(); + + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + initUI(ui); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + SpeciesFrequencyUIModel model = getModel(); + + // create table model + SpeciesFrequencyTableModel tableModel = + new SpeciesFrequencyTableModel(columnModel, model); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + installTableKeyListener(columnModel, table); + + table.getTableHeader().setReorderingAllowed(false); + + table.addHighlighter(TuttiUIUtil.newBackgroundColorHighlighter( + HighlightPredicate.READ_ONLY, Color.LIGHT_GRAY)); + + // when model datas change let's propagate it table model + listenRowsFromModel(); + + //TODO Should it come from PROTOCOL or config ? + model.setStep(.5f); + + model.setMinStep(10f); + model.setMaxStep(20f); + + //TODO Configure this ? + model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE); + + // always scroll to selected row + SwingUtil.scrollToTableSelection(getTable()); + + ui.getRafaleStepField().getTextField().addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + e.consume(); + Float step = (Float) ui.getRafaleStepField().getModel(); + + applyRafaleStep(step); + } + } + }); + } + + @Override + public void onCloseUI() { + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + public void generateLengthSteps() { + + SpeciesFrequencyUIModel model = getModel(); + + Map<Float, SpeciesFrequencyRowModel> rowsByStep = + getTableModel().getRowCache(); + + Float minStep = model.getLengthStep(model.getMinStep()); + Float maxStep = model.getLengthStep(model.getMaxStep()); + + for (float i = minStep, step = model.getStep(); i <= maxStep; i += step) { + if (!rowsByStep.containsKey(i)) { + + // add it + SpeciesFrequencyRowModel newRow = new SpeciesFrequencyRowModel(); + newRow.setLengthStep(i); + rowsByStep.put(i, newRow); + } + } + + List<SpeciesFrequencyRowModel> rows = + Lists.newArrayList(rowsByStep.values()); + + model.setRows(rows); + } + + public void applyRafaleStep(Float step) { + + if (log.isInfoEnabled()) { + log.info("Will apply rafale step: " + step); + } + SpeciesFrequencyUIModel model = getModel(); + SpeciesFrequencyTableModel tableModel = getTableModel(); + + Map<Float, SpeciesFrequencyRowModel> rowsByStep = tableModel.getRowCache(); + + float aroundLengthStep = model.getLengthStep(step); + + SpeciesFrequencyRowModel row = rowsByStep.get(aroundLengthStep); + + int rowIndex; + + if (row != null) { + + // increments current row + Integer number = row.getNumber(); + row.setNumber((number == null ? 0 : number) + 1); + rowIndex = tableModel.updateRow(row); + + } else { + + // create a new row + row = new SpeciesFrequencyRowModel(); + row.setLengthStep(aroundLengthStep); + row.setNumber(1); + + // get new index + List<Float> steps = Lists.newArrayList(rowsByStep.keySet()); + steps.add(aroundLengthStep); + + Collections.sort(steps); + + rowIndex = steps.indexOf(aroundLengthStep); + + tableModel.addNewRow(rowIndex, row); + } + + getTable().scrollRowToVisible(rowIndex); + } + + public void editBatch(SpeciesBatchRowModel row) { + + List<SpeciesFrequencyRowModel> frequency = null; + if (row != null) { + frequency = row.getFrequency(); + } + + List<SpeciesFrequencyRowModel> editFrequency; + if (CollectionUtils.isEmpty(frequency)) { + + // new list + editFrequency = Lists.newArrayList(); + } else { + + editFrequency = Lists.newArrayList(frequency); + } + + if (log.isInfoEnabled()) { + log.info("Will edit batch row: " + row + " with " + + editFrequency.size() + " frequency"); + } + getModel().setRows(editFrequency); + + // keep batch (will be used to push back editing entry) + getModel().setBatch(row); + } + + public void close() { + + if (log.isInfoEnabled()) { + log.info("Will close UI " + ui); + } + + // transfer rows to editor + + List<SpeciesFrequencyRowModel> frequency = Lists.newArrayList(); + for (SpeciesFrequencyRowModel row : getModel().getRows()) { + if (row.isValid()) { + + // can keep this row + frequency.add(row); + } + } + + if (log.isInfoEnabled()) { + log.info("Push back " + frequency.size() + + " frequency to batch " + getModel().getBatch()); + } + + // push back to batch + getModel().getBatch().setFrequency(frequency); + + ui.editBatch(null); + + SwingUtil.getParentContainer(ui, JDialog.class).setVisible(false); + } + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void computeComputedWeight(SpeciesFrequencyRowModel row) { + + if (log.isInfoEnabled()) { + log.info("Will recompute computed weight for frequency: " + row); + } + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIModel.java (from rev 103, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -0,0 +1,174 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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% + */ + +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBatchRowModel, SpeciesFrequencyRowModel, SpeciesFrequencyUIModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_CONFIGURATION_MODE = "configurationMode"; + + public static final String PROPERTY_STEP = "step"; + + private static final String PROPERTY_MIN_STEP = "minStep"; + + private static final String PROPERTY_MAX_STEP = "maxStep"; + + public static final String PROPERTY_CAN_GENERATE = "canGenerate"; + + public static final String PROPERTY_SIMPLE_MODE = "simpleMode"; + + public static final String PROPERTY_AUTO_GEN_MODE = "autoGenMode"; + + public static final String PROPERTY_RAFALE_MODE = "rafaleMode"; + + public static enum ConfigurationMode { + SIMPLE, + AUTO_GEN, + RAFALE + } + + /** + * Fill mode. + * + * @since 0.2 + */ + protected ConfigurationMode configurationMode; + + /** + * Batch that contains frequencies. + * + * @since 0.2 + */ + protected SpeciesBatchRowModel batch; + + /** + * Default step to increment length step. + * + * @since 0.2 + */ + protected float step; + + /** + * Min step to auto generate length steps. + * + * @since 0.2 + */ + protected Float minStep; + + /** + * Max step to auto generate length steps. + * + * @since 0.2 + */ + protected Float maxStep; + + public SpeciesFrequencyUIModel() { + super(SpeciesBatchRowModel.class, null, null); + } + + public ConfigurationMode getConfigurationMode() { + return configurationMode; + } + + public void setConfigurationMode(ConfigurationMode configurationMode) { + Object oldValue = getConfigurationMode(); + this.configurationMode = configurationMode; + firePropertyChange(PROPERTY_CONFIGURATION_MODE, oldValue, configurationMode); + firePropertyChange(PROPERTY_SIMPLE_MODE, null, isSimpleMode()); + firePropertyChange(PROPERTY_AUTO_GEN_MODE, null, isAutoGenMode()); + firePropertyChange(PROPERTY_RAFALE_MODE, null, isRafaleMode()); + } + + public float getStep() { + return step; + } + + public void setStep(float step) { + Object oldValue = getStep(); + this.step = step; + firePropertyChange(PROPERTY_STEP, oldValue, step); + } + + public Float getMinStep() { + return minStep; + } + + public void setMinStep(Float minStep) { + Object oldValue = getMinStep(); + this.minStep = minStep; + firePropertyChange(PROPERTY_MIN_STEP, oldValue, minStep); + firePropertyChange(PROPERTY_CAN_GENERATE, null, isCanGenerate()); + } + + public Float getMaxStep() { + return maxStep; + } + + public void setMaxStep(Float maxStep) { + Object oldValue = getMaxStep(); + this.maxStep = maxStep; + firePropertyChange(PROPERTY_MAX_STEP, oldValue, maxStep); + firePropertyChange(PROPERTY_CAN_GENERATE, null, isCanGenerate()); + } + + public boolean isSimpleMode() { + return ConfigurationMode.SIMPLE == configurationMode; + } + + public boolean isAutoGenMode() { + return ConfigurationMode.AUTO_GEN == configurationMode; + } + + public boolean isRafaleMode() { + return ConfigurationMode.RAFALE == configurationMode; + } + + public boolean isCanGenerate() { + return minStep != null && maxStep != null && maxStep > minStep; + } + + public SpeciesBatchRowModel getBatch() { + return batch; + } + + public void setBatch(SpeciesBatchRowModel batch) { + this.batch = batch; + } + + public float getLengthStep(float lengthStep) { + int intValue = (int) (lengthStep * 10); + int intStep = (int) (step * 10); + int correctIntStep = intValue - (intValue % intStep); + float result = correctIntStep / 10f; + return result; + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesFrequencyUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchRowModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,138 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.macrowaste; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.MacroWasteBatch; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * Define a benthos batch row. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class MacroWasteBatchRowModel extends AbstractTuttiBeanUIModel<MacroWasteBatch, MacroWasteBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_MACRO_WASTE_CATEGORY = "macroWasteCategory"; - - public static final String PROPERTY_WEIGHT = "weight"; - - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - - /** - * macroWaste category. - * - * @since 0.2 - */ - protected CaracteristicQualitativeValue macroWasteCategory; - - /** - * Observed weight. - * - * @since 0.2 - */ - protected Float weight; - - /** - * Comment on this batch. - * - * @since 0.2 - */ - protected String comment; - - /** - * Attachments. - * - * @since 0.2 - */ - protected List<Attachment> attachments; - - protected static final Binder<MacroWasteBatch, MacroWasteBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(MacroWasteBatch.class, - MacroWasteBatchRowModel.class); - - protected static final Binder<MacroWasteBatchRowModel, MacroWasteBatch> toBeanBinder = - BinderFactory.newBinder(MacroWasteBatchRowModel.class, - MacroWasteBatch.class); - - public MacroWasteBatchRowModel() { - super(MacroWasteBatch.class, fromBeanBinder, toBeanBinder); - } - - public MacroWasteBatchRowModel(MacroWasteBatch aBatch) { - this(); - fromBean(aBatch); - } - - public CaracteristicQualitativeValue getMacroWasteCategory() { - return macroWasteCategory; - } - - public void setMacroWasteCategory(CaracteristicQualitativeValue macroWasteCategory) { - Object oldValue = getMacroWasteCategory(); - this.macroWasteCategory = macroWasteCategory; - firePropertyChange(PROPERTY_MACRO_WASTE_CATEGORY, oldValue, macroWasteCategory); - } - - public Float getWeight() { - return weight; - } - - public void setWeight(Float weight) { - Object oldValue = getWeight(); - this.weight = weight; - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - Object oldValue = getComment(); - this.comment = comment; - firePropertyChange(PROPERTY_COMMENT, oldValue, comment); - } - - public List<Attachment> getAttachments() { - return attachments; - } - - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchTableModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,77 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.macrowaste; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; - -import javax.swing.table.TableColumnModel; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class MacroWasteBatchTableModel extends AbstractTuttiTableModel<MacroWasteBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final ColumnIdentifier<MacroWasteBatchRowModel> MACRO_WASTE_CATEGORY = ColumnIdentifier.newId( - MacroWasteBatchRowModel.PROPERTY_MACRO_WASTE_CATEGORY, - n_("tutti.table.macrowaste.batch.header.macroWasteCategory"), - n_("tutti.table.macrowaste.batch.header.macroWasteCategory")); - - public static final ColumnIdentifier<MacroWasteBatchRowModel> WEIGHT = ColumnIdentifier.newId( - MacroWasteBatchRowModel.PROPERTY_WEIGHT, - n_("tutti.table.macrowaste.batch.header.weight"), - n_("tutti.table.macrowaste.batch.header.weight")); - - public static final ColumnIdentifier<MacroWasteBatchRowModel> COMMENT = ColumnIdentifier.newId( - MacroWasteBatchRowModel.PROPERTY_COMMENT, - n_("tutti.table.macrowaste.batch.header.comment"), - n_("tutti.table.macrowaste.batch.header.comment")); - - public static final ColumnIdentifier<MacroWasteBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - MacroWasteBatchRowModel.PROPERTY_ATTACHMENTS, - n_("tutti.table.macrowaste.batch.header.file"), - n_("tutti.table.macrowaste.batch.header.file")); - - public MacroWasteBatchTableModel(TableColumnModel columnModel) { - super(columnModel); - - setNoneEditableCols(); - } - - @Override - protected MacroWasteBatchRowModel createNewRow() { - MacroWasteBatchRowModel result = new MacroWasteBatchRowModel(); - - // by default empty row is not valid - result.setValid(false); - return result; - } - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.css 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -1,49 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -NumberEditor { - autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; - bean: {model}; - showReset: true; -} - -#macroWasteTotalWeightLabel { - text: "tutti.label.catches.macroWasteTotalWeight"; - labelFor: {macroWasteTotalWeightField}; -} - -#macroWasteTotalWeightField { - property: "macroWasteTotalWeight"; - model: {model.getMacroWasteTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#table { - selectionMode: {ListSelectionModel.SINGLE_SELECTION}; - selectionBackground: {null}; - selectionForeground: {Color.BLACK}; - sortable: false; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -1,95 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<MacroWasteBatchUIModel, MacroWasteBatchUIHandler>'> - - <import> - fr.ifremer.tutti.ui.swing.TuttiUI - fr.ifremer.tutti.ui.swing.TuttiUIContext - - fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI - - jaxx.runtime.swing.editor.NumberEditor - - jaxx.runtime.validator.swing.SwingValidatorUtil - jaxx.runtime.validator.swing.SwingValidatorMessageTableModel - - org.jdesktop.swingx.JXTable - - javax.swing.ListSelectionModel - - java.awt.Color - - static org.nuiton.i18n.I18n._ - </import> - - <script><![CDATA[ - -public MacroWasteBatchUI(TuttiUI<?,?> parentUI) { - JAXXUtil.initContext(this, parentUI); - MacroWasteBatchUIHandler handler = new MacroWasteBatchUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <MacroWasteBatchUIHandler id='handler' - initializer='getContextValue(MacroWasteBatchUIHandler.class)'/> - - <MacroWasteBatchUIModel id='model' - initializer='getContextValue(MacroWasteBatchUIModel.class)'/> - - <SwingValidatorMessageTableModel id='errorTableModel'/> - - <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' - uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='macroWasteTotalWeight' component='macroWasteTotalWeightField'/> - </BeanValidator> - - <LongTextEditorUI id='longTextEditor'/> - - <AttachmentEditorUI id='attachmentEditor'/> - - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> - - <!-- Poids total --> - <row> - <cell anchor='west'> - <JLabel id='macroWasteTotalWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='macroWasteTotalWeightField' constructorParams='this'/> - </cell> - </row> - </Table> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JXTable id='table' - onFocusLost='handler.saveSelectedRowIfRequired(event);'/> - </JScrollPane> - -</JPanel> \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,353 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.macrowaste; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.MacroWasteBatch; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; -import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.table.TableColumnModel; -import java.util.List; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class MacroWasteBatchUIHandler extends AbstractTuttiBatchTableUIHandler<MacroWasteBatchRowModel, MacroWasteBatchUIModel> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(MacroWasteBatchUIHandler.class); - - /** - * UI. - * - * @since 0.2 - */ - private final MacroWasteBatchUI ui; - - public MacroWasteBatchUIHandler(TuttiUI<?, ?> parentUi, MacroWasteBatchUI ui) { - super(parentUi, - MacroWasteBatchRowModel.PROPERTY_MACRO_WASTE_CATEGORY, - MacroWasteBatchRowModel.PROPERTY_WEIGHT, - MacroWasteBatchRowModel.PROPERTY_COMMENT); - this.ui = ui; - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - protected MacroWasteBatchUIModel getModel() { - return ui.getModel(); - } - - @Override - protected MacroWasteBatchTableModel getTableModel() { - return (MacroWasteBatchTableModel) getTable().getModel(); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - { - // MacroWaste Category column - - Decorator<CaracteristicQualitativeValue> decorator = getDecorator( - CaracteristicQualitativeValue.class, null); - - addComboDataColumnToModel(columnModel, - MacroWasteBatchTableModel.MACRO_WASTE_CATEGORY, - decorator, persistenceService.getMacroWasteCategoryCaracteristic().getQualitativeValue()); - } - - { // Weight column - - addFloatColumnToModel(columnModel, - MacroWasteBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Comment column - - addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), - MacroWasteBatchTableModel.COMMENT); - } - - { // File column - - addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - MacroWasteBatchTableModel.ATTACHMENTS); - } - return columnModel; - } - - @Override - protected void onRowModified(MacroWasteBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - - boolean wasValid = row.isValid(); - - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); - } - row.setValid(valid); - } - - @Override - protected void onRowValidStateChanged(MacroWasteBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); - - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - - @Override - protected void onRowModifyStateChanged(MacroWasteBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onModelRowsChanged(List<MacroWasteBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (MacroWasteBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } - } - - @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<MacroWasteBatchRowModel> rowMonitor = getRowMonitor(); - - MacroWasteBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - MacroWasteBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteMacroWasteBatch(catchBean.getId()); - } - } - } - } - - @Override - protected boolean isRowValid(MacroWasteBatchRowModel row) { - boolean result = row.getMacroWasteCategory() != null && - row.getWeight() != null; - return result; - } - - @Override - protected void saveRow(MacroWasteBatchRowModel row) { - - MacroWasteBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createMacroWasteBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.saveMacroWasteBatch(catchBean); - } - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - JXTable table = getTable(); - - if (table.isEditing()) { - - // make sure to stop editor - table.editingCanceled(null); - } - - // make sure selection is empty (will remove bean from monitor) - table.clearSelection(); - - boolean empty = bean == null; - - MacroWasteBatchUIModel model = getModel(); - - List<MacroWasteBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get species batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<MacroWasteBatch> catches = - persistenceService.getAllMacroWasteBatch(bean.getId()); - for (MacroWasteBatch aBatch : catches) { - MacroWasteBatchRowModel entry = - new MacroWasteBatchRowModel(aBatch); - rows.add(entry); - } - } - } - - model.setRows(rows); - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInitUI() { - - if (log.isInfoEnabled()) { - log.info("beforeInit: " + ui); - } - - EditCatchesUIModel catchesUIModel = - ui.getContextValue(EditCatchesUIModel.class); - - MacroWasteBatchUIModel model = new MacroWasteBatchUIModel(catchesUIModel); - ui.setContextValue(model); - } - - @Override - public void afterInitUI() { - - if (log.isInfoEnabled()) { - log.info("afterInit: " + ui); - } - - initUI(ui); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - // create table model - MacroWasteBatchTableModel tableModel = - new MacroWasteBatchTableModel(columnModel); - - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initBatchTable(table, columnModel, tableModel); - } - - @Override - public void onCloseUI() { - if (log.isInfoEnabled()) { - log.info("closing: " + ui); - } - } - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/macrowaste/MacroWasteBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,50 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.macrowaste; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class MacroWasteBatchUIModel extends AbstractTuttiBatchUIModel<MacroWasteBatchRowModel, MacroWasteBatchUIModel> { - - private static final long serialVersionUID = 1L; - - public MacroWasteBatchUIModel(EditCatchesUIModel catchesUIModel) { - super(catchesUIModel, - EditCatchesUIModel.PROPERTY_MACRO_WASTE_TOTAL_WEIGHT); - } - - public Float getMacroWasteTotalWeight() { - return catchesUIModel.getMacroWasteTotalWeight(); - } - - public void setMacroWasteTotalWeight(Float macroWasteTotalWeight) { - catchesUIModel.setMacroWasteTotalWeight(macroWasteTotalWeight); - } -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchRowModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,195 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.plankton; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * Define a benthos batch row. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class PlanktonBatchRowModel extends AbstractTuttiBeanUIModel<PlanktonBatch, PlanktonBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_SPECIES = "species"; - - public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; - - public static final String PROPERTY_WEIGHT = "weight"; - - public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; - - public static final String PROPERTY_SAMPLING_RATIO = "samplingRatio"; - - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - - /** - * Species observed. - * - * @since 0.2 - */ - protected Species species; - - /** - * Is the species need to be confirmed?. - * - * @since 0.2 - */ - protected boolean speciesToConfirm; - - /** - * Observed weight. - * - * @since 0.2 - */ - protected Float weight; - - /** - * Sample weight. - * - * @since 0.2 - */ - protected Float sampleWeight; - - /** - * Sampling ratio. - * - * @since 0.2 - */ - protected Float samplingRatio; - - /** - * Comment on this catches. - * - * @since 0.2 - */ - protected String comment; - - /** - * Attachments - * - * @since 0.2 - */ - protected List<Attachment> attachments; - - protected static final Binder<PlanktonBatch, PlanktonBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(PlanktonBatch.class, - PlanktonBatchRowModel.class); - - protected static final Binder<PlanktonBatchRowModel, PlanktonBatch> toBeanBinder = - BinderFactory.newBinder(PlanktonBatchRowModel.class, - PlanktonBatch.class); - - public PlanktonBatchRowModel() { - super(PlanktonBatch.class, fromBeanBinder, toBeanBinder); - } - - public PlanktonBatchRowModel(PlanktonBatch aBatch) { - this(); - fromBean(aBatch); - } - - public Species getSpecies() { - return species; - } - - public void setSpecies(Species species) { - Object oldValue = getSpecies(); - this.species = species; - firePropertyChange(PROPERTY_SPECIES, oldValue, species); - } - - public Boolean getSpeciesToConfirm() { - return speciesToConfirm; - } - - public void setSpeciesToConfirm(Boolean speciesToConfirm) { - Object oldValue = getSpeciesToConfirm(); - this.speciesToConfirm = speciesToConfirm; - firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); - } - - public Float getWeight() { - return weight; - } - - public void setWeight(Float weight) { - Object oldValue = getWeight(); - this.weight = weight; - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); - } - - public Float getSampleWeight() { - return sampleWeight; - } - - public void setSampleWeight(Float sampleWeight) { - Object oldValue = getSampleWeight(); - this.sampleWeight = sampleWeight; - firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); - } - - public Float getSamplingRatio() { - return samplingRatio; - } - - public void setSamplingRatio(Float samplingRatio) { - Object oldValue = getSamplingRatio(); - this.samplingRatio = samplingRatio; - firePropertyChange(PROPERTY_SAMPLING_RATIO, oldValue, samplingRatio); - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - Object oldValue = getComment(); - this.comment = comment; - firePropertyChange(PROPERTY_COMMENT, oldValue, comment); - } - - public List<Attachment> getAttachments() { - return attachments; - } - - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchTableModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,117 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.plankton; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; - -import javax.swing.table.TableColumnModel; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class PlanktonBatchTableModel extends AbstractTuttiTableModel<PlanktonBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final ColumnIdentifier<PlanktonBatchRowModel> SPECIES_TO_CONFIRM = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - n_("tutti.table.plankton.batch.header.toConfirm"), - n_("tutti.table.plankton.batch.header.toConfirm")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.plankton.batch.header.speciesByCode"), - n_("tutti.table.plankton.batch.header.speciesByCode")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.plankton.batch.header.speciesByGenusCode"), - n_("tutti.table.plankton.batch.header.speciesByGenusCode")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> WEIGHT = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_WEIGHT, - n_("tutti.table.plankton.batch.header.weight"), - n_("tutti.table.plankton.batch.header.weight")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> SAMPLE_WEIGHT = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - n_("tutti.table.plankton.batch.header.sampleWeight"), - n_("tutti.table.plankton.batch.header.sampleWeight")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> SAMPLING_RATIO = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_SAMPLING_RATIO, - n_("tutti.table.plankton.batch.header.elevationRate"), - n_("tutti.table.plankton.batch.header.elevationRate")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> COMMENT = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_COMMENT, - n_("tutti.table.plankton.batch.header.comment"), - n_("tutti.table.plankton.batch.header.comment")); - - public static final ColumnIdentifier<PlanktonBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_ATTACHMENTS, - n_("tutti.table.plankton.batch.header.file"), - n_("tutti.table.plankton.batch.header.file")); - - public PlanktonBatchTableModel(TableColumnModel columnModel) { - super(columnModel); - - setNoneEditableCols(SAMPLE_WEIGHT, SAMPLING_RATIO); - } - - @Override - protected PlanktonBatchRowModel createNewRow() { - PlanktonBatchRowModel result = new PlanktonBatchRowModel(); - - // by default empty row is not valid - result.setValid(false); - return result; - } - - @Override - public void setValueAt(Object aValue, - int rowIndex, - int columnIndex, - ColumnIdentifier<PlanktonBatchRowModel> propertyName, - PlanktonBatchRowModel entry) { - super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); - - if (propertyName == SPECIES_BY_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, SPECIES_BY_GENUS_CODE); - - } else if (propertyName == SPECIES_BY_GENUS_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, SPECIES_BY_CODE); - } - } - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.css 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -1,61 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -NumberEditor { - autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; - bean: {model}; - showReset: true; -} - -#planktonTotalWeightLabel { - text: "tutti.label.catches.planktonTotalWeight"; - labelFor: {planktonTotalWeightField}; -} - -#planktonTotalWeightField { - property: "planktonTotalWeight"; - model: {model.getPlanktonTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#planktonTotalSampleWeightLabel { - text: "tutti.label.catches.planktonTotalSampleWeight"; - labelFor: {planktonTotalSampleWeightField}; -} - -#planktonTotalSampleWeightField { - property: "planktonTotalSampleWeight"; - model: {model.getPlanktonTotalSampleWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#table { - selectionMode: {ListSelectionModel.SINGLE_SELECTION}; - selectionBackground: {null}; - selectionForeground: {Color.BLACK}; - sortable: false; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -1,107 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<PlanktonBatchUIModel, PlanktonBatchUIHandler>'> - - <import> - fr.ifremer.tutti.ui.swing.TuttiUI - fr.ifremer.tutti.ui.swing.TuttiUIContext - fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI - - jaxx.runtime.swing.editor.NumberEditor - - jaxx.runtime.validator.swing.SwingValidatorUtil - jaxx.runtime.validator.swing.SwingValidatorMessageTableModel - - org.jdesktop.swingx.JXTable - - javax.swing.ListSelectionModel - - java.awt.Color - - static org.nuiton.i18n.I18n._ - </import> - - <script><![CDATA[ - -public PlanktonBatchUI(TuttiUI<?,?> parentUI) { - JAXXUtil.initContext(this, parentUI); - PlanktonBatchUIHandler handler = new PlanktonBatchUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <PlanktonBatchUIHandler id='handler' - initializer='getContextValue(PlanktonBatchUIHandler.class)'/> - - <PlanktonBatchUIModel id='model' - initializer='getContextValue(PlanktonBatchUIModel.class)'/> - - <SwingValidatorMessageTableModel id='errorTableModel'/> - - <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' - uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='planktonTotalWeight' component='planktonTotalWeightField'/> - <field name='planktonTotalSampleWeight' - component='planktonTotalSampleWeightField'/> - </BeanValidator> - - <LongTextEditorUI id='longTextEditor'/> - - <AttachmentEditorUI id='attachmentEditor'/> - - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> - - <!-- Poids total --> - <row> - <cell anchor='west'> - <JLabel id='planktonTotalWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='planktonTotalWeightField' constructorParams='this'/> - </cell> - </row> - - <!-- Poids total échantillonné --> - <row> - <cell> - <JLabel id='planktonTotalSampleWeightLabel'/> - </cell> - <cell> - <NumberEditor id='planktonTotalSampleWeightField' - constructorParams='this'/> - </cell> - </row> - </Table> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JXTable id='table' - onFocusLost='handler.saveSelectedRowIfRequired(event);'/> - </JScrollPane> - -</JPanel> \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,397 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.plankton; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; -import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.table.TableColumnModel; -import java.util.List; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class PlanktonBatchUIHandler extends AbstractTuttiBatchTableUIHandler<PlanktonBatchRowModel, PlanktonBatchUIModel> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(PlanktonBatchUIHandler.class); - - /** - * UI. - * - * @since 0.2 - */ - private final PlanktonBatchUI ui; - - public PlanktonBatchUIHandler(TuttiUI<?, ?> parentUi, PlanktonBatchUI ui) { - super(parentUi, - PlanktonBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - PlanktonBatchRowModel.PROPERTY_SPECIES, - PlanktonBatchRowModel.PROPERTY_WEIGHT, - PlanktonBatchRowModel.PROPERTY_COMMENT); - this.ui = ui; - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - protected PlanktonBatchUIModel getModel() { - return ui.getModel(); - } - - @Override - protected PlanktonBatchTableModel getTableModel() { - return (PlanktonBatchTableModel) getTable().getModel(); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } - - @Override - protected String[] getRowPropertiesToIgnore() { - return new String[]{ - PlanktonBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - PlanktonBatchRowModel.PROPERTY_SAMPLING_RATIO - }; - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - { - // Species to confirm column - - addBooleanColumnToModel(columnModel, - PlanktonBatchTableModel.SPECIES_TO_CONFIRM, - getTable()); - } - - List<Species> allSpecies = persistenceService.getAllSpecies(); - - { - // Species (by code) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_CODE); - - addComboDataColumnToModel(columnModel, - PlanktonBatchTableModel.SPECIES_BY_CODE, - decorator, allSpecies); - } - - { - // Species (by genusCode) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_GENUS); - - addComboDataColumnToModel(columnModel, - PlanktonBatchTableModel.SPECIES_BY_GENUS_CODE, - decorator, allSpecies); - - } - - { // Weight column - - addFloatColumnToModel(columnModel, - PlanktonBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Sample weight column - - addColumnToModel(columnModel, - PlanktonBatchTableModel.SAMPLE_WEIGHT); - } - - { // SamplingRatio column - - addColumnToModel(columnModel, - PlanktonBatchTableModel.SAMPLING_RATIO); - } - - { // Comment column - - addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), - PlanktonBatchTableModel.COMMENT); - } - - { // File column - - addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - PlanktonBatchTableModel.ATTACHMENTS); - } - return columnModel; - } - - @Override - protected void onRowModified(PlanktonBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - - boolean wasValid = row.isValid(); - - boolean valid = isRowValid(row); - - if (log.isInfoEnabled()) { - log.info("Was valid / Is valid: " + wasValid + " / " + valid); - } - row.setValid(valid); - } - - @Override - protected void onRowValidStateChanged(PlanktonBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); - - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - - @Override - protected void onRowModifyStateChanged(PlanktonBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onModelRowsChanged(List<PlanktonBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // set valid flag - for (PlanktonBatchRowModel row : rows) { - boolean valid = isRowValid(row); - row.setValid(valid); - } - } - - @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<PlanktonBatchRowModel> rowMonitor = getRowMonitor(); - - PlanktonBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - PlanktonBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deletePlanktonBatch(catchBean.getId()); - } - } - } - } - - @Override - protected boolean isRowValid(PlanktonBatchRowModel row) { - boolean result = row.getSpecies() != null && row.getWeight() != null; - return result; - } - - @Override - protected void saveRow(PlanktonBatchRowModel row) { - - PlanktonBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createPlanktonBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.savePlanktonBatch(catchBean); - } - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - JXTable table = getTable(); - - if (table.isEditing()) { - - // make sure to stop editor - table.editingCanceled(null); - } - - // make sure selection is empty (will remove bean from monitor) - table.clearSelection(); - - boolean empty = bean == null; - - PlanktonBatchUIModel model = getModel(); - - List<PlanktonBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - - if (log.isInfoEnabled()) { - log.info("Get species batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<PlanktonBatch> catches = - persistenceService.getAllPlanktonBatch(bean.getId()); - for (PlanktonBatch aBatch : catches) { - PlanktonBatchRowModel entry = - new PlanktonBatchRowModel(aBatch); - rows.add(entry); - } - } - } - - model.setRows(rows); - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInitUI() { - - if (log.isInfoEnabled()) { - log.info("beforeInit: " + ui); - } - - EditCatchesUIModel catchesUIModel = - ui.getContextValue(EditCatchesUIModel.class); - - PlanktonBatchUIModel model = new PlanktonBatchUIModel(catchesUIModel); - ui.setContextValue(model); - } - - @Override - public void afterInitUI() { - - if (log.isInfoEnabled()) { - log.info("afterInit: " + ui); - } - - initUI(ui); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - // create table model - PlanktonBatchTableModel tableModel = - new PlanktonBatchTableModel(columnModel); - - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initBatchTable(table, columnModel, tableModel); - } - - @Override - public void onCloseUI() { - if (log.isInfoEnabled()) { - log.info("closing: " + ui); - } - } - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/plankton/PlanktonBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,59 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.plankton; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class PlanktonBatchUIModel extends AbstractTuttiBatchUIModel<PlanktonBatchRowModel, PlanktonBatchUIModel> { - - private static final long serialVersionUID = 1L; - - public PlanktonBatchUIModel(EditCatchesUIModel catchesUIModel) { - super(catchesUIModel, - EditCatchesUIModel.PROPERTY_PLANKTON_TOTAL_WEIGHT, - EditCatchesUIModel.PROPERTY_PLANKTON_TOTAL_SAMPLE_WEIGHT); - } - - public Float getPlanktonTotalWeight() { - return catchesUIModel.getPlanktonTotalWeight(); - } - - public void setPlanktonTotalWeight(Float planktonTotalWeight) { - catchesUIModel.setPlanktonTotalWeight(planktonTotalWeight); - } - - public Float getPlanktonTotalSampleWeight() { - return catchesUIModel.getPlanktonTotalSampleWeight(); - } - - public void setPlanktonTotalSampleWeight(Float planktonTotalSampleWeight) { - catchesUIModel.setPlanktonTotalSampleWeight(planktonTotalSampleWeight); - } -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,257 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.base.Preconditions; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; -import jaxx.runtime.SwingUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.AbstractCellEditor; -import javax.swing.JButton; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import java.awt.Color; -import java.awt.Component; -import java.awt.Frame; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import static org.nuiton.i18n.I18n._; - -/** - * Component to render and edit frequency stuff from batch table. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class FrequencyCellComponent extends JButton { - - private static final long serialVersionUID = 1L; - - public static final String ROW_INDEX = "rowIndex"; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(FrequencyCellComponent.class); - - public FrequencyCellComponent() { - setContentAreaFilled(false); - setOpaque(false); - setIcon(SwingUtil.createActionIcon("show-frequency")); - } - - public static TableCellRenderer newRender() { - return new FrequencyCellRenderer(); - } - - public static TableCellEditor newEditor(SpeciesFrequencyUI ui) { - return new FrequencyCellEditor(ui); - } - - public static class FrequencyCellEditor extends AbstractCellEditor implements TableCellEditor { - - private static final long serialVersionUID = 1L; - - protected final FrequencyCellComponent component; - - protected final SpeciesFrequencyUI ui; - - protected Frame frame; - - protected JTable table; - - protected SpeciesBatchTableModel tableModel; - - protected ColumnIdentifier<SpeciesBatchRowModel> columnIdentifier; - - protected SpeciesBatchRowModel editRow; - - protected Integer rowIndex; - - protected Integer columnIndex; - - public FrequencyCellEditor(SpeciesFrequencyUI ui) { - this.ui = ui; - component = new FrequencyCellComponent(); - component.setBorder(new LineBorder(Color.BLACK)); - component.addKeyListener(new KeyAdapter() { - @Override - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER || - e.getKeyCode() == KeyEvent.VK_SPACE) { - e.consume(); - startEdit(); - } - } - }); - - component.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - e.consume(); - startEdit(); - } - }); - } - - protected void startEdit() { - - Preconditions.checkNotNull(tableModel, "No table model assigned."); - - // open frequency dialog - - Preconditions.checkNotNull(editRow, "No editRow found."); - - if (log.isInfoEnabled()) { - log.info("Will edit frequencies for row: " + rowIndex); - } - - if (frame == null) { - frame = SwingUtil.getParentContainer(ui, Frame.class); - } - - ui.editBatch(editRow); - - // open frequency dialog - TuttiUIUtil.openInDialog( - ui, frame, _("tutti.title.frequency"), true, null); - - // at close, synch back frequencies - - editRow.updateTotalFromFrequencies(); - - int r = rowIndex; - int c = columnIndex; - - // stop edition - stopCellEditing(); - - // reselect this cell - AbstractSelectTableAction.doSelectCell(table, r, c); - table.requestFocus(); - } - - @Override - public Component getTableCellEditorComponent(JTable table, - Object value, - boolean isSelected, - int row, - int column) { - if (tableModel == null) { - tableModel = (SpeciesBatchTableModel) table.getModel(); - this.table = table; - columnIdentifier = tableModel.getPropertyName(column); - } - String text; - if (value == null) { - text = " - "; - } else { - text = String.valueOf(value); - } - component.setText(text); - - rowIndex = row; - columnIndex = column; - - editRow = tableModel.getEntry(row); - - return component; - } - - @Override - public Object getCellEditorValue() { - - Preconditions.checkNotNull(editRow, "No editRow found in editor."); - - Object result; - if (columnIdentifier == SpeciesBatchTableModel.COMPUTED_NUMBER) { - result = editRow.getComputedNumber(); - } else { - result = editRow.getComputedWeight(); - } - if (log.isInfoEnabled()) { - log.info("editor value (" + columnIdentifier + "): " + result); - } - - return result; - } - - @Override - public boolean stopCellEditing() { - boolean b = super.stopCellEditing(); - if (b) { - rowIndex = null; - editRow = null; - columnIndex = null; - } - return b; - } - - @Override - public void cancelCellEditing() { - super.cancelCellEditing(); - rowIndex = null; - columnIndex = null; - editRow = null; - } - } - - public static class FrequencyCellRenderer implements TableCellRenderer { - - protected final FrequencyCellComponent component; - - public FrequencyCellRenderer() { - component = new FrequencyCellComponent(); - } - - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - - String text; - if (value == null) { - text = " - "; - } else { - text = String.valueOf(value); - } - boolean editable = table.isCellEditable(row, column); - component.setEnabled(editable); - component.setText(text); - return component; - } - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,390 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import org.apache.commons.collections.CollectionUtils; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.Collections; -import java.util.List; - -/** - * Represents a species batch (i.e a row in the batch table). - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, SpeciesBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_SPECIES = "species"; - - public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; - - public static final String PROPERTY_SORTED_UNSORTED_CATEGORY = "sortedUnsortedCategory"; - - public static final String PROPERTY_SIZE_CATEGORY = "sizeCategory"; - - public static final String PROPERTY_SEX_CATEGORY = "sexCategory"; - - public static final String PROPERTY_MATURITY_CATEGORY = "maturityCategory"; - - public static final String PROPERTY_AGE = "age"; - - public static final String PROPERTY_WEIGHT = "weight"; - - public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; - - public static final String PROPERTY_SAMPLING_RATIO = "samplingRatio"; - - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_FREQUENCY = "frequency"; - - public static final String PROPERTY_COMPUTED_NUMBER = "computedNumber"; - - public static final String PROPERTY_COMPUTED_WEIGHT = "computedWeight"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - - /** - * Species observed. - * - * @since 0.2 - */ - protected Species species; - - /** - * Is the species need to be confirmed?. - * - * @since 0.2 - */ - protected boolean speciesToConfirm; - - /** - * Is catch is vrac or horsVrac?. - * - * @since 0.2 - */ - protected CaracteristicQualitativeValue sortedUnsortedCategory; - - /** - * Weight category (can be null). - * - * @since 0.2 - */ - protected CaracteristicQualitativeValue sizeCategory; - - /** - * Sex (can be null). - * - * @since 0.2 - */ - protected CaracteristicQualitativeValue sexCategory; - - /** - * Maturity (can be null). - * - * @since 0.2 - */ - protected CaracteristicQualitativeValue maturityCategory; - - /** - * Age (can be null). - * - * @since 0.2 - */ - protected Float age; - - /** - * Observed weight. - * - * @since 0.2 - */ - protected Float weight; - - /** - * Total computed weight (from frequencies). - * - * @since 0.2 - */ - protected Float computedWeight; - - /** - * Total computed number (from frequencies). - * - * @since 0.2 - */ - protected Float computedNumber; - - /** - * Sample weight. - * - * @since 0.2 - */ - protected Float sampleWeight; - - /** - * Sampling ratio. - * - * @since 0.2 - */ - protected Float samplingRatio; - - /** - * Comment on this catches. - * - * @since 0.2 - */ - protected String comment; - - /** - * Attachments - * - * @since 0.2 - */ - protected List<Attachment> attachments; - - /** - * List of frequencies observed for this batch. - * - * @since 0.2 - */ - protected List<SpeciesFrequencyRowModel> frequency; - - protected static final Binder<SpeciesBatch, SpeciesBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(SpeciesBatch.class, - SpeciesBatchRowModel.class); - - protected static final Binder<SpeciesBatchRowModel, SpeciesBatch> toBeanBinder = - BinderFactory.newBinder(SpeciesBatchRowModel.class, - SpeciesBatch.class); - - public SpeciesBatchRowModel() { - super(SpeciesBatch.class, fromBeanBinder, toBeanBinder); - frequency = Lists.newArrayList(); - } - - public SpeciesBatchRowModel(SpeciesBatch aBatch, - List<SpeciesBatchFrequency> frequencies) { - this(); - fromBean(aBatch); - List<SpeciesFrequencyRowModel> frequencyRows = - SpeciesFrequencyRowModel.fromBeans(frequencies); - frequency.addAll(frequencyRows); - Collections.sort(frequency); - updateTotalFromFrequencies(); - } - - public void updateTotalFromFrequencies() { - Float totalNumber = null; - Float totalWeight = null; - if (CollectionUtils.isNotEmpty(frequency)) { - totalNumber = 0f; - totalWeight = 0f; - for (SpeciesFrequencyRowModel frequencyModel : frequency) { - totalNumber += frequencyModel.getNumber(); - Float w = frequencyModel.getWeight(); - if (w == null) { - - // can't sum when a null value appears - totalWeight = null; - } else if (totalWeight != null) { - - // still can sum weights - totalWeight += w; - } - } - } - - setComputedNumber(totalNumber); - setComputedWeight(totalWeight); - } - - public Species getSpecies() { - return species; - } - - public void setSpecies(Species species) { - Object oldValue = getSpecies(); - this.species = species; - firePropertyChange(PROPERTY_SPECIES, oldValue, species); - } - - public Boolean getSpeciesToConfirm() { - return speciesToConfirm; - } - - public void setSpeciesToConfirm(Boolean speciesToConfirm) { - Object oldValue = getSpeciesToConfirm(); - this.speciesToConfirm = speciesToConfirm; - firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); - } - - public CaracteristicQualitativeValue getSortedUnsortedCategory() { - return sortedUnsortedCategory; - } - - public void setSortedUnsortedCategory(CaracteristicQualitativeValue sortedUnsortedCategory) { - Object oldValue = getSortedUnsortedCategory(); - this.sortedUnsortedCategory = sortedUnsortedCategory; - firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY, oldValue, sortedUnsortedCategory); - } - - public CaracteristicQualitativeValue getSizeCategory() { - return sizeCategory; - } - - public void setSizeCategory(CaracteristicQualitativeValue sizeCategory) { - Object oldValue = getSizeCategory(); - this.sizeCategory = sizeCategory; - firePropertyChange(PROPERTY_SIZE_CATEGORY, oldValue, sizeCategory); - } - - public CaracteristicQualitativeValue getSexCategory() { - return sexCategory; - } - - public void setSexCategory(CaracteristicQualitativeValue sexCategory) { - Object oldValue = getSexCategory(); - this.sexCategory = sexCategory; - firePropertyChange(PROPERTY_SEX_CATEGORY, oldValue, sexCategory); - } - - public CaracteristicQualitativeValue getMaturityCategory() { - return maturityCategory; - } - - public void setMaturityCategory(CaracteristicQualitativeValue maturityCategory) { - Object oldValue = getMaturityCategory(); - this.maturityCategory = maturityCategory; - firePropertyChange(PROPERTY_MATURITY_CATEGORY, oldValue, maturityCategory); - } - - public Float getAge() { - return age; - } - - public void setAge(Float age) { - Object oldValue = getAge(); - this.age = age; - firePropertyChange(PROPERTY_AGE, oldValue, age); - } - - public Float getWeight() { - return weight; - } - - public void setWeight(Float weight) { - Object oldValue = getWeight(); - this.weight = weight; - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); - } - - public Float getSampleWeight() { - return sampleWeight; - } - - public void setSampleWeight(Float sampleWeight) { - Object oldValue = getSampleWeight(); - this.sampleWeight = sampleWeight; - firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); - } - - public Float getSamplingRatio() { - return samplingRatio; - } - - public void setSamplingRatio(Float samplingRatio) { - Object oldValue = getSamplingRatio(); - this.samplingRatio = samplingRatio; - firePropertyChange(PROPERTY_SAMPLING_RATIO, oldValue, samplingRatio); - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - Object oldValue = getComment(); - this.comment = comment; - firePropertyChange(PROPERTY_COMMENT, oldValue, comment); - } - - public List<Attachment> getAttachments() { - return attachments; - } - - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); - } - - public List<SpeciesFrequencyRowModel> getFrequency() { - return frequency; - } - - public void setFrequency(List<SpeciesFrequencyRowModel> frequency) { - Object oldValue = getFrequency(); - this.frequency = frequency; - firePropertyChange(PROPERTY_FREQUENCY, oldValue, frequency); - } - - public Float getComputedWeight() { - return computedWeight; - } - - public void setComputedWeight(Float computedWeight) { - Object oldValue = getComputedWeight(); - this.computedWeight = computedWeight; - firePropertyChange(PROPERTY_COMPUTED_WEIGHT, oldValue, - computedWeight); - } - - public Float getComputedNumber() { - return computedNumber; - } - - public void setComputedNumber(Float computedNumber) { - Object oldValue = getComputedNumber(); - this.computedNumber = computedNumber; - firePropertyChange(PROPERTY_COMPUTED_NUMBER, oldValue, - computedNumber); - } - - public int getRowCount() { - return frequency == null ? 0 : frequency.size(); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,202 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Sets; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; - -import javax.swing.table.TableColumnModel; -import java.util.Set; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesBatchTableModel extends AbstractTuttiTableModel<SpeciesBatchRowModel> { - - private static final long serialVersionUID = 1L; - - public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES_BY_CODE = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.species.batch.header.speciesByCode"), - n_("tutti.table.species.batch.header.speciesByCode")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES_BY_GENUS_CODE = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SPECIES, - n_("tutti.table.species.batch.header.speciesByGenusCode"), - n_("tutti.table.species.batch.header.speciesByGenusCode")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SORTED_UNSORTED_CATEGORY = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, - n_("tutti.table.species.batch.header.sortedUnsortedCategory"), - n_("tutti.table.species.batch.header.sortedUnsortedCategory")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SIZE_CATEGORY = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, - n_("tutti.table.species.batch.header.sizeCategory"), - n_("tutti.table.species.batch.header.sizeCategory")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SEX_CATEGORY = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, - n_("tutti.table.species.batch.header.sexCategory"), - n_("tutti.table.species.batch.header.sexCategory")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> MATURITY_CATEGORY = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, - n_("tutti.table.species.batch.header.maturityCategory"), - n_("tutti.table.species.batch.header.maturityCategory")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> AGE = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_AGE, - n_("tutti.table.species.batch.header.age"), - n_("tutti.table.species.batch.header.age")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> WEIGHT = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_WEIGHT, - n_("tutti.table.species.batch.header.weight"), - n_("tutti.table.species.batch.header.weight")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> COMPUTED_WEIGHT = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_COMPUTED_WEIGHT, - n_("tutti.table.species.batch.header.computedWeight"), - n_("tutti.table.species.batch.header.computedWeight")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> COMPUTED_NUMBER = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_COMPUTED_NUMBER, - n_("tutti.table.species.batch.header.computedNumber"), - n_("tutti.table.species.batch.header.computedNumber")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SAMPLE_WEIGHT = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - n_("tutti.table.species.batch.header.sampleWeight"), - n_("tutti.table.species.batch.header.sampleWeight")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SAMPLING_RATIO = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO, - n_("tutti.table.species.batch.header.elevationRate"), - n_("tutti.table.species.batch.header.elevationRate")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> COMMENT = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_COMMENT, - n_("tutti.table.species.batch.header.comment"), - n_("tutti.table.species.batch.header.comment")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, - n_("tutti.table.species.batch.header.file"), - n_("tutti.table.species.batch.header.file")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES_TO_CONFIRM = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - n_("tutti.table.species.batch.header.toConfirm"), - n_("tutti.table.species.batch.header.toConfirm")); - - protected final Set<ColumnIdentifier<SpeciesBatchRowModel>> noneEditableColIfNoSpecies; - - public SpeciesBatchTableModel(TableColumnModel columnModel) { - super(columnModel); - - setNoneEditableCols(SAMPLE_WEIGHT, SAMPLING_RATIO); - noneEditableColIfNoSpecies = Sets.newHashSet(); - noneEditableColIfNoSpecies.add(COMPUTED_NUMBER); - noneEditableColIfNoSpecies.add(COMPUTED_WEIGHT); - } - - @Override - protected SpeciesBatchRowModel createNewRow() { - SpeciesBatchRowModel result = new SpeciesBatchRowModel(); - - // by default empty row is not valid - result.setValid(false); - return result; - } - - @Override - public void setValueAt(Object aValue, - int rowIndex, - int columnIndex, - ColumnIdentifier<SpeciesBatchRowModel> propertyName, - SpeciesBatchRowModel entry) { - super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); - - if (propertyName == SPECIES_BY_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, - SPECIES_BY_GENUS_CODE, - COMPUTED_NUMBER, - COMPUTED_WEIGHT); - - } else if (propertyName == SPECIES_BY_GENUS_CODE) { - - // update also other columns - fireTableCellUpdated(rowIndex, - SPECIES_BY_CODE, - COMPUTED_NUMBER, - COMPUTED_WEIGHT); - } else if (propertyName == COMPUTED_NUMBER) { - - // update also other columns - fireTableCellUpdated(rowIndex, COMPUTED_WEIGHT); - - } else if (propertyName == COMPUTED_WEIGHT) { - - // update also other columns - fireTableCellUpdated(rowIndex, COMPUTED_NUMBER); - } - } - - public void updateSamplingRatio(Set<SpeciesBatchRowModel> rows) { - for (SpeciesBatchRowModel row : rows) { - int rowIndex = getRows().indexOf(row); - fireTableCellUpdated(rowIndex, SAMPLE_WEIGHT, SAMPLING_RATIO); - } - - - } - - @Override - protected boolean isCellEditable(int rowIndex, - int columnIndex, - ColumnIdentifier<SpeciesBatchRowModel> propertyName) { - - boolean result = super.isCellEditable(rowIndex, - columnIndex, - propertyName); - if (result) { - - if (noneEditableColIfNoSpecies.contains(propertyName)) { - - // must have filled a species to edit this column - SpeciesBatchRowModel entry = getEntry(rowIndex); - result = entry.getSpecies() != null; - } - } - return result; - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,297 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import org.apache.commons.collections.CollectionUtils; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesBatchTreeModel implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Root node (with no sampling on it. - * - * @since 0.2 - */ - protected final SpeciesBatchTreeNode root; - - /** - * Property which are used to sub sampling. - * - * @since 0.2 - */ - protected String[] samplingOrder; - - /** - * Mapping from row to node. - * - * @since 0.2 - */ - protected final Map<SpeciesBatchRowModel, SpeciesBatchTreeNode> rowToNode; - - /** - * Mapping from node to row. - * - * @since 0.2 - */ - protected final Multimap<SpeciesBatchTreeNode, SpeciesBatchRowModel> nodeToRow; - - public SpeciesBatchTreeModel(String... samplingOrder) { - this.samplingOrder = samplingOrder; - root = new SpeciesBatchTreeNode(); - rowToNode = Maps.newHashMap(); - nodeToRow = HashMultimap.create(); - } - - public void populate(List<SpeciesBatchRowModel> rows) { - - clear(); - - for (SpeciesBatchRowModel row : rows) { - - SpeciesBatchTreeNode node = getSamplingNode(row); - - // check if row is valid - boolean rowIsValid = isValid(row, node); - - // set it in row - row.setValid(rowIsValid); - } - } - - public String[] getSamplingOrder() { - return samplingOrder; - } - - public void setSamplingOrder(String... samplingOrder) { - this.samplingOrder = samplingOrder; - clear(); - } - - protected void clear() { - // clear tree representation - root.removeAllChildren(); - - // clear mappings - rowToNode.clear(); - nodeToRow.clear(); - } - - public SpeciesBatchTreeNode removeNodeFromCache(SpeciesBatchRowModel row) { - SpeciesBatchTreeNode result = rowToNode.remove(row); - if (result != null) { - - nodeToRow.remove(result, row); - } - return result; - } - - public SpeciesBatchTreeNode getSamplingNode(SpeciesBatchRowModel row) { - - // search frist in cache - SpeciesBatchTreeNode result = rowToNode.get(row); - - if (result == null) { - - // not in cache must build the path - result = getSamplingNode(root, 0, row); - - if (result == root) { - - // this means an empty row, so no node for it - result = null; - - } else { - - // found a row with a sampling, add it in cache - rowToNode.put(row, result); - nodeToRow.put(result, row); - } - } - return result; - } - - protected SpeciesBatchTreeNode getSamplingNode(SpeciesBatchTreeNode node, - int samplingIndex, - SpeciesBatchRowModel row) { - - String samplingKey = samplingOrder[samplingIndex]; - - Serializable samplingValue = (Serializable) - TuttiUIUtil.getProperty(row, samplingKey); - - SpeciesBatchTreeNode result; - - if (samplingValue == null) { - - // was already on last sampling node - result = node; - } else { - - result = node.getChild(samplingValue); - - if (result == null) { - - // new node, creates it and add it as child of current node - result = new SpeciesBatchTreeNode(samplingKey, samplingValue); - node.add(result); - } - - if (samplingIndex < samplingOrder.length) { - - // can try to find yet another sampling level - result = getSamplingNode(result, samplingIndex + 1, row); - } - } - - return result; - } - - public SamplingContext createSamplingContext(SpeciesBatchTreeNode rootNode) { - - Set<SpeciesBatchRowModel> childRows = Sets.newHashSet(); - - SpeciesBatchRowModel superSamplingRow = getNodeToRow(rootNode); - - float totalWeight = 0f; - for (int i = 0, nbChildren = rootNode.getChildCount(); i < nbChildren; i++) { - SpeciesBatchTreeNode node = rootNode.getChildAt(i); - - SpeciesBatchRowModel row = getNodeToRow(node); - if (row != null) { - CaracteristicQualitativeValue sortedUnsortedCategory = - row.getSortedUnsortedCategory(); - if (sortedUnsortedCategory != null && - "unsorted".equals(sortedUnsortedCategory.getName())) { - - // never take account of a such child - - } else { - - childRows.add(row); - Float weight = row.getWeight(); - if (weight != null) { - totalWeight += weight; - } - } - } - } - SamplingContext result = new SamplingContext(rootNode, - superSamplingRow, - childRows, - totalWeight); - return result; - } - - public SpeciesBatchRowModel getNodeToRow(SpeciesBatchTreeNode node) { - Collection<SpeciesBatchRowModel> rows = nodeToRow.get(node); - - SpeciesBatchRowModel result = null; - if (CollectionUtils.isNotEmpty(rows)) { - for (SpeciesBatchRowModel next : rows) { - if (next.isValid()) { - result = next; - break; - } - } - } - return result; - } - - public boolean isValid(SpeciesBatchRowModel row, SpeciesBatchTreeNode newNode) { - - // row must be on a sampling and having a weight - boolean result = row.getWeight() != null && newNode != null; - - // make sure there is not already another row for this node - if (result && CollectionUtils.size(nodeToRow.get(newNode)) > 1) { - result = false; - } - - return result; - } - - public static class SamplingContext { - - private final SpeciesBatchTreeNode rootNode; - - private final SpeciesBatchRowModel superSamplingRow; - - private final Set<SpeciesBatchRowModel> samplingRows; - - private final float totalWeight; - - public SamplingContext(SpeciesBatchTreeNode rootNode, - SpeciesBatchRowModel superSamplingRow, - Set<SpeciesBatchRowModel> samplingRows, - float totalWeight) { - this.rootNode = rootNode; - this.superSamplingRow = superSamplingRow; - this.samplingRows = samplingRows; - this.totalWeight = totalWeight; - } - - public SpeciesBatchTreeNode getRootNode() { - return rootNode; - } - - public SpeciesBatchRowModel getSuperSamplingRow() { - return superSamplingRow; - } - - public Set<SpeciesBatchRowModel> getSamplingRows() { - return samplingRows; - } - - public float getTotalWeight() { - return totalWeight; - } - - public void applyNewSampleValues(float samplingWeight, - Float samplingRatio) { - - for (SpeciesBatchRowModel row : samplingRows) { - row.setSampleWeight(samplingWeight); - row.setSamplingRatio(samplingRatio); - } - } - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,175 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import org.apache.commons.lang3.ObjectUtils; - -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeNode; -import java.io.Serializable; -import java.util.Arrays; - -/** - * Defines a node of a species catches sampling. - * <p/> - * A path in the tree gives a sampling path. - * <p/> - * UserObject is the {@code samplingValue}. It can be null only on root node. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesBatchTreeNode extends DefaultMutableTreeNode { - - private static final long serialVersionUID = 1L; - - /** - * Property name defining the sampling. - * <p/> - * <strong>Note:</strong> can be null (only for root node). - * - * @since 0.2 - */ - protected final String samplingKey; - - public SpeciesBatchTreeNode() { - this(null, null); - } - - public SpeciesBatchTreeNode(String samplingKey, - Serializable samplingValue) { - this.samplingKey = samplingKey; - setUserObject(samplingValue); - } - - public String getSamplingPropertyKey() { - return samplingKey; - } - - public boolean matchSamplingValue(Serializable value) { - Serializable samplingValue = getUserObject(); - - boolean result = ObjectUtils.equals(value, samplingValue); - return result; - } - - public SpeciesBatchTreeNode getChild(Serializable samplingValue) { - SpeciesBatchTreeNode result = null; - - for (int i = 0, max = getChildCount(); i < max; i++) { - SpeciesBatchTreeNode child = getChildAt(i); - if (child.matchSamplingValue(samplingValue)) { - - // found matching child - result = child; - break; - } - } - return result; - } - - @Override - public Serializable getUserObject() { - return (Serializable) super.getUserObject(); - } - - @Override - public SpeciesBatchTreeNode getChildAt(int index) { - return (SpeciesBatchTreeNode) super.getChildAt(index); - } - - @Override - public SpeciesBatchTreeNode getParent() { - return (SpeciesBatchTreeNode) super.getParent(); - } - - @Override - public SpeciesBatchTreeNode getRoot() { - return (SpeciesBatchTreeNode) super.getRoot(); - } - - @Override - public SpeciesBatchTreeNode getFirstChild() { - return (SpeciesBatchTreeNode) super.getFirstChild(); - } - - @Override - public SpeciesBatchTreeNode getLastChild() { - return (SpeciesBatchTreeNode) super.getLastChild(); - } - - @Override - public SpeciesBatchTreeNode getChildAfter(TreeNode aChild) { - return (SpeciesBatchTreeNode) super.getChildAfter(aChild); - } - - @Override - public SpeciesBatchTreeNode getChildBefore(TreeNode aChild) { - return (SpeciesBatchTreeNode) super.getChildBefore(aChild); - } - - @Override - public SpeciesBatchTreeNode getNextSibling() { - return (SpeciesBatchTreeNode) super.getNextSibling(); - } - - @Override - public SpeciesBatchTreeNode getPreviousSibling() { - return (SpeciesBatchTreeNode) super.getPreviousSibling(); - } - - @Override - public SpeciesBatchTreeNode getFirstLeaf() { - return (SpeciesBatchTreeNode) super.getFirstLeaf(); - } - - @Override - public SpeciesBatchTreeNode getLastLeaf() { - return (SpeciesBatchTreeNode) super.getLastLeaf(); - } - - @Override - public SpeciesBatchTreeNode getNextLeaf() { - return (SpeciesBatchTreeNode) super.getNextLeaf(); - } - - @Override - public SpeciesBatchTreeNode getPreviousLeaf() { - return (SpeciesBatchTreeNode) super.getPreviousLeaf(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SpeciesBatchTreeNode)) return false; - - SpeciesBatchTreeNode that = (SpeciesBatchTreeNode) o; - - Object[] path = getUserObjectPath(); - Object[] path2 = that.getUserObjectPath(); - return Arrays.equals(path, path2); - } - -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.css 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -1,83 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -NumberEditor { - autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; - bean: {model}; - showReset: true; -} - -#speciesTotalWeightLabel { - text: "tutti.label.catches.speciesTotalWeight"; - labelFor: {speciesTotalWeightField}; -} - -#speciesTotalWeightField { - property: "speciesTotalWeight"; - model: {model.getSpeciesTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#speciesTotalSortedWeightLabel { - text: "tutti.label.catches.speciesTotalSortedWeight"; - labelFor: {speciesTotalSortedWeightField}; -} - -#speciesTotalSortedWeightField { - property: "speciesTotalSortedWeight"; - model: {model.getSpeciesTotalSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#speciesTotalSampleSortedWeightLabel { - text: "tutti.label.catches.speciesTotalSampleSortedWeight"; - labelFor: {speciesTotalSampleSortedWeightField}; -} - -#speciesTotalSampleSortedWeightField { - property: "speciesTotalSampleSortedWeight"; - model: {model.getSpeciesTotalSampleSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#speciesTotalUnsortedWeightLabel { - text: "tutti.label.catches.speciesTotalUnsortedWeight"; - labelFor: {speciesTotalUnsortedWeightField}; -} - -#speciesTotalUnsortedWeightField { - text: {getStringValue(model.getSpeciesTotalUnsortedWeight())}; - editable: false; -} - -#table { - selectionMode: {ListSelectionModel.SINGLE_SELECTION}; - selectionBackground: {null}; - selectionForeground: {Color.BLACK}; - sortable: false; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -1,127 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<SpeciesBatchUIModel, SpeciesBatchUIHandler>'> - - <import> - fr.ifremer.tutti.ui.swing.TuttiUI - fr.ifremer.tutti.ui.swing.TuttiUIContext - - fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI - - org.jdesktop.swingx.JXTable - - jaxx.runtime.swing.editor.NumberEditor - - jaxx.runtime.validator.swing.SwingValidatorUtil - jaxx.runtime.validator.swing.SwingValidatorMessageTableModel - - javax.swing.ListSelectionModel - - java.awt.Color - - static org.nuiton.i18n.I18n._ - static jaxx.runtime.SwingUtil.getStringValue - </import> - - <script><![CDATA[ - -public SpeciesBatchUI(TuttiUI<?,?> parentUI) { - JAXXUtil.initContext(this, parentUI); - SpeciesBatchUIHandler handler = new SpeciesBatchUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <SpeciesBatchUIHandler id='handler' - initializer='getContextValue(SpeciesBatchUIHandler.class)'/> - - <SpeciesBatchUIModel id='model' - initializer='getContextValue(SpeciesBatchUIModel.class)'/> - - <SwingValidatorMessageTableModel id='errorTableModel'/> - - <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' - uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='speciesTotalWeight' component='speciesTotalWeightField'/> - <field name='speciesTotalSortedWeight' - component='speciesTotalSortedWeightField'/> - <field name='speciesTotalSampleSortedWeight' - component='speciesTotalSampleSortedWeightField'/> - <field name='speciesTotalUnsortedWeight' - component='speciesTotalUnsortedWeightField'/> - </BeanValidator> - - <SpeciesFrequencyUI id='frequencyEditor' - constructorParams='handler.getContext()'/> - - <LongTextEditorUI id='longTextEditor'/> - - <AttachmentEditorUI id='attachmentEditor'/> - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> - - <!-- Poids total / Poids total vrac --> - <row> - <cell anchor='west'> - <JLabel id='speciesTotalWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='speciesTotalWeightField' constructorParams='this'/> - </cell> - <cell anchor='west'> - <JLabel id='speciesTotalSortedWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='speciesTotalSortedWeightField' - constructorParams='this'/> - </cell> - </row> - - <!-- Poids échantillonné vrac / Poids total hors vrac --> - <row> - <cell> - <JLabel id='speciesTotalSampleSortedWeightLabel'/> - </cell> - <cell> - <NumberEditor id='speciesTotalSampleSortedWeightField' - constructorParams='this'/> - </cell> - <cell> - <JLabel id='speciesTotalUnsortedWeightLabel'/> - </cell> - <cell> - <JTextField id='speciesTotalUnsortedWeightField'/> - </cell> - </row> - </Table> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JXTable id='table' onFocusLost='handler.saveSelectedRowIfRequired(event)'/> - </JScrollPane> - -</JPanel> Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,683 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; -import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.table.DefaultTableColumnModelExt; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.table.TableColumnModel; -import java.util.List; -import java.util.Set; - -import static org.nuiton.i18n.I18n.n_; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<SpeciesBatchRowModel, SpeciesBatchUIModel> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(SpeciesBatchUIHandler.class); - - public static final Set<String> RECOMPUTE_TOTAL_WEIGHT = Sets.newHashSet( - SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, - SpeciesBatchRowModel.PROPERTY_WEIGHT); - - public static final Set<String> SAMPLING_PROPERTIES = Sets.newHashSet( - SpeciesBatchRowModel.PROPERTY_SPECIES, - SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, - SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, - SpeciesBatchRowModel.PROPERTY_AGE); - - /** - * UI. - * - * @since 0.2 - */ - private final SpeciesBatchUI ui; - - public SpeciesBatchUIHandler(TuttiUI<?, ?> parentUi, - SpeciesBatchUI ui) { - super(parentUi, - SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - SpeciesBatchRowModel.PROPERTY_SPECIES, - SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, - SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, - SpeciesBatchRowModel.PROPERTY_AGE, - SpeciesBatchRowModel.PROPERTY_WEIGHT, - SpeciesBatchRowModel.PROPERTY_COMMENT, - SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, - SpeciesBatchRowModel.PROPERTY_FREQUENCY); - this.ui = ui; - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - protected SpeciesBatchUIModel getModel() { - return ui.getModel(); - } - - @Override - protected SpeciesBatchTableModel getTableModel() { - return (SpeciesBatchTableModel) getTable().getModel(); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected FishingOperation getFishingOperation() { - return getModel().getFishingOperation(); - } - - @Override - protected void onModelRowsChanged(List<SpeciesBatchRowModel> rows) { - super.onModelRowsChanged(rows); - - // build the new sampling tree from the new rows to edit - getModel().getSamplingTreeModel().populate(rows); - } - - @Override - protected String[] getRowPropertiesToIgnore() { - return new String[]{ - SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO, - SpeciesBatchRowModel.PROPERTY_FREQUENCY}; - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - Decorator<CaracteristicQualitativeValue> caracteristicDecorator = - getDecorator(CaracteristicQualitativeValue.class, null); - - List<Species> allSpecies = persistenceService.getAllSpecies(); - - { - // Species (by code) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_CODE); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_BY_CODE, - decorator, allSpecies); - } - - { - // Species (by genusCode) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_GENUS); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_BY_GENUS_CODE, - decorator, allSpecies); - - } - - { - - // SortedUnsortedCategory column - - Caracteristic data = - persistenceService.getSortedUnsortedCaracteristic(); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SORTED_UNSORTED_CATEGORY, - caracteristicDecorator, - data.getQualitativeValue()); - } - - { - - // SizeCategory column - - Caracteristic data = - persistenceService.getSizeCategoryCaracteristic(); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SIZE_CATEGORY, - caracteristicDecorator, - data.getQualitativeValue()); - } - - { - - // SexCategory column - - Caracteristic data = persistenceService.getSexCaracteristic(); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SEX_CATEGORY, - caracteristicDecorator, - data.getQualitativeValue()); - } - - { - - // MaturityCategory column - - Caracteristic data = - persistenceService.getMaturityCaracteristic(); - - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.MATURITY_CATEGORY, - caracteristicDecorator, - data.getQualitativeValue()); - } - - { - - // Age column - - addFloatColumnToModel(columnModel, - SpeciesBatchTableModel.AGE, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Weight column - - addFloatColumnToModel(columnModel, - SpeciesBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Computed weight column (from frequencies) - - addColumnToModel(columnModel, - FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), - FrequencyCellComponent.newRender(), - SpeciesBatchTableModel.COMPUTED_WEIGHT); - } - - { // Computed number column (from frequencies) - - addColumnToModel(columnModel, - FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), - FrequencyCellComponent.newRender(), - SpeciesBatchTableModel.COMPUTED_NUMBER); - } - - { // Sample weight column - - addColumnToModel(columnModel, - SpeciesBatchTableModel.SAMPLE_WEIGHT); - } - - { // SamplingRatio column - - addColumnToModel(columnModel, - SpeciesBatchTableModel.SAMPLING_RATIO); - } - - { // Comment column - - addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), - SpeciesBatchTableModel.COMMENT); - } - - { // File column - - addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - SpeciesBatchTableModel.ATTACHMENTS); - } - - { // Species to confirm column - - addBooleanColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_TO_CONFIRM, - getTable()); - } - return columnModel; - } - - @Override - protected void onRowModified(SpeciesBatchRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - - if (RECOMPUTE_TOTAL_WEIGHT.contains(propertyName)) { - - // Need to recompute totalHorsVracWeight - recomputeTotalHorsVrac(); - } - - SpeciesBatchUIModel model = getModel(); - - SpeciesBatchTreeModel samplingTreeModel = model.getSamplingTreeModel(); - - if (SAMPLING_PROPERTIES.contains(propertyName)) { - - // Need to rebuilt this row sampling tree path (and then recompute - // old super - samplingRatio and new super - samplingRatio) - - // old node of the previous sampling def for this row - // and remove it from any cache - SpeciesBatchTreeNode oldNode = samplingTreeModel.removeNodeFromCache(row); - - boolean rowWasValid = row.isValid(); - if (oldNode != null && rowWasValid) { - - // remove this row from his super sampling - recomputeSuperSamplingRatio(samplingTreeModel, oldNode); - } - - // get new sampling node - SpeciesBatchTreeNode newNode = samplingTreeModel.getSamplingNode(row); - - // check this row is valid - boolean rowValid = samplingTreeModel.isValid(row, newNode); - - // push this state back to the row - row.setValid(rowValid); - - if (rowValid) { - - // can add it to his super-sampling - recomputeSuperSamplingRatio(samplingTreeModel, newNode); - } else { - - if (rowWasValid) { - - row.setSampleWeight(null); - row.setSamplingRatio(null); - - getTableModel().updateSamplingRatio(Sets.newHashSet(row)); - } - } - } - - if (SpeciesBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { - - // Need to recompute the super - samplingRatio - - SpeciesBatchTreeNode node = samplingTreeModel.getSamplingNode(row); - - boolean rowWasValid = row.isValid(); - - // check this row is valid - boolean rowValid = samplingTreeModel.isValid(row, node); - - // push this state back to the row - row.setValid(rowValid); - - if (rowValid) { - recomputeSuperSamplingRatio(samplingTreeModel, node); - } else { - if (rowWasValid) { - - // must remove this row from his super-sampling - recomputeSuperSamplingRatio(samplingTreeModel, node); - - row.setSampleWeight(null); - row.setSamplingRatio(null); - - getTableModel().updateSamplingRatio(Sets.newHashSet(row)); - } - } - } - } - - @Override - protected void onRowValidStateChanged(SpeciesBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - int rowIndex = getTableModel().getRowIndex(row); - - if (rowIndex > -1) { - getTableModel().fireTableRowsUpdated(rowIndex, rowIndex); - } - } - - @Override - protected void onRowModifyStateChanged(SpeciesBatchRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void saveSelectedRowIfRequired() { - - TuttiBeanMonitor<SpeciesBatchRowModel> rowMonitor = getRowMonitor(); - - SpeciesBatchRowModel bean = rowMonitor.getBean(); - if (bean != null) { - - if (bean.isValid()) { - // there is a valid bean attached to the monitor - - if (rowMonitor.wasModified()) { - - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + bean + " was modified, will save it"); - } - - saveRow(bean); - - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - // row is not valid can not save it - - SpeciesBatch catchBean = bean.toBean(); - - if (!TuttiEntities.isNew(catchBean)) { - - // remove this - persistenceService.deleteSpeciesBatch(catchBean.getId()); - } - } - } - } - - @Override - protected boolean isRowValid(SpeciesBatchRowModel row) { - - SpeciesBatchUIModel model = getModel(); - - SpeciesBatchTreeModel samplingTreeModel = model.getSamplingTreeModel(); - SpeciesBatchTreeNode node = samplingTreeModel.getSamplingNode(row); - boolean rowValid = samplingTreeModel.isValid(row, node); - return rowValid; - } - - @Override - protected void saveRow(SpeciesBatchRowModel row) { - - SpeciesBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getFishingOperation(); - catchBean.setFishingOperation(fishingOperation); - if (log.isInfoEnabled()) { - log.info("Selected fishingOperation: " + fishingOperation.getId()); - } - - if (TuttiEntities.isNew(catchBean)) { - - catchBean = persistenceService.createSpeciesBatch(catchBean); - row.setId(catchBean.getId()); - } else { - persistenceService.saveSpeciesBatch(catchBean); - } - - List<SpeciesFrequencyRowModel> frequencyRows = row.getFrequency(); - - List<SpeciesBatchFrequency> frequency = - SpeciesFrequencyRowModel.toBeans(frequencyRows, catchBean); - - if (log.isInfoEnabled()) { - log.info("Will save " + frequency.size() + " frequencies."); - } - frequency = persistenceService.saveSpeciesBatchFrequency( - catchBean.getId(), frequency); - - // push it back to row model - frequencyRows = SpeciesFrequencyRowModel.fromBeans(frequency); - row.setFrequency(frequencyRows); - } - - @Override - public void selectFishingOperation(FishingOperation bean) { - - JXTable table = ui.getTable(); - - if (table.isEditing()) { - - // make sure to stop editor - table.editingCanceled(null); - } - - // make sure selection is empty (will remove bean from monitor) - table.clearSelection(); - - boolean empty = bean == null; - - SpeciesBatchUIModel model = getModel(); - - List<SpeciesBatchRowModel> rows; - - if (empty) { - rows = null; - } else { - - if (log.isInfoEnabled()) { - log.info("Get species batch for fishingOperation: " + - bean.getId()); - } - rows = Lists.newArrayList(); - - if (!TuttiEntities.isNew(bean)) { - List<SpeciesBatch> catches = - persistenceService.getAllSpeciesBatch(bean.getId()); - for (SpeciesBatch aBatch : catches) { - List<SpeciesBatchFrequency> frequencies = - persistenceService.getAllSpeciesBatchFrequency(aBatch.getId()); - SpeciesBatchRowModel entry = - new SpeciesBatchRowModel(aBatch, frequencies); - rows.add(entry); - } - } - } - model.setRows(rows); - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInitUI() { - - if (log.isInfoEnabled()) { - log.info("beforeInit: " + ui); - } - - EditCatchesUIModel catchesUIModel = - ui.getContextValue(EditCatchesUIModel.class); - - SpeciesBatchUIModel model = new SpeciesBatchUIModel(catchesUIModel); - ui.setContextValue(model); - } - - @Override - public void afterInitUI() { - - if (log.isInfoEnabled()) { - log.info("afterInit: " + ui); - } - - initUI(ui); - - //TODO Will come from protocol - List<String> samplingOrder = Lists.newArrayList( - SpeciesBatchRowModel.PROPERTY_SPECIES, - SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, - SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, - SpeciesBatchRowModel.PROPERTY_AGE - ); - - getModel().setSamplingOrder(samplingOrder); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - // create table model - SpeciesBatchTableModel tableModel = - new SpeciesBatchTableModel(columnModel); - - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initBatchTable(table, columnModel, tableModel); - } - - @Override - public void onCloseUI() { - if (log.isInfoEnabled()) { - log.info("closing: " + ui); - } - } - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - protected void recomputeSuperSamplingRatio(SpeciesBatchTreeModel samplingTreeModel, - SpeciesBatchTreeNode node) { - - SpeciesBatchTreeNode superSamplingNode = node.getParent(); - - Preconditions.checkNotNull(superSamplingNode, - "Super sampling node can't be null"); - - SpeciesBatchTreeModel.SamplingContext samplingContext = - samplingTreeModel.createSamplingContext(superSamplingNode); - - float samplingTotalWeight = samplingContext.getTotalWeight(); - Float superSamplingTotalWeight; - SpeciesBatchRowModel superSamplingRow = - samplingContext.getSuperSamplingRow(); - if (superSamplingRow == null) { - - // Use directly the batch total weight (means no super-sampling) - - superSamplingTotalWeight = getModel().getSpeciesTotalWeight(); - } else { - superSamplingTotalWeight = superSamplingRow.getWeight(); - } - - if (log.isInfoEnabled()) { - log.info("Super sampling total weight: " + - superSamplingTotalWeight); - } - - Float samplingRatio = null; - if (superSamplingTotalWeight != null) { - samplingRatio = samplingTotalWeight / superSamplingTotalWeight; - } - - if (log.isInfoEnabled()) { - log.info("Sampling ratio: " + samplingRatio); - } - - samplingContext.applyNewSampleValues(samplingTotalWeight, - samplingRatio); - - getTableModel().updateSamplingRatio(samplingContext.getSamplingRows()); - } - - protected void recomputeTotalHorsVrac() { - - // recompute total hors vrac - Float totalHorsVrac = 0f; - Float totalVrac = 0f; - - for (SpeciesBatchRowModel batch : getModel().getRows()) { - CaracteristicQualitativeValue vracHorsVrac = - batch.getSortedUnsortedCategory(); - - if (vracHorsVrac == null) { - - // can't sum anything - } else { - boolean unsorted = "unsorted".equals(vracHorsVrac.getName()); - if (unsorted) { - Float weight = batch.getWeight(); - if (weight != null) { - totalHorsVrac += weight; - } - } else { - Float weight = batch.getWeight(); - if (weight != null) { - totalVrac += weight; - } - } - } - } - if (log.isInfoEnabled()) { - log.info("New total vrac / hors vrac: " + - totalVrac + " / " + totalHorsVrac); - } - getModel().setSpeciesTotalUnsortedWeight(totalHorsVrac); - //TODO Should we also set the total vrac weight ? -// getModel().setTotalVracWeight(totalVrac); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,108 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel> { - - private static final long serialVersionUID = 1L; - - /** - * Sampling order (sets by protocol). - * - * @since 0.2 - */ - protected List<String> samplingOrder; - - /** - * Tree of sampling for batch rows. - * - * @since 0.2 - */ - protected final SpeciesBatchTreeModel samplingTreeModel; - - public SpeciesBatchUIModel(EditCatchesUIModel catchesUIModel) { - super(catchesUIModel, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT); - this.samplingTreeModel = new SpeciesBatchTreeModel(); - } - - public Float getSpeciesTotalWeight() { - return catchesUIModel.getSpeciesTotalWeight(); - } - - public void setSpeciesTotalWeight(Float speciesTotalWeight) { - catchesUIModel.setSpeciesTotalWeight(speciesTotalWeight); - } - - public Float getSpeciesTotalSortedWeight() { - return catchesUIModel.getSpeciesTotalSortedWeight(); - } - - public void setSpeciesTotalSortedWeight(Float speciesTotalSortedWeight) { - catchesUIModel.setSpeciesTotalSortedWeight(speciesTotalSortedWeight); - } - - public Float getSpeciesTotalSampleSortedWeight() { - return catchesUIModel.getSpeciesTotalSampleSortedWeight(); - } - - public void setSpeciesTotalSampleSortedWeight(Float speciesSampleSortedWeight) { - catchesUIModel.setSpeciesTotalSampleSortedWeight(speciesSampleSortedWeight); - } - - public Float getSpeciesTotalUnsortedWeight() { - return catchesUIModel.getSpeciesTotalUnsortedWeight(); - } - - public void setSpeciesTotalUnsortedWeight(Float speciesTotalUnsortedWeight) { - catchesUIModel.setSpeciesTotalUnsortedWeight(speciesTotalUnsortedWeight); - } - - public SpeciesBatchTreeModel getSamplingTreeModel() { - return samplingTreeModel; - } - - public List<String> getSamplingOrder() { - return samplingOrder; - } - - public void setSamplingOrder(List<String> samplingOrder) { - this.samplingOrder = samplingOrder; - samplingTreeModel.setSamplingOrder(samplingOrder.toArray(new String[samplingOrder.size()])); - } - -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,169 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * Represents a batch frequency row. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBatchFrequency, SpeciesFrequencyRowModel> implements Comparable<SpeciesFrequencyRowModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_LENGTH_STEP = "lengthStep"; - - public static final String PROPERTY_NUMBER = "number"; - - public static final String PROPERTY_WEIGHT = "weight"; - - public static final String PROPERTY_COMPUTED_WEIGHT = "computedWeight"; - - /** - * Length step. - * - * @since 0.2 - */ - protected Float lengthStep; - - /** - * Count of fishes for this lengthStep. - * - * @since 0.2 - */ - protected Integer number; - - /** - * Weight of fishes observed. - * - * @since 0.2 - */ - protected Float weight; - - /** - * Computed weight from number + relation taille-poids. - * - * @since 0.2 - */ - protected Float computedWeight; - - protected static final Binder<SpeciesBatchFrequency, SpeciesFrequencyRowModel> fromBeanBinder = - BinderFactory.newBinder(SpeciesBatchFrequency.class, - SpeciesFrequencyRowModel.class); - - protected static final Binder<SpeciesFrequencyRowModel, SpeciesBatchFrequency> toBeanBinder = - BinderFactory.newBinder(SpeciesFrequencyRowModel.class, - SpeciesBatchFrequency.class); - - private static final Ordering<Float> ordering = Ordering.natural().nullsFirst(); - - public static List<SpeciesFrequencyRowModel> fromBeans(List<SpeciesBatchFrequency> frequency) { - List<SpeciesFrequencyRowModel> result = Lists.newArrayList(); - for (SpeciesBatchFrequency b : frequency) { - SpeciesFrequencyRowModel model = new SpeciesFrequencyRowModel(); - fromBeanBinder.copy(b, model); - result.add(model); - } - return result; - } - - public static List<SpeciesBatchFrequency> toBeans(List<SpeciesFrequencyRowModel> frequency, SpeciesBatch batch) { - List<SpeciesBatchFrequency> result = Lists.newArrayList(); - for (SpeciesFrequencyRowModel b : frequency) { - SpeciesBatchFrequency model = new SpeciesBatchFrequency(); - toBeanBinder.copy(b, model); - model.setBatch(batch); - result.add(model); - } - return result; - } - - public SpeciesFrequencyRowModel() { - super(SpeciesBatchFrequency.class, fromBeanBinder, toBeanBinder); - } - - public Float getLengthStep() { - return lengthStep; - } - - public void setLengthStep(Float lengthStep) { - Object oldValue = getLengthStep(); - this.lengthStep = lengthStep; - firePropertyChange(PROPERTY_LENGTH_STEP, oldValue, lengthStep); - } - - public Integer getNumber() { - return number; - } - - public void setNumber(Integer number) { - Object oldValue = getNumber(); - this.number = number; - firePropertyChange(PROPERTY_NUMBER, oldValue, number); - } - - public Float getWeight() { - return weight; - } - - public void setWeight(Float weight) { - Object oldValue = getWeight(); - this.weight = weight; - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); - } - - public Float getComputedWeight() { - return computedWeight; - } - - public void setComputedWeight(Float computedWeight) { - Object oldValue = getComputedWeight(); - this.computedWeight = computedWeight; - firePropertyChange(PROPERTY_COMPUTED_WEIGHT, oldValue, computedWeight); - } - - //TODO Use validator - @Override - public boolean isValid() { - return lengthStep != null && number != null; - } - - @Override - public int compareTo(SpeciesFrequencyRowModel o) { - int result = ordering.compare(lengthStep, o.lengthStep); - return result; - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyTableModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyTableModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,146 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; -import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; - -import javax.swing.table.TableColumnModel; -import java.util.List; -import java.util.Map; - -import static org.nuiton.i18n.I18n.n_; - -/** - * Model of the species frequency table. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesFrequencyTableModel extends AbstractTuttiTableModel<SpeciesFrequencyRowModel> { - - private static final long serialVersionUID = 1L; - - public static final ColumnIdentifier<SpeciesFrequencyRowModel> LENGTH_STEP = ColumnIdentifier.newId( - SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP, - n_("tutti.table.species.frequency.header.lengthStep"), - n_("tutti.table.species.frequency.header.lengthStep")); - - public static final ColumnIdentifier<SpeciesFrequencyRowModel> NUMBER = ColumnIdentifier.newId( - SpeciesFrequencyRowModel.PROPERTY_NUMBER, - n_("tutti.table.species.frequency.header.number"), - n_("tutti.table.species.frequency.header.number")); - - public static final ColumnIdentifier<SpeciesFrequencyRowModel> WEIGHT = ColumnIdentifier.newId( - SpeciesFrequencyRowModel.PROPERTY_WEIGHT, - n_("tutti.table.species.frequency.header.weight"), - n_("tutti.table.species.frequency.header.weight")); - - public static final ColumnIdentifier<SpeciesFrequencyRowModel> COMPUTED_WEIGHT = ColumnIdentifier.newId( - SpeciesFrequencyRowModel.PROPERTY_COMPUTED_WEIGHT, - n_("tutti.table.species.frequency.header.computedWeight"), - n_("tutti.table.species.frequency.header.computedWeight")); - - private final SpeciesFrequencyUIModel uiModel; - - private final Map<Float, SpeciesFrequencyRowModel> rowCache; - - public SpeciesFrequencyTableModel(TableColumnModel columnModel, - SpeciesFrequencyUIModel uiModel) { - super(columnModel); - this.uiModel = uiModel; - this.rowCache = Maps.newTreeMap(); - setNoneEditableCols(COMPUTED_WEIGHT); - } - - @Override - protected SpeciesFrequencyRowModel createNewRow() { - Float defaultStep = null; - - int rowCount = getRowCount(); - if (rowCount > 0) { - - SpeciesFrequencyRowModel rowModel = getEntry(rowCount - 1); - Float lengthStep = rowModel.getLengthStep(); - if (lengthStep != null) { - defaultStep = uiModel.getLengthStep( - lengthStep + uiModel.getStep()); - } - } - SpeciesFrequencyRowModel result = new SpeciesFrequencyRowModel(); - result.setLengthStep(defaultStep); - result.setValid(false); - return result; - } - - @Override - public void setValueAt(Object aValue, - int rowIndex, - int columnIndex, - ColumnIdentifier<SpeciesFrequencyRowModel> propertyName, - SpeciesFrequencyRowModel entry) { - super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); - // TODO Rebuild the computedWeight if possible... - } - - public Map<Float, SpeciesFrequencyRowModel> getRowCache() { - return rowCache; - } - - @Override - protected void onRowsChanged(List<SpeciesFrequencyRowModel> data) { - - // rebuild row cache - rowCache.clear(); - - for (SpeciesFrequencyRowModel row : data) { - Float lengthStep = row.getLengthStep(); - if (lengthStep != null) { - rowCache.put(lengthStep, row); - } - } - } - - @Override - protected void onRowAdded(int rowIndex, SpeciesFrequencyRowModel newValue) { - - Preconditions.checkNotNull(newValue, "can't add a null row"); - - // add new row to cache - Float lengthStep = newValue.getLengthStep(); - - Preconditions.checkNotNull(lengthStep, - "can't add a null lengthStep row"); - - float roundLenghtValue = uiModel.getLengthStep(lengthStep); - - if (!rowCache.containsKey(roundLenghtValue)) { - - rowCache.put(roundLenghtValue, newValue); - } - } -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.css 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.css 2012-12-21 20:51:46 UTC (rev 105) @@ -1,142 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -NumberEditor { - autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; -} - -#stepLabel { - text: "tutti.label.frequencyConfiguration.step"; - labelFor: {stepField}; -} - -#stepField { - property: "step"; - model: {model.getStep()}; - useFloat: true; - numberPattern: {DECIMAL1_PATTERN}; - bean: {model}; -} - -#minStepLabel { - text: "tutti.label.frequencyConfiguration.minStep"; - labelFor: {minStepField}; -} - -#minStepField { - property: "minStep"; - model: {model.getMinStep()}; - useFloat: true; - showReset: true; - numberPattern: {DECIMAL1_PATTERN}; - bean: {model}; -} - -#maxStepLabel { - text: "tutti.label.frequencyConfiguration.maxStep"; - labelFor: {maxStepField}; -} - -#maxStepField { - property: "maxStep"; - model: {model.getMaxStep()}; - useFloat: true; - showReset: true; - numberPattern: {DECIMAL1_PATTERN}; - bean: {model}; -} - -#rafaleStepLabel { - text: "tutti.label.frequencyConfiguration.rafaleStep"; - labelFor: {rafaleStepField}; -} - -#rafaleStepField { - modelType: {Float.class}; - useFloat: true; - showReset: true; - numberPattern: {DECIMAL1_PATTERN}; -} - -#generateButton { - actionIcon: "generate"; - text: "tutti.action.generate"; - enabled: {model.isCanGenerate()}; -} - -#configurationPanel { - border: {new TitledBorder(null, _("tutti.legend.frequencyConfiguration"))}; -} - -#modeConfigurationLayout { - selected: {String.valueOf(mode.getSelectedValue())}; -} - -#modeConfigurationPanel { - layout: {modeConfigurationLayout}; -} - -#simpleModeButton { - text: "tutti.label.frequencyConfiguration.mode.simple"; - toolTipText: "tutti.label.frequencyConfiguration.mode.simple.tip"; - value: "simpleMode"; - selected: {model.isSimpleMode()}; - buttonGroup: "mode"; -} - -#simpleModeLabel { - text: "tutti.label.frequencyConfiguration.no.configuration"; - horizontalAlignment: {JLabel.CENTER}; - enabled: false; -} - -#autoGenModeButton { - text: "tutti.label.frequencyConfiguration.mode.autoGen"; - toolTipText: "tutti.label.frequencyConfiguration.mode.autoGen.tip"; - value: "autoGenMode"; - selected: {model.isAutoGenMode()}; - buttonGroup: "mode"; -} - -#rafaleModeButton { - text: "tutti.label.frequencyConfiguration.mode.rafale"; - toolTipText: "tutti.label.frequencyConfiguration.mode.rafale.tip"; - value: "rafaleMode"; - selected: {model.isRafaleMode()}; - buttonGroup: "mode"; -} - -#closeButton { - actionIcon: "close"; - text: "tutti.action.close"; - mnemonic: F; -} - -#table { - selectionMode: {ListSelectionModel.SINGLE_SELECTION}; - selectionBackground: {null}; - selectionForeground: {Color.BLACK}; - sortable: false; -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.jaxx 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUI.jaxx 2012-12-21 20:51:46 UTC (rev 105) @@ -1,167 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 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='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<SpeciesFrequencyUIModel, SpeciesFrequencyUIHandler>'> - - <import> - fr.ifremer.tutti.ui.swing.TuttiUIContext - fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesBatchRowModel - - jaxx.runtime.swing.CardLayout2Ext - jaxx.runtime.swing.editor.bean.BeanComboBox - jaxx.runtime.swing.editor.NumberEditor - - org.jdesktop.swingx.JXTable - - javax.swing.ListSelectionModel - javax.swing.SwingConstants - - java.awt.Color - java.awt.Dimension - - static org.nuiton.i18n.I18n._ - static jaxx.runtime.SwingUtil.getStringValue - </import> - - <script><![CDATA[ - - public SpeciesFrequencyUI(TuttiUIContext context) { - SpeciesFrequencyUIHandler handler = new SpeciesFrequencyUIHandler(context, this); - setContextValue(handler); - handler.beforeInitUI(); - } - - public void editBatch(SpeciesBatchRowModel row) { - handler.editBatch(row); - } - - protected void $afterCompleteSetup() { - handler.afterInitUI(); - } - ]]></script> - - <SpeciesFrequencyUIHandler id='handler' - initializer='getContextValue(SpeciesFrequencyUIHandler.class)'/> - - <SpeciesFrequencyUIModel id='model' - initializer='getContextValue(SpeciesFrequencyUIModel.class)'/> - - <CardLayout2Ext id='modeConfigurationLayout' - constructorParams='this, "modeConfigurationPanel"'/> - - <JPanel id='configurationPanel' layout='{new BorderLayout()}' constraints='BorderLayout.NORTH'> - - <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.CENTER'> - <VBox id='modePanel' constraints='BorderLayout.WEST' - verticalAlignment='{SwingConstants.CENTER}'> - <JRadioButton id='simpleModeButton' - onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE)'/> - <JRadioButton id='autoGenModeButton' - onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.AUTO_GEN)'/> - <JRadioButton id='rafaleModeButton' - onActionPerformed='model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.RAFALE)'/> - </VBox> - - <JPanel id='modeConfigurationPanel' constraints='BorderLayout.CENTER'> - <JPanel id='simpleModePanel' constraints='"simpleMode"' - layout='{new BorderLayout()}'> - <JLabel id='simpleModeLabel' constraints='BorderLayout.CENTER'/> - </JPanel> - <JPanel id='autoGenModePanel' constraints='"autoGenMode"'> - <Table fill='both' constraints='BorderLayout.SOUTH'> - <!-- Min step--> - <row> - <cell anchor='west'> - <JLabel id='minStepLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='minStepField' constructorParams='this'/> - </cell> - </row> - <!-- Max step--> - <row> - <cell anchor='west'> - <JLabel id='maxStepLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='maxStepField' constructorParams='this'/> - </cell> - </row> - <!-- Actions --> - <row> - <cell columns='2'> - <JPanel layout='{new GridLayout(1, 0)}'> - <JButton id='generateButton' - onActionPerformed='handler.generateLengthSteps()'/> - </JPanel> - </cell> - </row> - </Table> - </JPanel> - <JPanel id='rafaleModePanel' constraints='"rafaleMode"'> - <Table fill='both' constraints='BorderLayout.SOUTH'> - <!-- Rafale step--> - <row> - <cell weightx='1.0'> - <JLabel id='rafaleStepLabel'/> - </cell> - </row> - <row> - <cell weightx='1.0'> - <NumberEditor id='rafaleStepField' constructorParams='this'/> - </cell> - </row> - </Table> - </JPanel> - </JPanel> - </JPanel> - <Table fill='both' constraints='BorderLayout.SOUTH'> - <row> - <cell columns='2'> - <JSeparator/> - </cell> - </row> - <!-- Step --> - <row> - <cell anchor='west'> - <JLabel id='stepLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='stepField' constructorParams='this'/> - </cell> - </row> - </Table> - </JPanel> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JXTable id='table'/> - </JScrollPane> - - <!-- actions --> - <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}' - constraints='BorderLayout.SOUTH'> - <JButton id='closeButton' onActionPerformed='handler.close()'/> - </JPanel> - -</JPanel> \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIHandler.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIHandler.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,362 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.TuttiUIContext; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; -import jaxx.runtime.SwingUtil; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.HighlightPredicate; -import org.jdesktop.swingx.table.DefaultTableColumnModelExt; - -import javax.swing.JDialog; -import javax.swing.table.TableColumnModel; -import java.awt.Color; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<SpeciesFrequencyRowModel, SpeciesFrequencyUIModel> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(SpeciesFrequencyUIHandler.class); - - private final SpeciesFrequencyUI ui; - - public SpeciesFrequencyUIHandler(TuttiUIContext context, - SpeciesFrequencyUI ui) { - super(context, - SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP, - SpeciesFrequencyRowModel.PROPERTY_NUMBER, - SpeciesFrequencyRowModel.PROPERTY_WEIGHT, - SpeciesFrequencyRowModel.PROPERTY_COMPUTED_WEIGHT); - this.ui = ui; - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiTableUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - protected SpeciesFrequencyUIModel getModel() { - return ui.getModel(); - } - - @Override - protected SpeciesFrequencyTableModel getTableModel() { - return (SpeciesFrequencyTableModel) getTable().getModel(); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); - - { // LengthStep - - addFloatColumnToModel(columnModel, - SpeciesFrequencyTableModel.LENGTH_STEP, - TuttiUI.DECIMAL1_PATTERN); - } - - { // Number - - addIntegerColumnToModel(columnModel, - SpeciesFrequencyTableModel.NUMBER, - TuttiUI.INT_6_DIGITS_PATTERN); - } - - { // Weight - - addFloatColumnToModel(columnModel, - SpeciesFrequencyTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // ComputedWeight - - addFloatColumnToModel(columnModel, - SpeciesFrequencyTableModel.COMPUTED_WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - return columnModel; - } - - @Override - protected void onRowModified(SpeciesFrequencyRowModel row, - String propertyName, - Object oldValue, - Object newValue) { - if (SpeciesFrequencyRowModel.PROPERTY_NUMBER.equals(propertyName)) { - - // Need to recompute the computedWeight - computeComputedWeight(row); - } - } - - @Override - protected void onRowValidStateChanged(SpeciesFrequencyRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - @Override - protected void onRowModifyStateChanged(SpeciesFrequencyRowModel row, - Boolean oldValue, - Boolean newValue) { - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInitUI() { - - SpeciesFrequencyUIModel model = new SpeciesFrequencyUIModel(); - - ui.setContextValue(model); - } - - @Override - public void afterInitUI() { - - initUI(ui); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - SpeciesFrequencyUIModel model = getModel(); - - // create table model - SpeciesFrequencyTableModel tableModel = - new SpeciesFrequencyTableModel(columnModel, model); - - table.setModel(tableModel); - table.setColumnModel(columnModel); - - installTableKeyListener(columnModel, table); - - table.getTableHeader().setReorderingAllowed(false); - - table.addHighlighter(TuttiUIUtil.newBackgroundColorHighlighter( - HighlightPredicate.READ_ONLY, Color.LIGHT_GRAY)); - - // when model datas change let's propagate it table model - listenRowsFromModel(); - - //TODO Should it come from PROTOCOL or config ? - model.setStep(.5f); - - model.setMinStep(10f); - model.setMaxStep(20f); - - //TODO Configure this ? - model.setConfigurationMode(SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE); - - // always scroll to selected row - SwingUtil.scrollToTableSelection(getTable()); - - ui.getRafaleStepField().getTextField().addKeyListener(new KeyAdapter() { - - @Override - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - e.consume(); - Float step = (Float) ui.getRafaleStepField().getModel(); - - applyRafaleStep(step); - } - } - }); - } - - @Override - public void onCloseUI() { - } - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - public void generateLengthSteps() { - - SpeciesFrequencyUIModel model = getModel(); - - Map<Float, SpeciesFrequencyRowModel> rowsByStep = - getTableModel().getRowCache(); - - Float minStep = model.getLengthStep(model.getMinStep()); - Float maxStep = model.getLengthStep(model.getMaxStep()); - - for (float i = minStep, step = model.getStep(); i <= maxStep; i += step) { - if (!rowsByStep.containsKey(i)) { - - // add it - SpeciesFrequencyRowModel newRow = new SpeciesFrequencyRowModel(); - newRow.setLengthStep(i); - rowsByStep.put(i, newRow); - } - } - - List<SpeciesFrequencyRowModel> rows = - Lists.newArrayList(rowsByStep.values()); - - model.setRows(rows); - } - - public void applyRafaleStep(Float step) { - - if (log.isInfoEnabled()) { - log.info("Will apply rafale step: " + step); - } - SpeciesFrequencyUIModel model = getModel(); - SpeciesFrequencyTableModel tableModel = getTableModel(); - - Map<Float, SpeciesFrequencyRowModel> rowsByStep = tableModel.getRowCache(); - - float aroundLengthStep = model.getLengthStep(step); - - SpeciesFrequencyRowModel row = rowsByStep.get(aroundLengthStep); - - int rowIndex; - - if (row != null) { - - // increments current row - Integer number = row.getNumber(); - row.setNumber((number == null ? 0 : number) + 1); - rowIndex = tableModel.updateRow(row); - - } else { - - // create a new row - row = new SpeciesFrequencyRowModel(); - row.setLengthStep(aroundLengthStep); - row.setNumber(1); - - // get new index - List<Float> steps = Lists.newArrayList(rowsByStep.keySet()); - steps.add(aroundLengthStep); - - Collections.sort(steps); - - rowIndex = steps.indexOf(aroundLengthStep); - - tableModel.addNewRow(rowIndex, row); - } - - getTable().scrollRowToVisible(rowIndex); - } - - public void editBatch(SpeciesBatchRowModel row) { - - List<SpeciesFrequencyRowModel> frequency = null; - if (row != null) { - frequency = row.getFrequency(); - } - - List<SpeciesFrequencyRowModel> editFrequency; - if (CollectionUtils.isEmpty(frequency)) { - - // new list - editFrequency = Lists.newArrayList(); - } else { - - editFrequency = Lists.newArrayList(frequency); - } - - if (log.isInfoEnabled()) { - log.info("Will edit batch row: " + row + " with " + - editFrequency.size() + " frequency"); - } - getModel().setRows(editFrequency); - - // keep batch (will be used to push back editing entry) - getModel().setBatch(row); - } - - public void close() { - - if (log.isInfoEnabled()) { - log.info("Will close UI " + ui); - } - - // transfer rows to editor - - List<SpeciesFrequencyRowModel> frequency = Lists.newArrayList(); - for (SpeciesFrequencyRowModel row : getModel().getRows()) { - if (row.isValid()) { - - // can keep this row - frequency.add(row); - } - } - - if (log.isInfoEnabled()) { - log.info("Push back " + frequency.size() + - " frequency to batch " + getModel().getBatch()); - } - - // push back to batch - getModel().getBatch().setFrequency(frequency); - - ui.editBatch(null); - - SwingUtil.getParentContainer(ui, JDialog.class).setVisible(false); - } - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - protected void computeComputedWeight(SpeciesFrequencyRowModel row) { - - if (log.isInfoEnabled()) { - log.info("Will recompute computed weight for frequency: " + row); - } - } - -} \ No newline at end of file Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIModel.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyUIModel.java 2012-12-21 20:51:46 UTC (rev 105) @@ -1,174 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 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% - */ - -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBatchRowModel, SpeciesFrequencyRowModel, SpeciesFrequencyUIModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_CONFIGURATION_MODE = "configurationMode"; - - public static final String PROPERTY_STEP = "step"; - - private static final String PROPERTY_MIN_STEP = "minStep"; - - private static final String PROPERTY_MAX_STEP = "maxStep"; - - public static final String PROPERTY_CAN_GENERATE = "canGenerate"; - - public static final String PROPERTY_SIMPLE_MODE = "simpleMode"; - - public static final String PROPERTY_AUTO_GEN_MODE = "autoGenMode"; - - public static final String PROPERTY_RAFALE_MODE = "rafaleMode"; - - public static enum ConfigurationMode { - SIMPLE, - AUTO_GEN, - RAFALE - } - - /** - * Fill mode. - * - * @since 0.2 - */ - protected ConfigurationMode configurationMode; - - /** - * Batch that contains frequencies. - * - * @since 0.2 - */ - protected SpeciesBatchRowModel batch; - - /** - * Default step to increment length step. - * - * @since 0.2 - */ - protected float step; - - /** - * Min step to auto generate length steps. - * - * @since 0.2 - */ - protected Float minStep; - - /** - * Max step to auto generate length steps. - * - * @since 0.2 - */ - protected Float maxStep; - - public SpeciesFrequencyUIModel() { - super(SpeciesBatchRowModel.class, null, null); - } - - public ConfigurationMode getConfigurationMode() { - return configurationMode; - } - - public void setConfigurationMode(ConfigurationMode configurationMode) { - Object oldValue = getConfigurationMode(); - this.configurationMode = configurationMode; - firePropertyChange(PROPERTY_CONFIGURATION_MODE, oldValue, configurationMode); - firePropertyChange(PROPERTY_SIMPLE_MODE, null, isSimpleMode()); - firePropertyChange(PROPERTY_AUTO_GEN_MODE, null, isAutoGenMode()); - firePropertyChange(PROPERTY_RAFALE_MODE, null, isRafaleMode()); - } - - public float getStep() { - return step; - } - - public void setStep(float step) { - Object oldValue = getStep(); - this.step = step; - firePropertyChange(PROPERTY_STEP, oldValue, step); - } - - public Float getMinStep() { - return minStep; - } - - public void setMinStep(Float minStep) { - Object oldValue = getMinStep(); - this.minStep = minStep; - firePropertyChange(PROPERTY_MIN_STEP, oldValue, minStep); - firePropertyChange(PROPERTY_CAN_GENERATE, null, isCanGenerate()); - } - - public Float getMaxStep() { - return maxStep; - } - - public void setMaxStep(Float maxStep) { - Object oldValue = getMaxStep(); - this.maxStep = maxStep; - firePropertyChange(PROPERTY_MAX_STEP, oldValue, maxStep); - firePropertyChange(PROPERTY_CAN_GENERATE, null, isCanGenerate()); - } - - public boolean isSimpleMode() { - return ConfigurationMode.SIMPLE == configurationMode; - } - - public boolean isAutoGenMode() { - return ConfigurationMode.AUTO_GEN == configurationMode; - } - - public boolean isRafaleMode() { - return ConfigurationMode.RAFALE == configurationMode; - } - - public boolean isCanGenerate() { - return minStep != null && maxStep != null && maxStep > minStep; - } - - public SpeciesBatchRowModel getBatch() { - return batch; - } - - public void setBatch(SpeciesBatchRowModel batch) { - this.batch = batch; - } - - public float getLengthStep(float lengthStep) { - int intValue = (int) (lengthStep * 10); - int intStep = (int) (step * 10); - int correctIntStep = intValue - (intValue % intStep); - float result = correctIntStep / 10f; - return result; - } -} \ No newline at end of file Modified: trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModelTest.java =================================================================== --- trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModelTest.java 2012-12-21 20:27:17 UTC (rev 104) +++ trunk/tutti-ui-swing/src/test/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesFrequencyRowModelTest.java 2012-12-21 20:51:46 UTC (rev 105) @@ -24,6 +24,7 @@ * #L% */ +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesFrequencyRowModel; import org.junit.Assert; import org.junit.Test;
participants (1)
-
tchemit@users.forge.codelutin.com