r126 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species: . split
Author: tchemit Date: 2012-12-29 15:56:58 +0100 (Sat, 29 Dec 2012) New Revision: 126 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/126 Log: refs #1805: [Onglet Poisson] Assistance ?\195?\160 la saisie des lots de poissons (package split) Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIModel.java Removed: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryEditor.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryRenderer.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java 2012-12-29 14:55:51 UTC (rev 125) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java 2012-12-29 14:56:58 UTC (rev 126) @@ -37,6 +37,13 @@ private static final long serialVersionUID = 1L; /** + * Sample category type. + * + * @since 0.3 + */ + protected SampleCategoryType categoryType; + + /** * Sample category value. * * @since 0.3 @@ -50,6 +57,23 @@ */ protected Float categoryWeight; + public static <C extends Serializable> SampleCategory<C> newSample(SampleCategoryType categoryType) { + SampleCategory<C> result = new SampleCategory<C>(); + result.setCategoryType(categoryType); + return result; + } + + protected SampleCategory() { + } + + public SampleCategoryType getCategoryType() { + return categoryType; + } + + public void setCategoryType(SampleCategoryType categoryType) { + this.categoryType = categoryType; + } + public C getCategoryValue() { return categoryValue; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java 2012-12-29 14:55:51 UTC (rev 125) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java 2012-12-29 14:56:58 UTC (rev 126) @@ -24,10 +24,23 @@ * #L% */ +import jaxx.runtime.swing.editor.NumberEditor; import org.nuiton.util.decorator.Decorator; +import javax.swing.AbstractCellEditor; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.io.Serializable; /** @@ -45,4 +58,178 @@ public static <C extends Serializable> TableCellEditor newEditor(Decorator<C> decorator) { return new SampleCategoryEditor<C>(decorator); } + + /** + * SampleCategory cell editor. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ + public static class SampleCategoryEditor<C extends Serializable> extends AbstractCellEditor + implements TableCellEditor, FocusListener, AncestorListener { + + private static final long serialVersionUID = 1L; + + protected final NumberEditor numberEditor; + + protected final JPanel editor; + + protected final JLabel editorLabel; + + protected final Decorator<C> categoryDecorator; + + public SampleCategoryEditor(Decorator<C> categoryDecorator) { + this.categoryDecorator = categoryDecorator; + numberEditor = new NumberEditor(); + numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); + numberEditor.getTextField().setBorder(null); + numberEditor.getTextField().addFocusListener(this); + numberEditor.getTextField().addAncestorListener(this); + numberEditor.setModelType(Float.class); + numberEditor.setUseSign(false); + numberEditor.init(); + + editor = new JPanel(new BorderLayout()); + editor.add(BorderLayout.WEST, editorLabel = new JLabel()); + editor.add(BorderLayout.CENTER, numberEditor); + } + + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + + SampleCategory<C> sampleCategory = (SampleCategory<C>) value; + + C categoryValue = sampleCategory == null ? null : sampleCategory.getCategoryValue(); + Float number = sampleCategory == null ? null : sampleCategory.getCategoryWeight(); + + numberEditor.setModel(number); + + // Check nullity and set the text that will be selected with the current value + if (number == null) { + numberEditor.setModelText(""); + } else { + numberEditor.setModelText(String.valueOf(number)); + } + + String label = sampleCategory == null ? "-" : + categoryDecorator.toString(categoryValue); + + editorLabel.setText(label); + return editor; + } + + @Override + public Float getCellEditorValue() { + return (Float) numberEditor.getModel(); + } + + @Override + public void focusGained(FocusEvent e) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + numberEditor.getTextField().requestFocus(); + numberEditor.getTextField().selectAll(); + } + }); + } + + @Override + public void focusLost(FocusEvent e) { + } + + @Override + public void ancestorAdded(AncestorEvent event) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + numberEditor.getTextField().requestFocus(); + numberEditor.getTextField().selectAll(); + } + }); + } + + @Override + public void ancestorRemoved(AncestorEvent event) { + } + + @Override + public void ancestorMoved(AncestorEvent event) { + } + + @Override + public boolean stopCellEditing() { + boolean result = super.stopCellEditing(); + // Reset previous data to avoid keeping it on other cell edition + if (result) { + resetEditor(); + } + return result; + } + + @Override + public void cancelCellEditing() { + resetEditor(); + super.cancelCellEditing(); + } + + protected void resetEditor() { + numberEditor.setModel(null); + // Use empty string, otherwise there is a NPE in NumberEditorHandler + numberEditor.setModelText(""); + editorLabel.setText("-"); + } + } + + /** + * To render a {@link SampleCategory} in a table cell. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ + public static class SampleCategoryRenderer<C extends Serializable> implements TableCellRenderer { + + protected final TableCellRenderer delegate; + + protected final Decorator<C> categoryDecorator; + + public SampleCategoryRenderer(TableCellRenderer delegate, + Decorator<C> categoryDecorator) { + this.delegate = delegate; + this.categoryDecorator = categoryDecorator; + } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + SampleCategory<C> sampleCategory = (SampleCategory<C>) value; + + String text = null; + if (sampleCategory != null) { + C categoryValue = sampleCategory.getCategoryValue(); + Float number = sampleCategory.getCategoryWeight(); + + text = categoryDecorator.toString(categoryValue) + " / "; + + if (number == null) { + text = "-"; + } else { + text += number; + } + } + + return delegate.getTableCellRendererComponent(table, + text, + isSelected, + hasFocus, + row, + column); + } + } } Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryEditor.java 2012-12-29 14:55:51 UTC (rev 125) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryEditor.java 2012-12-29 14:56:58 UTC (rev 126) @@ -1,167 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.catches.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import jaxx.runtime.swing.editor.NumberEditor; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.AbstractCellEditor; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.event.AncestorEvent; -import javax.swing.event.AncestorListener; -import javax.swing.table.TableCellEditor; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.io.Serializable; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since TODO - */ -public class SampleCategoryEditor<C extends Serializable> extends AbstractCellEditor - implements TableCellEditor, FocusListener, AncestorListener { - - private static final long serialVersionUID = 1L; - - protected final NumberEditor numberEditor; - - protected final JPanel editor; - - protected final JLabel editorLabel; - - protected final Decorator<C> categoryDecorator; - - public SampleCategoryEditor(Decorator<C> categoryDecorator) { - this.categoryDecorator = categoryDecorator; - numberEditor = new NumberEditor(); - numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); - numberEditor.getTextField().setBorder(null); - numberEditor.getTextField().addFocusListener(this); - numberEditor.getTextField().addAncestorListener(this); - numberEditor.setModelType(Float.class); - numberEditor.setUseSign(false); - numberEditor.init(); - - editor = new JPanel(new BorderLayout()); - editor.add(BorderLayout.WEST, editorLabel = new JLabel()); - editor.add(BorderLayout.CENTER, numberEditor); - } - - @Override - public Component getTableCellEditorComponent(JTable table, - Object value, - boolean isSelected, - int row, - int column) { - - SampleCategory<C> sampleCategory = (SampleCategory<C>) value; - - C categoryValue = sampleCategory == null ? null : sampleCategory.getCategoryValue(); - Float number = sampleCategory == null ? null : sampleCategory.getCategoryWeight(); - - numberEditor.setModel(number); - - // Check nullity and set the text that will be selected with the current value - if (number == null) { - numberEditor.setModelText(""); - } else { - numberEditor.setModelText(String.valueOf(number)); - } - - String label = sampleCategory == null ? "-" : - categoryDecorator.toString(categoryValue); - - editorLabel.setText(label); - return editor; - } - - @Override - public Float getCellEditorValue() { - return (Float) numberEditor.getModel(); - } - - @Override - public void focusGained(FocusEvent e) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - numberEditor.getTextField().requestFocus(); - numberEditor.getTextField().selectAll(); - } - }); - } - - @Override - public void focusLost(FocusEvent e) { - } - - @Override - public void ancestorAdded(AncestorEvent event) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - numberEditor.getTextField().requestFocus(); - numberEditor.getTextField().selectAll(); - } - }); - } - - @Override - public void ancestorRemoved(AncestorEvent event) { - } - - @Override - public void ancestorMoved(AncestorEvent event) { - } - - @Override - public boolean stopCellEditing() { - boolean result = super.stopCellEditing(); - // Reset previous data to avoid keeping it on other cell edition - if (result) { - resetEditor(); - } - return result; - } - - @Override - public void cancelCellEditing() { - resetEditor(); - super.cancelCellEditing(); - } - - protected void resetEditor() { - numberEditor.setModel(null); - // Use empty string, otherwise there is a NPE in NumberEditorHandler - numberEditor.setModelText(""); - editorLabel.setText("-"); - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryRenderer.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryRenderer.java 2012-12-29 14:55:51 UTC (rev 125) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryRenderer.java 2012-12-29 14:56:58 UTC (rev 126) @@ -1,82 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.catches.species; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.nuiton.util.decorator.Decorator; - -import javax.swing.JTable; -import javax.swing.table.TableCellRenderer; -import java.awt.Component; -import java.io.Serializable; - -/** - * To render a {@link SampleCategory} in a table cell. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class SampleCategoryRenderer<C extends Serializable> implements TableCellRenderer { - - protected final TableCellRenderer delegate; - - protected final Decorator<C> categoryDecorator; - - public SampleCategoryRenderer(TableCellRenderer delegate, - Decorator<C> categoryDecorator) { - this.delegate = delegate; - this.categoryDecorator = categoryDecorator; - } - - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - SampleCategory<C> sampleCategory = (SampleCategory<C>) value; - - String text = null; - if (sampleCategory != null) { - C categoryValue = sampleCategory.getCategoryValue(); - Float number = sampleCategory.getCategoryWeight(); - - text = categoryDecorator.toString(categoryValue) + " / "; - - if (number == null) { - text = "-"; - } else { - text += number; - } - } - - return delegate.getTableCellRendererComponent(table, - text, - isSelected, - hasFocus, - row, - column); - } -} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-29 14:55:51 UTC (rev 125) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-29 14:56:58 UTC (rev 126) @@ -142,142 +142,14 @@ // compute row valid for (SpeciesBatchRowModel row : rows) { - boolean rowValid = row.isRowValid(); + boolean rowValid = isRowValid(row); row.setValid(rowValid); } // build the new sampling tree from the new rows to edit // getModel().getSamplingTreeModel().populate(rows); } -// @Override -// protected String[] getRowPropertiesToIgnore() { -// return new String[]{ -// SpeciesBatchRowModel.PROPERTY_SAMPLE_WEIGHT, -// SpeciesBatchRowModel.PROPERTY_SAMPLING_RATIO}; -// } - @Override - protected TableColumnModel createTableColumnModel(TableCellRenderer defaultRenderer) { - - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); - - Decorator<CaracteristicQualitativeValue> caracteristicDecorator = - getDecorator(CaracteristicQualitativeValue.class, null); - - List<Species> allSpecies = persistenceService.getAllSpecies(); - - { // Species (by code) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_CODE); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_BY_CODE, - decorator, allSpecies); - } - - { // Species (by genusCode) column - - Decorator<Species> decorator = getDecorator( - Species.class, DecoratorService.SPECIES_BY_GENUS); - - addComboDataColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_BY_GENUS_CODE, - decorator, allSpecies); - } - - { // SortedUnsortedCategory column - - addSampleCategoryColumnToModel(columnModel, - SpeciesBatchTableModel.SORTED_UNSORTED_CATEGORY, - caracteristicDecorator, - defaultRenderer); - } - - { // SizeCategory column - - addSampleCategoryColumnToModel(columnModel, - SpeciesBatchTableModel.SIZE_CATEGORY, - caracteristicDecorator, - defaultRenderer); - } - - { // SexCategory column - - addSampleCategoryColumnToModel(columnModel, - SpeciesBatchTableModel.SEX_CATEGORY, - caracteristicDecorator, - defaultRenderer); - } - - { // MaturityCategory column - - addSampleCategoryColumnToModel(columnModel, - SpeciesBatchTableModel.MATURITY_CATEGORY, - caracteristicDecorator, - defaultRenderer); - } - - { // AgeCategory column - - addSampleCategoryColumnToModel(columnModel, - SpeciesBatchTableModel.AGE_CATEGORY, - getDecorator(Float.class, null), - defaultRenderer); - } - - { // Weight column - - addFloatColumnToModel(columnModel, - SpeciesBatchTableModel.WEIGHT, - TuttiUI.DECIMAL3_PATTERN); - } - - { // Computed weight column (from frequencies) - - addColumnToModel(columnModel, - FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), - FrequencyCellComponent.newRender(), - SpeciesBatchTableModel.COMPUTED_WEIGHT); - } - - { // Computed number column (from frequencies) - - addColumnToModel(columnModel, - FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), - FrequencyCellComponent.newRender(), - SpeciesBatchTableModel.COMPUTED_NUMBER); - } - - { // Comment column - - addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), - SpeciesBatchTableModel.COMMENT); - } - - { // File column - - addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - SpeciesBatchTableModel.ATTACHMENTS); - } - - { // Species to confirm column - - addBooleanColumnToModel(columnModel, - SpeciesBatchTableModel.SPECIES_TO_CONFIRM, - getTable()); - } - return columnModel; - } - - @Override protected void onRowModified(SpeciesBatchRowModel row, String propertyName, Object oldValue, @@ -295,14 +167,14 @@ if (SAMPLING_PROPERTIES.contains(propertyName)) { // species has changed, recompute valid property - boolean rowValid = row.isRowValid(); + boolean rowValid = isRowValid(row); row.setValid(rowValid); } if (SpeciesBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { // weight has changed, recompute valid property - boolean rowValid = row.isRowValid(); + boolean rowValid = isRowValid(row); row.setValid(rowValid); } @@ -444,13 +316,21 @@ @Override protected boolean isRowValid(SpeciesBatchRowModel row) { + boolean result = row.getSpecies() != null; + if (result) { + result = row.getWeight() != null; - SpeciesBatchUIModel model = getModel(); + if (!result) { - SpeciesBatchTreeModel samplingTreeModel = model.getSamplingTreeModel(); - SpeciesBatchTreeNode node = samplingTreeModel.getSamplingNode(row); - boolean rowValid = samplingTreeModel.isValid(row, node); - return row.isValid(); + // No weight filled, so at least one sample category must be valid + result = row.getSortedUnsortedSampleCategory().isValid() || + row.getSizeSampleCategory().isValid() || + row.getSexSampleCategory().isValid() || + row.getMaturitySampleCategory().isValid() || + row.getAgeSampleCategory().isValid(); + } + } + return result; } @Override @@ -574,8 +454,124 @@ JXTable table = getTable(); // create table column model - TableColumnModel columnModel = createTableColumnModel(table.getDefaultRenderer(Object.class)); + TableCellRenderer defaultRenderer = table.getDefaultRenderer(Object.class); + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + Decorator<CaracteristicQualitativeValue> caracteristicDecorator = + getDecorator(CaracteristicQualitativeValue.class, null); + + List<Species> allSpecies = persistenceService.getAllSpecies(); + + { // Species (by code) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_CODE); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_BY_CODE, + decorator, allSpecies); + } + + { // Species (by genusCode) column + + Decorator<Species> decorator = getDecorator( + Species.class, DecoratorService.SPECIES_BY_GENUS); + + addComboDataColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_BY_GENUS_CODE, + decorator, allSpecies); + } + + { // SortedUnsortedCategory column + + addSampleCategoryColumnToModel(columnModel, + SpeciesBatchTableModel.SORTED_UNSORTED_CATEGORY, + caracteristicDecorator, + defaultRenderer); + } + + { // SizeCategory column + + addSampleCategoryColumnToModel(columnModel, + SpeciesBatchTableModel.SIZE_CATEGORY, + caracteristicDecorator, + defaultRenderer); + } + + { // SexCategory column + + addSampleCategoryColumnToModel(columnModel, + SpeciesBatchTableModel.SEX_CATEGORY, + caracteristicDecorator, + defaultRenderer); + } + + { // MaturityCategory column + + addSampleCategoryColumnToModel(columnModel, + SpeciesBatchTableModel.MATURITY_CATEGORY, + caracteristicDecorator, + defaultRenderer); + } + + { // AgeCategory column + + addSampleCategoryColumnToModel(columnModel, + SpeciesBatchTableModel.AGE_CATEGORY, + getDecorator(Float.class, null), + defaultRenderer); + } + + { // Weight column + + addFloatColumnToModel(columnModel, + SpeciesBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + { // Computed weight column (from frequencies) + + addColumnToModel(columnModel, + FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), + FrequencyCellComponent.newRender(), + SpeciesBatchTableModel.COMPUTED_WEIGHT); + } + + { // Computed number column (from frequencies) + + addColumnToModel(columnModel, + FrequencyCellComponent.newEditor(ui.getFrequencyEditor()), + FrequencyCellComponent.newRender(), + SpeciesBatchTableModel.COMPUTED_NUMBER); + } + + { // Comment column + + addColumnToModel(columnModel, + LongTextCellComponent.newEditor(ui.getLongTextEditor()), + LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + SpeciesBatchTableModel.COMMENT); + } + + { // File column + + addColumnToModel(columnModel, + AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), + AttachmentCellComponent.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")), + SpeciesBatchTableModel.ATTACHMENTS); + } + + { // Species to confirm column + + addBooleanColumnToModel(columnModel, + SpeciesBatchTableModel.SPECIES_TO_CONFIRM, + getTable()); + } + // create table model SpeciesBatchTableModel tableModel = new SpeciesBatchTableModel(columnModel); Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryRowModel.java 2012-12-29 14:56:58 UTC (rev 126) @@ -0,0 +1,103 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategory; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.io.Serializable; + +/** + * A row in the {@link SplitSampleCategoryUIModel}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class SplitSampleCategoryRowModel extends AbstractTuttiBeanUIModel<SplitSampleCategoryRowModel, SplitSampleCategoryRowModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_CATEGORY_VALUE = "categoryValue"; + + public static final String PROPERTY_WEIGHT = "weight"; + + /** + * Delegate sample category which contains category value + weight. + * + * @since 0.3 + */ + protected final SampleCategory<Serializable> category = SampleCategory.newSample(null); + + protected static final Binder<SplitSampleCategoryRowModel, SplitSampleCategoryRowModel> fromBeanBinder = + BinderFactory.newBinder(SplitSampleCategoryRowModel.class, + SplitSampleCategoryRowModel.class); + + protected static final Binder<SplitSampleCategoryRowModel, SplitSampleCategoryRowModel> toBeanBinder = + BinderFactory.newBinder(SplitSampleCategoryRowModel.class, + SplitSampleCategoryRowModel.class); + + public SplitSampleCategoryRowModel() { + super(SplitSampleCategoryRowModel.class, fromBeanBinder, toBeanBinder); + } + + public SampleCategoryType getCategoryType() { + return category.getCategoryType(); + } + + public void setCategoryType(SampleCategoryType categoryType) { + category.setCategoryType(categoryType); + } + + public Float getCategoryValue() { + return category.getCategoryWeight(); + } + + public void setCategoryValue(Serializable categoryValue) { + Object oldValue = getCategoryValue(); + category.setCategoryValue(categoryValue); + firePropertyChange(PROPERTY_CATEGORY_VALUE, oldValue, categoryValue); + } + + + public Float getWeight() { + return category.getCategoryWeight(); + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + category.setCategoryWeight(weight); + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + //TODO Use validator + @Override + public boolean isValid() { + return category.isValid(); + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryTableModel.java 2012-12-29 14:56:58 UTC (rev 126) @@ -0,0 +1,73 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; + +import javax.swing.table.TableColumnModel; + +import static org.nuiton.i18n.I18n.n_; + +/** + * Table model of sample categories values. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class SplitSampleCategoryTableModel extends AbstractTuttiTableModel<SplitSampleCategoryRowModel> { + + private static final long serialVersionUID = 1L; + + public static final ColumnIdentifier<SplitSampleCategoryRowModel> CATEGORY_VALUE = ColumnIdentifier.newId( + SplitSampleCategoryRowModel.PROPERTY_CATEGORY_VALUE, + n_("tutti.table.species.sampleCategory.header.category"), + n_("tutti.table.species.sampleCategory.header.category")); + + public static final ColumnIdentifier<SplitSampleCategoryRowModel> WEIGHT = ColumnIdentifier.newId( + SplitSampleCategoryRowModel.PROPERTY_WEIGHT, + n_("tutti.table.species.sampleCategory.header.weight"), + n_("tutti.table.species.sampleCategory.header.weight")); + + private final SplitSampleCategoryUIModel uiModel; + + + public SplitSampleCategoryTableModel(TableColumnModel columnModel, + SplitSampleCategoryUIModel uiModel) { + super(columnModel); + this.uiModel = uiModel; + setNoneEditableCols(); + } + + @Override + protected SplitSampleCategoryRowModel createNewRow() { + + SplitSampleCategoryRowModel result = new SplitSampleCategoryRowModel(); + result.setCategoryType(uiModel.getSelectedCategory()); + result.setValid(false); + return result; + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css 2012-12-29 14:56:58 UTC (rev 126) @@ -0,0 +1,63 @@ +/* + * #%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% + */ + +BeanComboBox { + showReset: true; + i18nPrefix: "tutti.property."; + bean: {model}; +} + +#configurationPanel { + border: {new TitledBorder(null, _("tutti.legend.sampleCategoryConfiguration"))}; +} + +#categoryLabelLabel { + text: "tutti.label.sampleCategoryConfiguration.category"; + labelFor: {categoryComboBox}; +} + +#categoryComboBox { + property: "selectedCategory"; + selectedItem: {model.getSelectedCategory()}; +} + +#sampleCheckBox { + text: "tutti.label.sampleCategoryConfiguration.sample"; + selected: {model.isSample()}; +} + +#closeButton { + actionIcon: "close"; + text: "tutti.action.close"; + mnemonic: F; + enabled: {model.isValid()}; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; + enabled: {model.getSelectedCategory() != null} +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx 2012-12-29 14:56:58 UTC (rev 126) @@ -0,0 +1,106 @@ +<!-- + #%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<SplitSampleCategoryUIModel, SplitSampleCategoryUIHandler>'> + + <import> + fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType + fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI + + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + + org.jdesktop.swingx.JXTable + + jaxx.runtime.swing.editor.bean.BeanComboBox + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + + javax.swing.ListSelectionModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + static jaxx.runtime.SwingUtil.getStringValue + </import> + + <script><![CDATA[ + +public SplitSampleCategoryUI(SpeciesBatchUI parentUI) { + JAXXUtil.initContext(this, parentUI); + SplitSampleCategoryUIHandler handler = new SplitSampleCategoryUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <SplitSampleCategoryUIHandler id='handler' + initializer='getContextValue(SplitSampleCategoryUIHandler.class)'/> + + <SplitSampleCategoryUIModel id='model' + initializer='getContextValue(SplitSampleCategoryUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='category' component='categoryComboBox'/> + <field name='sample' component='sampleCheckBox'/> + </BeanValidator> + + <Table id='configurationPanel' fill='both' constraints='BorderLayout.NORTH'> + + <!-- SampleCategory choice --> + <row> + <cell anchor='west'> + <JLabel id='categoryLabel'/> + </cell> + <cell weightx='1.0'> + <BeanComboBox id='categoryComboBox' constructorParams='this' + genericType='SampleCategoryType'/> + </cell> + </row> + + <!-- Split as a sample or not ? --> + <row> + <cell columns='2'> + <JCheckBox id='sampleCheckBox' + onItemStateChanged='handler.setBoolean(event, "sample")'/> + </cell> + </row> + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table'/> + </JScrollPane> + + <!-- actions --> + <JPanel id='actionPanel' layout='{new GridLayout(1, 0)}' + constraints='BorderLayout.SOUTH'> + <JButton id='closeButton' onActionPerformed='handler.close()'/> + </JPanel> + +</JPanel> Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java 2012-12-29 14:56:58 UTC (rev 126) @@ -0,0 +1,373 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split; + +/* + * #%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.SampleCategoryEnum; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategory; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI; +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.decorator.Decorator; + +import javax.swing.JDialog; +import javax.swing.table.DefaultTableModel; +import java.awt.Color; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.List; + +/** + * Handler of {@link SplitSampleCategoryUI}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class SplitSampleCategoryUIHandler extends AbstractTuttiTableUIHandler<SplitSampleCategoryRowModel, SplitSampleCategoryUIModel> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SplitSampleCategoryUIHandler.class); + + /** + * Parent UI. + * + * @since 0.3 + */ + private final SpeciesBatchUI parentUi; + + /** + * UI. + * + * @since 0.3 + */ + private final SplitSampleCategoryUI ui; + + /** + * Persistence service. + * + * @since 0.3 + */ + protected final PersistenceService persistenceService; + + public SplitSampleCategoryUIHandler(SpeciesBatchUI parentUi, + SplitSampleCategoryUI ui) { + super(parentUi.getHandler().getContext(), + SplitSampleCategoryRowModel.PROPERTY_CATEGORY_VALUE, + SplitSampleCategoryRowModel.PROPERTY_WEIGHT); + this.parentUi = parentUi; + this.ui = ui; + this.persistenceService = getContext().getService(PersistenceService.class); + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + protected SplitSampleCategoryUIModel getModel() { + return ui.getModel(); + } + + @Override + protected SplitSampleCategoryTableModel getTableModel() { + return (SplitSampleCategoryTableModel) getTable().getModel(); + } + + @Override + protected JXTable getTable() { + return ui.getTable(); + } + + @Override + protected void onRowModified(SplitSampleCategoryRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + if (SplitSampleCategoryRowModel.PROPERTY_WEIGHT.equals(propertyName)) { + + // Need to recompute the total weight + computeComputedWeight(row); + } + } + + @Override + protected void onRowValidStateChanged(SplitSampleCategoryRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected void onRowModifyStateChanged(SplitSampleCategoryRowModel row, + Boolean oldValue, + Boolean newValue) { + } + + @Override + protected boolean isRowValid(SplitSampleCategoryRowModel row) { + //TODO + return true; + } + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public void beforeInitUI() { + + SplitSampleCategoryUIModel model = new SplitSampleCategoryUIModel(); + + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + initUI(ui); + + SplitSampleCategoryUIModel model = getModel(); + + //TODO Use protocol to have lengthStepCaracteristic to use (if any protocol) + initBeanComboBox(ui.getCategoryComboBox(), + Lists.<SampleCategoryType>newArrayList(), + model.getSelectedCategory()); + + JXTable table = getTable(); + + 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(); + + // always scroll to selected row + SwingUtil.scrollToTableSelection(getTable()); + + // when category changed, remove selected category + model.addPropertyChangeListener(SplitSampleCategoryUIModel.PROPERTY_CATEGORY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + getModel().setSelectedCategory(null); + } + }); + + // when selected category changed, regenerate the table model + add inside some default rows + model.addPropertyChangeListener(SplitSampleCategoryUIModel.PROPERTY_SELECTED_CATEGORY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + SampleCategoryEnum newValue = (SampleCategoryEnum) evt.getNewValue(); + generateTableModel(newValue); + } + }); + } + + @Override + public void onCloseUI() { + } + + //------------------------------------------------------------------------// + //-- Public methods --// + //------------------------------------------------------------------------// + + public void editBatch(SpeciesBatchRowModel row) { + + // get possible the last used + List<SampleCategoryType> categories = + Lists.newArrayList(SampleCategoryType.values()); + + //TODO Use the samplingOrder + SampleCategory<?> lastCategory = null; + + if (row.getSortedUnsortedSampleCategory().isValid()) { + categories.remove(SampleCategoryType.sortedUnsorted); + lastCategory = row.getSortedUnsortedSampleCategory(); + } + + if (row.getSizeSampleCategory().isValid()) { + categories.remove(SampleCategoryType.size); + lastCategory = row.getSizeSampleCategory(); + } + + if (row.getSexSampleCategory().isValid()) { + categories.remove(SampleCategoryType.sex); + lastCategory = row.getSexSampleCategory(); + } + + if (row.getMaturitySampleCategory().isValid()) { + categories.remove(SampleCategoryType.maturity); + lastCategory = row.getMaturitySampleCategory(); + } + + if (row.getAgeSampleCategory().isValid()) { + categories.remove(SampleCategoryType.age); + lastCategory = row.getAgeSampleCategory(); + } + + Float batchWeight = lastCategory == null ? null : + lastCategory.getCategoryWeight(); + + SplitSampleCategoryUIModel model = getModel(); + + model.setCategory(categories); + + model.setBatchWeight(batchWeight); + + // keep batch (will be used to push back editing entry) + model.setBatch(row); + } + + public void close() { + + if (log.isInfoEnabled()) { + log.info("Will close UI " + ui); + } + + SplitSampleCategoryUIModel model = getModel(); + + // transfer rows to editor + List<SplitSampleCategoryRowModel> safeRows = Lists.newArrayList(); + for (SplitSampleCategoryRowModel row : model.getRows()) { + if (row.isValid()) { + + // can keep this row + safeRows.add(row); + } + } + + if (log.isInfoEnabled()) { + log.info("Push back " + safeRows.size() + + " rows to batch " + model.getBatch()); + } + //TODO Create rows in batch table model + + editBatch(null); + + SwingUtil.getParentContainer(ui, JDialog.class).setVisible(false); + } + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void computeComputedWeight(SplitSampleCategoryRowModel row) { + + if (log.isInfoEnabled()) { + log.info("Will recompute computed weight for frequency: " + row); + } + } + + + protected void generateTableModel(SampleCategoryEnum category) { + + if (category == null) { + + getTable().setModel(new DefaultTableModel()); + } else { + + Decorator<CaracteristicQualitativeValue> caracteristicDecorator = + getDecorator(CaracteristicQualitativeValue.class, null); + + Caracteristic data = null; + + DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); + + switch (category) { + + case sortedUnsorted: + data = persistenceService.getSortedUnsortedCaracteristic(); + break; + case size: + data = persistenceService.getSizeCategoryCaracteristic(); + break; + case sex: + data = persistenceService.getSexCaracteristic(); + break; + case maturity: + data = persistenceService.getMaturityCaracteristic(); + break; + case age: + addFloatColumnToModel(columnModel, + SplitSampleCategoryTableModel.CATEGORY_VALUE, + TuttiUI.DECIMAL1_PATTERN); + break; + } + + if (data != null) { + + addComboDataColumnToModel(columnModel, + SplitSampleCategoryTableModel.CATEGORY_VALUE, + caracteristicDecorator, + data.getQualitativeValue()); + } + { // Weight + + addFloatColumnToModel(columnModel, + SplitSampleCategoryTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + + // create table model + SplitSampleCategoryTableModel tableModel = + new SplitSampleCategoryTableModel(columnModel, getModel()); + + JXTable table = getTable(); + + table.setModel(tableModel); + table.setColumnModel(columnModel); + + //TODO Fix this! +// installTableKeyListener(columnModel, table); + + if (data != null) { + + // add a row for each qualitive value + for (CaracteristicQualitativeValue qualitativeValue : data.getQualitativeValue()) { + SplitSampleCategoryRowModel newRow = tableModel.createNewRow(); + newRow.setCategoryValue(qualitativeValue); + tableModel.addNewRow(tableModel.getRowCount(), newRow); + } + } + } + + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIModel.java 2012-12-29 14:56:58 UTC (rev 126) @@ -0,0 +1,157 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategoryType; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; + +import java.util.List; + +/** + * Model of {@link SplitSampleCategoryUI}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class SplitSampleCategoryUIModel extends AbstractTuttiTableUIModel<SpeciesBatchRowModel, SplitSampleCategoryRowModel, SplitSampleCategoryUIModel> { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_CATEGORY = "category"; + + public static final String PROPERTY_SAMPLE = "sample"; + + public static final String PROPERTY_SELECTED_CATEGORY = "selectedCategory"; + + public static final String PROPERTY_BATCH_WEIGHT = "batchWeight"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + + /** + * Batch which fires the editor. + * + * @since 0.3 + */ + protected SpeciesBatchRowModel batch; + + /** + * Sample categories. + * + * @since 0.3 + */ + protected List<SampleCategoryType> category; + + /** + * Selected Sample category. + * + * @since 0.3 + */ + protected SampleCategoryType selectedCategory; + + /** + * Flag when the batch to split is a sample. + * + * @since 0.3 + */ + protected boolean sample; + + /** + * Incoming batch weight to split. + * + * @since 0.3 + */ + protected Float batchWeight; + + + /** + * Sample weight of split batches. + * + * @since 0.3 + */ + protected Float sampleWeight; + + public SplitSampleCategoryUIModel() { + super(SpeciesBatchRowModel.class, null, null); + } + + public SpeciesBatchRowModel getBatch() { + return batch; + } + + public void setBatch(SpeciesBatchRowModel batch) { + this.batch = batch; + } + + public List<SampleCategoryType> getCategory() { + return category; + } + + public void setCategory(List<SampleCategoryType> category) { + Object oldValue = getCategory(); + this.category = category; + firePropertyChange(PROPERTY_CATEGORY, oldValue, category); + } + + public SampleCategoryType getSelectedCategory() { + return selectedCategory; + } + + public void setSelectedCategory(SampleCategoryType selectedCategory) { + Object oldValue = getSelectedCategory(); + this.selectedCategory = selectedCategory; + firePropertyChange(PROPERTY_SELECTED_CATEGORY, oldValue, selectedCategory); + } + + public boolean isSample() { + return sample; + } + + public void setSample(boolean sample) { + Object oldValue = isSample(); + this.sample = sample; + firePropertyChange(PROPERTY_SAMPLE, oldValue, sample); + } + + public Float getBatchWeight() { + return batchWeight; + } + + public void setBatchWeight(Float batchWeight) { + Object oldValue = getBatchWeight(); + this.batchWeight = batchWeight; + firePropertyChange(PROPERTY_BATCH_WEIGHT, oldValue, batchWeight); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSampleCategoryUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.forge.codelutin.com