r41 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing/content java/fr/ifremer/tutti/ui/swing/content/catches/species java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency java/fr/ifremer/tutti/ui/swing/content/operation java/fr/ifremer/tutti/ui/swing/content/operation/species resources/fr/ifremer/tutti/ui/swing/content
Author: tchemit Date: 2012-12-11 15:29:06 +0100 (Tue, 11 Dec 2012) New Revision: 41 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/41 Log: move species to his correct package + remove obsolete packages Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/ 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/SpeciesTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIModel.java Removed: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/campaign/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeNode.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/campaign/ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/catches/ Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/FrequencyCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/FrequencyCellComponent.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/FrequencyCellComponent.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,256 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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.content.catches.species.frequency.SpeciesFrequencyUI; -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); - } - - @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/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchRowModel.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchRowModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,379 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.VracHorsVracEnum; -import fr.ifremer.tutti.persistence.entities.referential.Sex; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.WeightCategory; -import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; -import fr.ifremer.tutti.ui.swing.content.catches.species.frequency.SpeciesFrequencyRowModel; -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_VRAC_HORS_VRAC = "vracHorsVrac"; - - public static final String PROPERTY_WEIGHT_CATEGORY = "weightCategory"; - - public static final String PROPERTY_SEX = "sex"; - - public static final String PROPERTY_MATURITY = "maturity"; - - 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"; - - /** - * 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 VracHorsVracEnum vracHorsVrac; - - /** - * Weight category (can be null). - * - * @since 0.2 - */ - protected WeightCategory weightCategory; - - /** - * Sex (can be null). - * - * @since 0.2 - */ - protected Sex sex; - - /** - * Maturity (can be null). - * - * @since 0.2 - */ - protected Float maturity; - - /** - * 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; - - /** - * Elevation ratio. - * - * @since 0.2 - */ - protected Float samplingRatio; - - /** - * Comment on this catches. - * - * @since 0.2 - */ - protected String comment; - - /** - * 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 VracHorsVracEnum getVracHorsVrac() { - return vracHorsVrac; - } - - public void setVracHorsVrac(VracHorsVracEnum vracHorsVrac) { - Object oldValue = getVracHorsVrac(); - this.vracHorsVrac = vracHorsVrac; - firePropertyChange(PROPERTY_VRAC_HORS_VRAC, oldValue, vracHorsVrac); - } - - public WeightCategory getWeightCategory() { - return weightCategory; - } - - public void setWeightCategory(WeightCategory weightCategory) { - Object oldValue = getWeightCategory(); - this.weightCategory = weightCategory; - firePropertyChange(PROPERTY_WEIGHT_CATEGORY, oldValue, weightCategory); - } - - public Sex getSex() { - return sex; - } - - public void setSex(Sex sex) { - Object oldValue = getSex(); - this.sex = sex; - firePropertyChange(PROPERTY_SEX, oldValue, sex); - } - - public Float getMaturity() { - return maturity; - } - - public void setMaturity(Float maturity) { - Object oldValue = getMaturity(); - this.maturity = maturity; - firePropertyChange(PROPERTY_MATURITY, oldValue, maturity); - } - - 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<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); - } - - //TODO Use validator - @Override - public boolean isValid() { - return species != null && weight != null; - } - - public int getRowCount() { - return frequency == null ? 0 : frequency.size(); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTableModel.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTableModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,200 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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_TO_CONFIRM = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - n_("tutti.table.species.batch.header.toConfirm"), - n_("tutti.table.species.batch.header.toConfirm")); - - 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> VRAC_HORS_VRAC = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_VRAC_HORS_VRAC, - n_("tutti.table.species.batch.header.vracHorsVrac"), - n_("tutti.table.species.batch.header.vracHorsVrac")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> WEIGHT_CATEGORY = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_WEIGHT_CATEGORY, - n_("tutti.table.species.batch.header.weightCategory"), - n_("tutti.table.species.batch.header.weightCategory")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> SEX = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SEX, - n_("tutti.table.species.batch.header.sex"), - n_("tutti.table.species.batch.header.sex")); - - public static final ColumnIdentifier<SpeciesBatchRowModel> MATURITY = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_MATURITY, - n_("tutti.table.species.batch.header.maturity"), - n_("tutti.table.species.batch.header.maturity")); - - 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> ELEVATION_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> FILE = ColumnIdentifier.newId( - null, - n_("tutti.table.species.batch.header.file"), - n_("tutti.table.species.batch.header.file")); - - - protected final Set<ColumnIdentifier<SpeciesBatchRowModel>> noneEditableColIfNoSpecies; - - public SpeciesBatchTableModel(TableColumnModel columnModel) { - super(columnModel); - - // TODO This will be dynamic by the protocol... - setNoneEditableCols( - AGE, - MATURITY, - SAMPLE_WEIGHT, - ELEVATION_RATIO, - FILE - ); - noneEditableColIfNoSpecies = Sets.newHashSet(); - noneEditableColIfNoSpecies.add(COMPUTED_NUMBER); - noneEditableColIfNoSpecies.add(COMPUTED_WEIGHT); - } - - @Override - protected SpeciesBatchRowModel createNewRow() { - return new SpeciesBatchRowModel(); - } - - @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); - } - } - - @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/catches/species/SpeciesBatchTreeModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeModel.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,102 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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.SpeciesBatch; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; - -import java.io.Serializable; -import java.util.List; - -/** - * @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 final String[] samplingOrder; - - /** - * Samplings view as a linear list (to display in the table). - * - * @since 0.2 - */ - protected final List<SpeciesBatchTreeNode> lines; - - public SpeciesBatchTreeModel(String... samplingOrder) { - this.samplingOrder = samplingOrder; - root = new SpeciesBatchTreeNode(); - lines = Lists.newArrayList(); - } - - public SpeciesBatchTreeNode getNode(int rowIndex) { - return lines.get(rowIndex); - } - - public int getSize() { - return lines.size(); - } - - public void populate(List<SpeciesBatch> data) { - - // clear tree representation - root.removeAllChildren(); - - // clear linear representation - lines.clear(); - } - - public Object[] getSamplingKey(SpeciesBatch bean) { - List<Object> result = Lists.newArrayList(); - for (String s : samplingOrder) { - Object property = TuttiUIUtil.getProperty(bean, s); - if (property == null) { - // stop findind sample key - break; - } - result.add(property); - } - return result.toArray(); - } - - public String[] getSamplingDefinition(SpeciesBatch bean) { - return null; - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeNode.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeNode.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeNode.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,152 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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.persistence.entities.data.SpeciesBatch; - -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeNode; -import java.io.Serializable; - -/** - * Defines a node of a species catches. - * <p/> - * UserObject is the {@link SpeciesBatch}. It can be null on two cases: - * <ul> - * <li>On root node</li> - * <li>For node on a path of sampling but with no filled data </li> - * </ul> - * - * @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 samplingPropertyKey; - - /** - * Property value defining the sampling. - * <p/> - * <strong>Note:</strong> can be null (only for root node). - * - * @since 0.2 - */ - protected final Serializable samplingPropertyValue; - - public SpeciesBatchTreeNode() { - this(null, null, null); - } - - public SpeciesBatchTreeNode(SpeciesBatch userObject, - String samplingPropertyKey, - Serializable samplingPropertyValue) { - this.samplingPropertyKey = samplingPropertyKey; - this.samplingPropertyValue = samplingPropertyValue; - setUserObject(userObject); - } - - public String getSamplingPropertyKey() { - return samplingPropertyKey; - } - - public Serializable getSamplingPropertyValue() { - return samplingPropertyValue; - } - - @Override - public SpeciesBatch getUserObject() { - return (SpeciesBatch) super.getUserObject(); - } - - @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(); - } - -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css 2012-12-11 14:29:06 UTC (rev 41) @@ -1,85 +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; -} - -#totalWeightLabel { - text: "tutti.label.species.totalWeight"; - labelFor: {totalWeightField}; -} - -#totalWeightField { - property: "totalWeight"; - model: {model.getTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#totalVracWeightLabel { - text: "tutti.label.species.totalVracWeight"; - labelFor: {totalVracWeightField}; -} - -#totalVracWeightField { - property: "totalVracWeight"; - model: {model.getTotalVracWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#sampleVracWeightLabel { - text: "tutti.label.species.sampleVracWeight"; - labelFor: {sampleVracWeightField}; -} - -#sampleVracWeightField { - property: "sampleVracWeight"; - model: {model.getSampleVracWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; -} - -#totalHorsVracWeightLabel { - text: "tutti.label.species.totalHorsVracWeight"; - labelFor: {totalHorsVracWeightField}; -} - -#totalHorsVracWeightField { - property: "totalHorsVracWeight"; - model: {model.getTotalHorsVracWeight()}; - 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/catches/species/SpeciesTabUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx 2012-12-11 14:29:06 UTC (rev 41) @@ -1,118 +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<SpeciesTabUIModel, SpeciesTabUIHandler>'> - - <import> - fr.ifremer.tutti.persistence.entities.data.FishingOperation - - fr.ifremer.tutti.ui.swing.TuttiUIContext - fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI - fr.ifremer.tutti.ui.swing.content.catches.species.frequency.SpeciesFrequencyUI - - 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._ - </import> - - <script><![CDATA[ - -public SpeciesTabUI(FishingOperationsUI parentUI) { - SpeciesTabUIHandler handler = new SpeciesTabUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -public void selectFishingOperation(FishingOperation fishingOperation) { handler.selectFishingOperation(fishingOperation); } - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <SpeciesTabUIHandler id='handler' - initializer='getContextValue(SpeciesTabUIHandler.class)'/> - - <SpeciesTabUIModel id='model' - initializer='getContextValue(SpeciesTabUIModel.class)'/> - - <SwingValidatorMessageTableModel id='errorTableModel'/> - - <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' - uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='totalWeight' component='totalWeightField'/> - <field name='totalVracWeight' component='totalVracWeightField'/> - <field name='sampleVracWeight' component='sampleVracWeightField'/> - <field name='totalHorsVracWeight' component='totalHorsVracWeightField'/> - </BeanValidator> - - <SpeciesFrequencyUI id='frequencyUI' constructorParams='handler.getContext()'/> - - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> - - <!-- Poids total / Poids total vrac --> - <row> - <cell anchor='west'> - <JLabel id='totalWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='totalWeightField' constructorParams='this'/> - </cell> - <cell anchor='west'> - <JLabel id='totalVracWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='totalVracWeightField' constructorParams='this'/> - </cell> - </row> - - <!-- Poids échantillonné vrac / Poids total hors vrac --> - <row> - <cell> - <JLabel id='sampleVracWeightLabel'/> - </cell> - <cell> - <NumberEditor id='sampleVracWeightField' constructorParams='this'/> - </cell> - <cell> - <JLabel id='totalHorsVracWeightLabel'/> - </cell> - <cell> - <NumberEditor id='totalHorsVracWeightField' constructorParams='this'/> - </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/catches/species/SpeciesTabUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,393 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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.TuttiEntities; -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.data.VracHorsVracEnum; -import fr.ifremer.tutti.persistence.entities.referential.Sex; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.WeightCategory; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.ui.swing.TuttiUI; -import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; -import fr.ifremer.tutti.ui.swing.content.catches.species.frequency.SpeciesFrequencyRowModel; -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.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 org.nuiton.util.beans.BeanMonitor; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.table.TableColumnModel; -import java.awt.Color; -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesTabUIHandler extends AbstractTuttiTableUIHandler<SpeciesBatchRowModel, SpeciesTabUIModel> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(SpeciesTabUIHandler.class); - - private final SpeciesTabUI ui; - - private final FishingOperationsUI parentUi; - - private final PersistenceService persistenceService; - - private final BeanMonitor traitMonitor; - - public SpeciesTabUIHandler(FishingOperationsUI parentUi, SpeciesTabUI ui) { - super(parentUi.getHandler().getContext(), - SpeciesBatchRowModel.PROPERTY_SPECIES, - SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, - SpeciesBatchRowModel.PROPERTY_VRAC_HORS_VRAC, - SpeciesBatchRowModel.PROPERTY_WEIGHT_CATEGORY, - SpeciesBatchRowModel.PROPERTY_SEX, - SpeciesBatchRowModel.PROPERTY_MATURITY, - SpeciesBatchRowModel.PROPERTY_AGE, - SpeciesBatchRowModel.PROPERTY_WEIGHT, - SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, - SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO, - SpeciesBatchRowModel.PROPERTY_COMMENT, - SpeciesBatchRowModel.PROPERTY_FREQUENCY); - this.ui = ui; - this.parentUi = parentUi; - this.persistenceService = context.getService(PersistenceService.class); - traitMonitor = new BeanMonitor( - SpeciesTabUIModel.PROPERTY_SAMPLE_VRAC_WEIGHT, - SpeciesTabUIModel.PROPERTY_TOTAL_HORS_VRAC_WEIGHT, - SpeciesTabUIModel.PROPERTY_TOTAL_VRAC_WEIGHT, - SpeciesTabUIModel.PROPERTY_TOTAL_WEIGHT - ); - } - - @Override - protected JXTable getTable() { - return ui.getTable(); - } - - @Override - protected SpeciesBatchTableModel getTableModel() { - return (SpeciesBatchTableModel) getTable().getModel(); - } - - @Override - protected SpeciesTabUIModel getModel() { - return ui.getModel(); - } - - @Override - public void beforeInitUI() { - - SpeciesTabUIModel model = new SpeciesTabUIModel(); - ui.setContextValue(model); - - traitMonitor.setBean(model); - } - - @Override - public void afterInitUI() { - - initUI(ui); - - JXTable table = getTable(); - - // create table column model - TableColumnModel columnModel = createTableColumnModel(); - - // create table model - SpeciesBatchTableModel tableModel = - new SpeciesBatchTableModel(columnModel); - - 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(); - - // save when row chaged and was modified - listenRowModification(table); - - // always scroll to selected row - SwingUtil.scrollToTableSelection(getTable()); - } - - @Override - public void onCloseUI() { - } - - @Override - protected void saveRow(SpeciesBatchRowModel row) { - SpeciesBatch catchBean = row.toBean(); - - FishingOperation fishingOperation = getModel().getTrait(); - 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); - } - - public void selectFishingOperation(FishingOperation bean) { - - JXTable table = ui.getTable(); - - if (table.isEditing()) { - - // make sure to stop editor - table.editingCanceled(null); - } - - if (traitMonitor.wasModified()) { - - // previous fishingOperation was modified, let's save it - SpeciesTabUIModel traitMonitorBean = - (SpeciesTabUIModel) traitMonitor.getBean(); - - FishingOperation fishingOperation = traitMonitorBean.toBean(); - - if (log.isInfoEnabled()) { - log.info("FishingOperation " + fishingOperation.getId() + - " was modified, will save it."); - } - - persistenceService.saveFishingOperation(fishingOperation); - } - - // make sure selection is empty (will remove bean from monitor) - table.clearSelection(); - - boolean empty = bean == null; - - SpeciesTabUIModel model = getModel(); - - List<SpeciesBatchRowModel> rows; - - if (empty) { - rows = null; - bean = new FishingOperation(); - model.setTrait(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.setTrait(bean); - } - - model.fromBean(bean); - model.setRows(rows); - - listenModifcationOnFirstRow(); - - traitMonitor.clearModified(); - } - - @Override - protected TableColumnModel createTableColumnModel() { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - { // Species to confirm - - addBooleanColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_TO_CONFIRM, - getTable()); - } - - List<Species> allSpecies = persistenceService.getAllSpecies(); - - { // Species (by code) - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_CODE); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_BY_CODE, - decorator, allSpecies); - } - - { // Species (by genusCode) - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_GENUS); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_BY_GENUS_CODE, - decorator, allSpecies); - - } - - { // Vrac / Hors vrac - - addComboEnumColumnToModel(columnModel, - SpeciesBatchTableModel.VRAC_HORS_VRAC, - VracHorsVracEnum.values()); - } - - { // Catégorie de poids - - Decorator<WeightCategory> decorator = - getDecorator(WeightCategory.class, - DecoratorService.BY_NAME); - - List<WeightCategory> data = - persistenceService.getAllWeightCategory(); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.WEIGHT_CATEGORY, - decorator, data); - } - - { // Sex - - Decorator<Sex> decorator = - getDecorator(Sex.class, DecoratorService.BY_NAME); - - List<Sex> data = persistenceService.getAllSex(); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SEX, - decorator, data); - } - - { // Maturity - - addFloatColumnToModel(columnModel, - SpeciesBatchTableModel.MATURITY, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Age - - addFloatColumnToModel(columnModel, - SpeciesBatchTableModel.AGE, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Poids observé - - addFloatColumnToModel(columnModel, - SpeciesBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Poids calculé - - addColumnToModel(columnModel, - FrequencyCellComponent.newEditor(ui.getFrequencyUI()), - FrequencyCellComponent.newRender(), - SpeciesBatchTableModel.COMPUTED_WEIGHT); - } - - { // Nombre calculé - - addColumnToModel(columnModel, - FrequencyCellComponent.newEditor(ui.getFrequencyUI()), - FrequencyCellComponent.newRender(), - SpeciesBatchTableModel.COMPUTED_NUMBER); - } - - { // Poids d'échantillon - - addColumnToModel(columnModel, - SpeciesBatchTableModel.SAMPLE_WEIGHT); - } - - { // Fraction d'élévation - - addColumnToModel(columnModel, - SpeciesBatchTableModel.ELEVATION_RATIO); - } - - { // Commentaire - - addColumnToModel(columnModel, - SpeciesBatchTableModel.COMMENT); - } - - { // Pièces-jointes - - addColumnToModel(columnModel, - SpeciesBatchTableModel.FILE); - } - return columnModel; - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -1,130 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.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.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesTabUIModel extends AbstractTuttiTableUIModel<FishingOperation, SpeciesBatchRowModel, SpeciesTabUIModel> { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; - - public static final String PROPERTY_TOTAL_VRAC_WEIGHT = "totalVracWeight"; - - public static final String PROPERTY_SAMPLE_VRAC_WEIGHT = "sampleVracWeight"; - - public static final String PROPERTY_TOTAL_HORS_VRAC_WEIGHT = "totalHorsVracWeight"; - - protected FishingOperation trait; - - protected Float totalWeight; - - protected Float totalVracWeight; - - protected Float sampleVracWeight; - - protected Float totalHorsVracWeight; - - protected static final Binder<FishingOperation, SpeciesTabUIModel> fromBeanBinder = BinderModelBuilder.newEmptyBuilder(FishingOperation.class, SpeciesTabUIModel.class) - .addProperty("speciesTotalWeight", PROPERTY_TOTAL_WEIGHT) - .addProperty("speciesTotalHorsVracWeight", PROPERTY_TOTAL_HORS_VRAC_WEIGHT) - .addProperty("speciesTotalVracWeight", PROPERTY_TOTAL_VRAC_WEIGHT) - .addProperty("speciesSampleVracWeight", PROPERTY_SAMPLE_VRAC_WEIGHT) - .addProperty("id", PROPERTY_ID) - .toBinder(); - - protected static final Binder<SpeciesTabUIModel, FishingOperation> toBeanBinder = BinderModelBuilder.newEmptyBuilder(SpeciesTabUIModel.class, FishingOperation.class) - .addProperty(PROPERTY_TOTAL_WEIGHT, "speciesTotalWeight") - .addProperty(PROPERTY_TOTAL_HORS_VRAC_WEIGHT, "speciesTotalHorsVracWeight") - .addProperty(PROPERTY_TOTAL_VRAC_WEIGHT, "speciesTotalVracWeight") - .addProperty(PROPERTY_SAMPLE_VRAC_WEIGHT, "speciesSampleVracWeight") - .toBinder(); - - public SpeciesTabUIModel() { - super(FishingOperation.class, fromBeanBinder, toBeanBinder); - } - - public FishingOperation getTrait() { - return trait; - } - - public void setTrait(FishingOperation trait) { - this.trait = trait; - } - - public Float getTotalWeight() { - return totalWeight; - } - - public void setTotalWeight(Float totalWeight) { - Object oldValue = getTotalWeight(); - this.totalWeight = totalWeight; - firePropertyChange(PROPERTY_TOTAL_WEIGHT, oldValue, totalWeight); - } - - public Float getTotalVracWeight() { - return totalVracWeight; - } - - public void setTotalVracWeight(Float totalVracWeight) { - Object oldValue = getTotalVracWeight(); - this.totalVracWeight = totalVracWeight; - firePropertyChange(PROPERTY_TOTAL_VRAC_WEIGHT, oldValue, totalVracWeight); - } - - public Float getSampleVracWeight() { - return sampleVracWeight; - } - - public void setSampleVracWeight(Float sampleVracWeight) { - Object oldValue = getSampleVracWeight(); - this.sampleVracWeight = sampleVracWeight; - firePropertyChange(PROPERTY_SAMPLE_VRAC_WEIGHT, oldValue, sampleVracWeight); - } - - public Float getTotalHorsVracWeight() { - return totalHorsVracWeight; - } - - public void setTotalHorsVracWeight(Float totalHorsVracWeight) { - Object oldValue = getTotalHorsVracWeight(); - this.totalHorsVracWeight = totalHorsVracWeight; - firePropertyChange(PROPERTY_TOTAL_HORS_VRAC_WEIGHT, oldValue, totalHorsVracWeight); - } - - @Override - protected FishingOperation newEntity() { - return trait; - } - -} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUI.jaxx 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUI.jaxx 2012-12-11 14:29:06 UTC (rev 41) @@ -26,7 +26,7 @@ <import> fr.ifremer.tutti.ui.swing.TuttiUIContext - fr.ifremer.tutti.ui.swing.content.catches.species.SpeciesBatchRowModel + fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesBatchRowModel jaxx.runtime.swing.CardLayout2Ext jaxx.runtime.swing.editor.bean.BeanComboBox Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIHandler.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIHandler.java 2012-12-11 14:29:06 UTC (rev 41) @@ -27,7 +27,7 @@ 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.content.catches.species.SpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.SwingUtil; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIModel.java 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/frequency/SpeciesFrequencyUIModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -24,7 +24,7 @@ * #L% */ -import fr.ifremer.tutti.ui.swing.content.catches.species.SpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; /** Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx 2012-12-11 14:19:11 UTC (rev 40) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx 2012-12-11 14:29:06 UTC (rev 41) @@ -32,7 +32,7 @@ fr.ifremer.tutti.ui.swing.content.catches.benthos.BenthosTabUI fr.ifremer.tutti.ui.swing.content.catches.macrodechet.MacroDechetTabUI fr.ifremer.tutti.ui.swing.content.catches.plancton.PlanctonTabUI - fr.ifremer.tutti.ui.swing.content.catches.species.SpeciesTabUI + fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesTabUI jaxx.runtime.swing.editor.bean.BeanComboBox Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/FrequencyCellComponent.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/FrequencyCellComponent.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,256 @@ +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.content.catches.species.frequency.SpeciesFrequencyUI; +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); + } + + @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/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/species/SpeciesBatchRowModel.java (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchRowModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,379 @@ +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.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.VracHorsVracEnum; +import fr.ifremer.tutti.persistence.entities.referential.Sex; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.WeightCategory; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.content.catches.species.frequency.SpeciesFrequencyRowModel; +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_VRAC_HORS_VRAC = "vracHorsVrac"; + + public static final String PROPERTY_WEIGHT_CATEGORY = "weightCategory"; + + public static final String PROPERTY_SEX = "sex"; + + public static final String PROPERTY_MATURITY = "maturity"; + + 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"; + + /** + * 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 VracHorsVracEnum vracHorsVrac; + + /** + * Weight category (can be null). + * + * @since 0.2 + */ + protected WeightCategory weightCategory; + + /** + * Sex (can be null). + * + * @since 0.2 + */ + protected Sex sex; + + /** + * Maturity (can be null). + * + * @since 0.2 + */ + protected Float maturity; + + /** + * 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; + + /** + * Elevation ratio. + * + * @since 0.2 + */ + protected Float samplingRatio; + + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + + /** + * 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 VracHorsVracEnum getVracHorsVrac() { + return vracHorsVrac; + } + + public void setVracHorsVrac(VracHorsVracEnum vracHorsVrac) { + Object oldValue = getVracHorsVrac(); + this.vracHorsVrac = vracHorsVrac; + firePropertyChange(PROPERTY_VRAC_HORS_VRAC, oldValue, vracHorsVrac); + } + + public WeightCategory getWeightCategory() { + return weightCategory; + } + + public void setWeightCategory(WeightCategory weightCategory) { + Object oldValue = getWeightCategory(); + this.weightCategory = weightCategory; + firePropertyChange(PROPERTY_WEIGHT_CATEGORY, oldValue, weightCategory); + } + + public Sex getSex() { + return sex; + } + + public void setSex(Sex sex) { + Object oldValue = getSex(); + this.sex = sex; + firePropertyChange(PROPERTY_SEX, oldValue, sex); + } + + public Float getMaturity() { + return maturity; + } + + public void setMaturity(Float maturity) { + Object oldValue = getMaturity(); + this.maturity = maturity; + firePropertyChange(PROPERTY_MATURITY, oldValue, maturity); + } + + 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<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); + } + + //TODO Use validator + @Override + public boolean isValid() { + return species != null && weight != null; + } + + 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/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/species/SpeciesBatchTableModel.java (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,200 @@ +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_TO_CONFIRM = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + n_("tutti.table.species.batch.header.toConfirm"), + n_("tutti.table.species.batch.header.toConfirm")); + + 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> VRAC_HORS_VRAC = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_VRAC_HORS_VRAC, + n_("tutti.table.species.batch.header.vracHorsVrac"), + n_("tutti.table.species.batch.header.vracHorsVrac")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> WEIGHT_CATEGORY = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_WEIGHT_CATEGORY, + n_("tutti.table.species.batch.header.weightCategory"), + n_("tutti.table.species.batch.header.weightCategory")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> SEX = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_SEX, + n_("tutti.table.species.batch.header.sex"), + n_("tutti.table.species.batch.header.sex")); + + public static final ColumnIdentifier<SpeciesBatchRowModel> MATURITY = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_MATURITY, + n_("tutti.table.species.batch.header.maturity"), + n_("tutti.table.species.batch.header.maturity")); + + 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> ELEVATION_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> FILE = ColumnIdentifier.newId( + null, + n_("tutti.table.species.batch.header.file"), + n_("tutti.table.species.batch.header.file")); + + + protected final Set<ColumnIdentifier<SpeciesBatchRowModel>> noneEditableColIfNoSpecies; + + public SpeciesBatchTableModel(TableColumnModel columnModel) { + super(columnModel); + + // TODO This will be dynamic by the protocol... + setNoneEditableCols( + AGE, + MATURITY, + SAMPLE_WEIGHT, + ELEVATION_RATIO, + FILE + ); + noneEditableColIfNoSpecies = Sets.newHashSet(); + noneEditableColIfNoSpecies.add(COMPUTED_NUMBER); + noneEditableColIfNoSpecies.add(COMPUTED_WEIGHT); + } + + @Override + protected SpeciesBatchRowModel createNewRow() { + return new SpeciesBatchRowModel(); + } + + @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); + } + } + + @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/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/species/SpeciesBatchTreeModel.java (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,102 @@ +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.SpeciesBatch; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; + +import java.io.Serializable; +import java.util.List; + +/** + * @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 final String[] samplingOrder; + + /** + * Samplings view as a linear list (to display in the table). + * + * @since 0.2 + */ + protected final List<SpeciesBatchTreeNode> lines; + + public SpeciesBatchTreeModel(String... samplingOrder) { + this.samplingOrder = samplingOrder; + root = new SpeciesBatchTreeNode(); + lines = Lists.newArrayList(); + } + + public SpeciesBatchTreeNode getNode(int rowIndex) { + return lines.get(rowIndex); + } + + public int getSize() { + return lines.size(); + } + + public void populate(List<SpeciesBatch> data) { + + // clear tree representation + root.removeAllChildren(); + + // clear linear representation + lines.clear(); + } + + public Object[] getSamplingKey(SpeciesBatch bean) { + List<Object> result = Lists.newArrayList(); + for (String s : samplingOrder) { + Object property = TuttiUIUtil.getProperty(bean, s); + if (property == null) { + // stop findind sample key + break; + } + result.add(property); + } + return result.toArray(); + } + + public String[] getSamplingDefinition(SpeciesBatch bean) { + return null; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/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/species/SpeciesBatchTreeNode.java (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesBatchTreeNode.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTreeNode.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,152 @@ +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.persistence.entities.data.SpeciesBatch; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeNode; +import java.io.Serializable; + +/** + * Defines a node of a species catches. + * <p/> + * UserObject is the {@link SpeciesBatch}. It can be null on two cases: + * <ul> + * <li>On root node</li> + * <li>For node on a path of sampling but with no filled data </li> + * </ul> + * + * @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 samplingPropertyKey; + + /** + * Property value defining the sampling. + * <p/> + * <strong>Note:</strong> can be null (only for root node). + * + * @since 0.2 + */ + protected final Serializable samplingPropertyValue; + + public SpeciesBatchTreeNode() { + this(null, null, null); + } + + public SpeciesBatchTreeNode(SpeciesBatch userObject, + String samplingPropertyKey, + Serializable samplingPropertyValue) { + this.samplingPropertyKey = samplingPropertyKey; + this.samplingPropertyValue = samplingPropertyValue; + setUserObject(userObject); + } + + public String getSamplingPropertyKey() { + return samplingPropertyKey; + } + + public Serializable getSamplingPropertyValue() { + return samplingPropertyValue; + } + + @Override + public SpeciesBatch getUserObject() { + return (SpeciesBatch) super.getUserObject(); + } + + @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(); + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/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/species/SpeciesTabUI.css (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUI.css 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,85 @@ +/* + * #%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; +} + +#totalWeightLabel { + text: "tutti.label.species.totalWeight"; + labelFor: {totalWeightField}; +} + +#totalWeightField { + property: "totalWeight"; + model: {model.getTotalWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#totalVracWeightLabel { + text: "tutti.label.species.totalVracWeight"; + labelFor: {totalVracWeightField}; +} + +#totalVracWeightField { + property: "totalVracWeight"; + model: {model.getTotalVracWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#sampleVracWeightLabel { + text: "tutti.label.species.sampleVracWeight"; + labelFor: {sampleVracWeightField}; +} + +#sampleVracWeightField { + property: "sampleVracWeight"; + model: {model.getSampleVracWeight()}; + useFloat: false; + numberPattern: {INT_6_DIGITS_PATTERN}; +} + +#totalHorsVracWeightLabel { + text: "tutti.label.species.totalHorsVracWeight"; + labelFor: {totalHorsVracWeightField}; +} + +#totalHorsVracWeightField { + property: "totalHorsVracWeight"; + model: {model.getTotalHorsVracWeight()}; + 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/species/SpeciesTabUI.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/species/SpeciesTabUI.jaxx (from rev 40, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUI.jaxx 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,118 @@ +<!-- + #%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<SpeciesTabUIModel, SpeciesTabUIHandler>'> + + <import> + fr.ifremer.tutti.persistence.entities.data.FishingOperation + + fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI + fr.ifremer.tutti.ui.swing.content.catches.species.frequency.SpeciesFrequencyUI + + 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._ + </import> + + <script><![CDATA[ + +public SpeciesTabUI(FishingOperationsUI parentUI) { + SpeciesTabUIHandler handler = new SpeciesTabUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +public void selectFishingOperation(FishingOperation fishingOperation) { handler.selectFishingOperation(fishingOperation); } + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <SpeciesTabUIHandler id='handler' + initializer='getContextValue(SpeciesTabUIHandler.class)'/> + + <SpeciesTabUIModel id='model' + initializer='getContextValue(SpeciesTabUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='totalWeight' component='totalWeightField'/> + <field name='totalVracWeight' component='totalVracWeightField'/> + <field name='sampleVracWeight' component='sampleVracWeightField'/> + <field name='totalHorsVracWeight' component='totalHorsVracWeightField'/> + </BeanValidator> + + <SpeciesFrequencyUI id='frequencyUI' constructorParams='handler.getContext()'/> + + <Table id='form' fill='both' constraints='BorderLayout.NORTH'> + + <!-- Poids total / Poids total vrac --> + <row> + <cell anchor='west'> + <JLabel id='totalWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='totalWeightField' constructorParams='this'/> + </cell> + <cell anchor='west'> + <JLabel id='totalVracWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='totalVracWeightField' constructorParams='this'/> + </cell> + </row> + + <!-- Poids échantillonné vrac / Poids total hors vrac --> + <row> + <cell> + <JLabel id='sampleVracWeightLabel'/> + </cell> + <cell> + <NumberEditor id='sampleVracWeightField' constructorParams='this'/> + </cell> + <cell> + <JLabel id='totalHorsVracWeightLabel'/> + </cell> + <cell> + <NumberEditor id='totalHorsVracWeightField' constructorParams='this'/> + </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/species/SpeciesTabUI.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/species/SpeciesTabUIHandler.java (from rev 40, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIHandler.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,393 @@ +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.TuttiEntities; +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.data.VracHorsVracEnum; +import fr.ifremer.tutti.persistence.entities.referential.Sex; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.WeightCategory; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; +import fr.ifremer.tutti.ui.swing.content.catches.species.frequency.SpeciesFrequencyRowModel; +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.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 org.nuiton.util.beans.BeanMonitor; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.table.TableColumnModel; +import java.awt.Color; +import java.util.List; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesTabUIHandler extends AbstractTuttiTableUIHandler<SpeciesBatchRowModel, SpeciesTabUIModel> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SpeciesTabUIHandler.class); + + private final SpeciesTabUI ui; + + private final FishingOperationsUI parentUi; + + private final PersistenceService persistenceService; + + private final BeanMonitor traitMonitor; + + public SpeciesTabUIHandler(FishingOperationsUI parentUi, SpeciesTabUI ui) { + super(parentUi.getHandler().getContext(), + SpeciesBatchRowModel.PROPERTY_SPECIES, + SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, + SpeciesBatchRowModel.PROPERTY_VRAC_HORS_VRAC, + SpeciesBatchRowModel.PROPERTY_WEIGHT_CATEGORY, + SpeciesBatchRowModel.PROPERTY_SEX, + SpeciesBatchRowModel.PROPERTY_MATURITY, + SpeciesBatchRowModel.PROPERTY_AGE, + SpeciesBatchRowModel.PROPERTY_WEIGHT, + SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, + SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO, + SpeciesBatchRowModel.PROPERTY_COMMENT, + SpeciesBatchRowModel.PROPERTY_FREQUENCY); + this.ui = ui; + this.parentUi = parentUi; + this.persistenceService = context.getService(PersistenceService.class); + traitMonitor = new BeanMonitor( + SpeciesTabUIModel.PROPERTY_SAMPLE_VRAC_WEIGHT, + SpeciesTabUIModel.PROPERTY_TOTAL_HORS_VRAC_WEIGHT, + SpeciesTabUIModel.PROPERTY_TOTAL_VRAC_WEIGHT, + SpeciesTabUIModel.PROPERTY_TOTAL_WEIGHT + ); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected SpeciesBatchTableModel getTableModel() { + return (SpeciesBatchTableModel) getTable().getModel(); + } + + @Override + protected SpeciesTabUIModel getModel() { + return ui.getModel(); + } + + @Override + public void beforeInitUI() { + + SpeciesTabUIModel model = new SpeciesTabUIModel(); + ui.setContextValue(model); + + traitMonitor.setBean(model); + } + + @Override + public void afterInitUI() { + + initUI(ui); + + JXTable table = getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(); + + // create table model + SpeciesBatchTableModel tableModel = + new SpeciesBatchTableModel(columnModel); + + 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(); + + // save when row chaged and was modified + listenRowModification(table); + + // always scroll to selected row + SwingUtil.scrollToTableSelection(getTable()); + } + + @Override + public void onCloseUI() { + } + + @Override + protected void saveRow(SpeciesBatchRowModel row) { + SpeciesBatch catchBean = row.toBean(); + + FishingOperation fishingOperation = getModel().getTrait(); + 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); + } + + public void selectFishingOperation(FishingOperation bean) { + + JXTable table = ui.getTable(); + + if (table.isEditing()) { + + // make sure to stop editor + table.editingCanceled(null); + } + + if (traitMonitor.wasModified()) { + + // previous fishingOperation was modified, let's save it + SpeciesTabUIModel traitMonitorBean = + (SpeciesTabUIModel) traitMonitor.getBean(); + + FishingOperation fishingOperation = traitMonitorBean.toBean(); + + if (log.isInfoEnabled()) { + log.info("FishingOperation " + fishingOperation.getId() + + " was modified, will save it."); + } + + persistenceService.saveFishingOperation(fishingOperation); + } + + // make sure selection is empty (will remove bean from monitor) + table.clearSelection(); + + boolean empty = bean == null; + + SpeciesTabUIModel model = getModel(); + + List<SpeciesBatchRowModel> rows; + + if (empty) { + rows = null; + bean = new FishingOperation(); + model.setTrait(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.setTrait(bean); + } + + model.fromBean(bean); + model.setRows(rows); + + listenModifcationOnFirstRow(); + + traitMonitor.clearModified(); + } + + @Override + protected TableColumnModel createTableColumnModel() { + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + { // Species to confirm + + addBooleanColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_TO_CONFIRM, + getTable()); + } + + List<Species> allSpecies = persistenceService.getAllSpecies(); + + { // Species (by code) + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_CODE); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_BY_CODE, + decorator, allSpecies); + } + + { // Species (by genusCode) + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_GENUS); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_BY_GENUS_CODE, + decorator, allSpecies); + + } + + { // Vrac / Hors vrac + + addComboEnumColumnToModel(columnModel, + SpeciesBatchTableModel.VRAC_HORS_VRAC, + VracHorsVracEnum.values()); + } + + { // Catégorie de poids + + Decorator<WeightCategory> decorator = + getDecorator(WeightCategory.class, + DecoratorService.BY_NAME); + + List<WeightCategory> data = + persistenceService.getAllWeightCategory(); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.WEIGHT_CATEGORY, + decorator, data); + } + + { // Sex + + Decorator<Sex> decorator = + getDecorator(Sex.class, DecoratorService.BY_NAME); + + List<Sex> data = persistenceService.getAllSex(); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SEX, + decorator, data); + } + + { // Maturity + + addFloatColumnToModel(columnModel, + SpeciesBatchTableModel.MATURITY, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Age + + addFloatColumnToModel(columnModel, + SpeciesBatchTableModel.AGE, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Poids observé + + addFloatColumnToModel(columnModel, + SpeciesBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Poids calculé + + addColumnToModel(columnModel, + FrequencyCellComponent.newEditor(ui.getFrequencyUI()), + FrequencyCellComponent.newRender(), + SpeciesBatchTableModel.COMPUTED_WEIGHT); + } + + { // Nombre calculé + + addColumnToModel(columnModel, + FrequencyCellComponent.newEditor(ui.getFrequencyUI()), + FrequencyCellComponent.newRender(), + SpeciesBatchTableModel.COMPUTED_NUMBER); + } + + { // Poids d'échantillon + + addColumnToModel(columnModel, + SpeciesBatchTableModel.SAMPLE_WEIGHT); + } + + { // Fraction d'élévation + + addColumnToModel(columnModel, + SpeciesBatchTableModel.ELEVATION_RATIO); + } + + { // Commentaire + + addColumnToModel(columnModel, + SpeciesBatchTableModel.COMMENT); + } + + { // Pièces-jointes + + addColumnToModel(columnModel, + SpeciesBatchTableModel.FILE); + } + return columnModel; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIHandler.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/species/SpeciesTabUIModel.java (from rev 39, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIModel.java 2012-12-11 14:29:06 UTC (rev 41) @@ -0,0 +1,130 @@ +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.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderModelBuilder; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesTabUIModel extends AbstractTuttiTableUIModel<FishingOperation, SpeciesBatchRowModel, SpeciesTabUIModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; + + public static final String PROPERTY_TOTAL_VRAC_WEIGHT = "totalVracWeight"; + + public static final String PROPERTY_SAMPLE_VRAC_WEIGHT = "sampleVracWeight"; + + public static final String PROPERTY_TOTAL_HORS_VRAC_WEIGHT = "totalHorsVracWeight"; + + protected FishingOperation trait; + + protected Float totalWeight; + + protected Float totalVracWeight; + + protected Float sampleVracWeight; + + protected Float totalHorsVracWeight; + + protected static final Binder<FishingOperation, SpeciesTabUIModel> fromBeanBinder = BinderModelBuilder.newEmptyBuilder(FishingOperation.class, SpeciesTabUIModel.class) + .addProperty("speciesTotalWeight", PROPERTY_TOTAL_WEIGHT) + .addProperty("speciesTotalHorsVracWeight", PROPERTY_TOTAL_HORS_VRAC_WEIGHT) + .addProperty("speciesTotalVracWeight", PROPERTY_TOTAL_VRAC_WEIGHT) + .addProperty("speciesSampleVracWeight", PROPERTY_SAMPLE_VRAC_WEIGHT) + .addProperty("id", PROPERTY_ID) + .toBinder(); + + protected static final Binder<SpeciesTabUIModel, FishingOperation> toBeanBinder = BinderModelBuilder.newEmptyBuilder(SpeciesTabUIModel.class, FishingOperation.class) + .addProperty(PROPERTY_TOTAL_WEIGHT, "speciesTotalWeight") + .addProperty(PROPERTY_TOTAL_HORS_VRAC_WEIGHT, "speciesTotalHorsVracWeight") + .addProperty(PROPERTY_TOTAL_VRAC_WEIGHT, "speciesTotalVracWeight") + .addProperty(PROPERTY_SAMPLE_VRAC_WEIGHT, "speciesSampleVracWeight") + .toBinder(); + + public SpeciesTabUIModel() { + super(FishingOperation.class, fromBeanBinder, toBeanBinder); + } + + public FishingOperation getTrait() { + return trait; + } + + public void setTrait(FishingOperation trait) { + this.trait = trait; + } + + public Float getTotalWeight() { + return totalWeight; + } + + public void setTotalWeight(Float totalWeight) { + Object oldValue = getTotalWeight(); + this.totalWeight = totalWeight; + firePropertyChange(PROPERTY_TOTAL_WEIGHT, oldValue, totalWeight); + } + + public Float getTotalVracWeight() { + return totalVracWeight; + } + + public void setTotalVracWeight(Float totalVracWeight) { + Object oldValue = getTotalVracWeight(); + this.totalVracWeight = totalVracWeight; + firePropertyChange(PROPERTY_TOTAL_VRAC_WEIGHT, oldValue, totalVracWeight); + } + + public Float getSampleVracWeight() { + return sampleVracWeight; + } + + public void setSampleVracWeight(Float sampleVracWeight) { + Object oldValue = getSampleVracWeight(); + this.sampleVracWeight = sampleVracWeight; + firePropertyChange(PROPERTY_SAMPLE_VRAC_WEIGHT, oldValue, sampleVracWeight); + } + + public Float getTotalHorsVracWeight() { + return totalHorsVracWeight; + } + + public void setTotalHorsVracWeight(Float totalHorsVracWeight) { + Object oldValue = getTotalHorsVracWeight(); + this.totalHorsVracWeight = totalHorsVracWeight; + firePropertyChange(PROPERTY_TOTAL_HORS_VRAC_WEIGHT, oldValue, totalHorsVracWeight); + } + + @Override + protected FishingOperation newEntity() { + return trait; + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesTabUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.forge.codelutin.com