r1188 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol tutti-ui-swing/src/main/filtered-resources tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/s
Author: tchemit Date: 2013-09-18 18:47:50 +0200 (Wed, 18 Sep 2013) New Revision: 1188 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1188 Log: refs #3280: [CAPTURE] ?\195?\160 la cr?\195?\169ation d'un lot, scanner le protocole et proposer la cat?\195?\169gorisation du protocole Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SelectedCategoryAble.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIModel.java 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/create/CreateSpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel-error-validation.xml trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel-error-validation.xml trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -360,6 +360,30 @@ } /** + * Retrieve the speciesProtocol corresponding to the species of the given protocol. + * + * @param protocol + * @param species + * @return + * @since 2.5 + */ + public static SpeciesProtocol getSpeciesProtocol(TuttiProtocol protocol, Species species) { + return getSpeciesProtocol(species, protocol.getSpecies()); + } + + /** + * Retrieve the benthosProtocol corresponding to the species of the given protocol. + * + * @param protocol + * @param species + * @return + * @since 2.5 + */ + public static SpeciesProtocol getBenthosProtocol(TuttiProtocol protocol, Species species) { + return getSpeciesProtocol(species, protocol.getBenthos()); + } + + /** * Retrieve the speciesprotocol corresponding to the species of the batch * * @param species Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-09-18 16:47:50 UTC (rev 1188) @@ -1,5 +1,5 @@ #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Wed Sep 18 14:22:16 CEST 2013 +#Wed Sep 18 18:37:46 CEST 2013 tutti.config.help=config.html tutti.createAccidentalBatch.action.cancel.help=editFishingOperation.html\#captureCapturesAccidentellesActions tutti.createAccidentalBatch.action.save.help=editFishingOperation.html\#captureCapturesAccidentellesActions @@ -16,7 +16,9 @@ tutti.createBenthosBatch.action.saveAndContinue.help=editFishingOperation.html\#captureBenthosActions tutti.createBenthosBatch.field.batchCount.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.batchWeight.help=editFishingOperation.html\#captureBenthosFields +tutti.createBenthosBatch.field.categoryField.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.sampleCategory.help=editFishingOperation.html\#captureBenthosFields +tutti.createBenthosBatch.field.sampleWeightField.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.sortedUnsortedCategory.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.species.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.help=editFishingOperation.html\#captureBenthos @@ -40,7 +42,9 @@ tutti.createSpeciesBatch.action.saveAndContinue.help=editFishingOperation.html\#captureEspecesCreeLotActions tutti.createSpeciesBatch.field.batchCount.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.batchWeight.help=editFishingOperation.html\#captureEspecesCreeLotFields +tutti.createSpeciesBatch.field.categoryField.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.sampleCategory.help=editFishingOperation.html\#captureEspecesCreeLotFields +tutti.createSpeciesBatch.field.sampleWeightField.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.sortedUnsortedCategory.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.species.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.help=editFishingOperation.html\#captureEspecesCreeLot @@ -211,12 +215,12 @@ tutti.editProtocol.field.vesselUseFeature.help=editProtocol.html\#fieldsCaracteristics tutti.editProtocol.help=editProtocol.html tutti.editProtocol.pane.caracteristic.help=editProtocol.html\#fieldsCaracteristics -tutti.editSampleCategoryModel.action.cancel.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.close.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.moveDownEntry.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.moveUpEntry.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.removeEntry.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.save.help=editSampleCategory.html#actions +tutti.editSampleCategoryModel.action.cancel.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.close.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.moveDownEntry.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.moveUpEntry.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.removeEntry.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.save.help=editSampleCategory.html\#actions tutti.editSampleCategoryModel.help=editSampleCategory.html tutti.editSpeciesBatch.action.createBatch.help=editFishingOperation.html\#captureEspecesActions tutti.editSpeciesBatch.action.createMelag.help=editFishingOperation.html\#captureEspecesActions Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-09-18 16:47:50 UTC (rev 1188) @@ -1,5 +1,5 @@ #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Wed Sep 18 14:22:16 CEST 2013 +#Wed Sep 18 18:37:46 CEST 2013 tutti.config.help=config.html tutti.createAccidentalBatch.action.cancel.help=editFishingOperation.html\#captureCapturesAccidentellesActions tutti.createAccidentalBatch.action.save.help=editFishingOperation.html\#captureCapturesAccidentellesActions @@ -16,7 +16,9 @@ tutti.createBenthosBatch.action.saveAndContinue.help=editFishingOperation.html\#captureBenthosActions tutti.createBenthosBatch.field.batchCount.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.batchWeight.help=editFishingOperation.html\#captureBenthosFields +tutti.createBenthosBatch.field.categoryField.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.sampleCategory.help=editFishingOperation.html\#captureBenthosFields +tutti.createBenthosBatch.field.sampleWeightField.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.sortedUnsortedCategory.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.field.species.help=editFishingOperation.html\#captureBenthosFields tutti.createBenthosBatch.help=editFishingOperation.html\#captureBenthos @@ -40,7 +42,9 @@ tutti.createSpeciesBatch.action.saveAndContinue.help=editFishingOperation.html\#captureEspecesCreeLotActions tutti.createSpeciesBatch.field.batchCount.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.batchWeight.help=editFishingOperation.html\#captureEspecesCreeLotFields +tutti.createSpeciesBatch.field.categoryField.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.sampleCategory.help=editFishingOperation.html\#captureEspecesCreeLotFields +tutti.createSpeciesBatch.field.sampleWeightField.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.sortedUnsortedCategory.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.field.species.help=editFishingOperation.html\#captureEspecesCreeLotFields tutti.createSpeciesBatch.help=editFishingOperation.html\#captureEspecesCreeLot @@ -211,12 +215,12 @@ tutti.editProtocol.field.vesselUseFeature.help=editProtocol.html\#fieldsCaracteristics tutti.editProtocol.help=editProtocol.html tutti.editProtocol.pane.caracteristic.help=editProtocol.html\#fieldsCaracteristics -tutti.editSampleCategoryModel.action.cancel.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.close.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.moveDownEntry.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.moveUpEntry.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.removeEntry.help=editSampleCategory.html#actions -tutti.editSampleCategoryModel.action.save.help=editSampleCategory.html#actions +tutti.editSampleCategoryModel.action.cancel.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.close.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.moveDownEntry.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.moveUpEntry.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.removeEntry.help=editSampleCategory.html\#actions +tutti.editSampleCategoryModel.action.save.help=editSampleCategory.html\#actions tutti.editSampleCategoryModel.help=editSampleCategory.html tutti.editSpeciesBatch.action.createBatch.help=editFishingOperation.html\#captureEspecesActions tutti.editSpeciesBatch.action.createMelag.help=editFishingOperation.html\#captureEspecesActions Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SelectedCategoryAble.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SelectedCategoryAble.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SelectedCategoryAble.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -0,0 +1,14 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; + +/** + * When a model offers a selected category. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.5 + */ +public interface SelectedCategoryAble { + + SampleCategoryModelEntry getSelectedCategory(); +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SelectedCategoryAble.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -53,7 +53,6 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchUI; -import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; @@ -656,6 +655,15 @@ // update speciesUsed addToSpeciesUsed(newRow); + + if (batchRootRowModel.getSelectedCategory() != null) { + + // add first category + splitBatch(batchRootRowModel.getSelectedCategory(), + batchRootRowModel.getRows(), + batchRootRowModel.getSampleWeight() + ); + } } recomputeBatchActionEnable(); @@ -721,63 +729,63 @@ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class); SplitBenthosBatchUI splitBatchEditor = parent.getBenthosTabSplitBatch(); -// splitBatchEditor.getHandler().editBatch(parentBatch); -// parent.getHandler().setBenthosSelectedCard(EditCatchesUIHandler.SPLIT_BATCH_CARD); parent.getHandler().splitBenthosBatch(parentBatch, splitBatchEditor); } } - public void splitBatch(SplitBenthosBatchUIModel splitModel) { - if (splitModel.isValid()) { + public void splitBatch(SampleCategoryModelEntry sampleCategoryDef, + List<SplitBenthosBatchRowModel> rows, + Float totalRowWeight) { - JXTable table = getTable(); + JXTable table = getTable(); - // get selected row - int insertRow = table.getSelectedRow(); + // get selected row + int insertRow = table.getSelectedRow(); - BenthosBatchTableModel tableModel = getTableModel(); - BenthosBatchRowModel parentBatch = tableModel.getEntry(insertRow); + BenthosBatchTableModel tableModel = getTableModel(); + BenthosBatchRowModel parentBatch = tableModel.getEntry(insertRow); - // create batch rows + // Create rows in batch table model + Float parentWeight = parentBatch.getFinestCategory().getNotNullWeight(); + boolean subSample = parentWeight != null && totalRowWeight != null + && parentWeight > totalRowWeight; - SampleCategoryModelEntry sampleCategoryDef = splitModel.getSelectedCategory(); + List<BenthosBatchRowModel> newBatches = Lists.newArrayList(); + for (SplitBenthosBatchRowModel row : rows) { + if (row.isValid()) { - // Create rows in batch table model + // can keep this row + BenthosBatchRowModel newBatch = tableModel.createNewRow(); - List<BenthosBatchRowModel> newBatches = Lists.newArrayList(); - for (SplitBenthosBatchRowModel row : splitModel.getRows()) { - if (row.isValid()) { + loadBatchRow(parentBatch, + newBatch, + sampleCategoryDef.getCategoryId(), + row.getCategoryValue(), + row.getWeight(), + null); - // can keep this row - BenthosBatchRowModel newBatch = tableModel.createNewRow(); + newBatch.getFinestCategory().setSubSample(subSample); - loadBatchRow(parentBatch, - newBatch, - sampleCategoryDef.getCategoryId(), - row.getCategoryValue(), - row.getWeight(), - null); + recomputeRowValidState(newBatch); + newBatches.add(newBatch); - recomputeRowValidState(newBatch); - newBatches.add(newBatch); - - tableModel.addNewRow(++insertRow, newBatch); - } + tableModel.addNewRow(++insertRow, newBatch); } + } - // add new batches to his parent - parentBatch.setChildBatch(newBatches); + // add new batches to his parent + parentBatch.setChildBatch(newBatches); - //TODO Should only save parentBatch (will persist all his childs) - //saveRow(parentBatch); + //TODO Should only save parentBatch (will persist all his childs) + //saveRow(parentBatch); - // save new batches - saveRows(newBatches); + // save new batches + saveRows(newBatches); - BenthosBatchUIModel model = getModel(); - model.setLeafNumber(model.getLeafNumber() + newBatches.size() - 1); - } + BenthosBatchUIModel model = getModel(); + model.setLeafNumber(model.getLeafNumber() + newBatches.size() - 1); + recomputeBatchActionEnable(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.css 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.css 2013-09-18 16:47:50 UTC (rev 1188) @@ -51,6 +51,10 @@ data: {model.getAvailableSpecies()}; } +#categoryPanel { + visible: {model.getSpecies() != null}; +} + #sampleCategoryLabel { text: "tutti.createBenthosBatch.field.sampleCategory"; toolTipText: "tutti.createBenthosBatch.field.sampleCategory.tip"; @@ -93,6 +97,38 @@ bean: {model}; } +#categoryLabel { + text: "tutti.createBenthosBatch.field.category"; + toolTipText: "tutti.createBenthosBatch.field.categoryField.tip"; + labelFor: {categoryComboBox}; + _help: {"tutti.createBenthosBatch.field.categoryField.help"}; +} + +#categoryComboBox { + selectedItem: {model.getSelectedCategory()}; +} + +#sampleWeightLabel { + text: "tutti.createBenthosBatch.field.sampleWeight"; + toolTipText: "tutti.createBenthosBatch.field.sampleWeightField.tip"; + labelFor: {sampleWeightField}; + _help: {"tutti.createBenthosBatch.field.sampleWeightField.help"}; +} + +#sampleWeightField { + editable: false; + enabled: false; + text: {getStringValue(model.getSampleWeight())}; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; + enabled: {model.getSelectedCategory() != null} +} + #addSpeciesButton { text: "tutti.createBenthosBatch.action.addSpecies"; toolTipText: "tutti.createBenthosBatch.action.addSpecies.tip"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.jaxx 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUI.jaxx 2013-09-18 16:47:50 UTC (rev 1188) @@ -28,6 +28,7 @@ <import> fr.ifremer.tutti.persistence.entities.referential.Species fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue + fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry fr.ifremer.tutti.ui.swing.TuttiHelpBroker fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI @@ -39,6 +40,7 @@ jaxx.runtime.swing.editor.NumberEditor java.awt.Color + javax.swing.ListSelectionModel static org.nuiton.i18n.I18n._ static jaxx.runtime.SwingUtil.getStringValue @@ -68,12 +70,15 @@ <field name='sampleCategory' component='sampleCategoryComboBox'/> <field name='batchWeight' component='batchWeightField'/> + <field name='batchCount' component='batchCountField'/> + <field name='selectedCategory' component='categoryComboBox'/> + <field name='sampleWeight' component='sampleWeightField'/> </BeanValidator> <TuttiHelpBroker id='broker' constructorParams='"tutti.createBenthosBatch.help"'/> - <Table id='configurationPanel' constraints='BorderLayout.CENTER' fill='both'> + <Table id='configurationPanel' constraints='BorderLayout.NORTH' fill='both'> <!-- Species --> <row> @@ -123,6 +128,44 @@ </Table> + <JPanel id='categoryPanel' constraints='BorderLayout.CENTER' + layout='{new BorderLayout()}'> + <Table id='categoryConfigurationPanel' constraints='BorderLayout.NORTH' + fill='both'> + <row> + <cell columns="2"> + <JSeparator/> + </cell> + </row> + + <!-- First SampleCategory choice --> + <row> + <cell anchor='west'> + <JLabel id='categoryLabel'/> + </cell> + <cell weightx='1.0'> + <JComboBox id='categoryComboBox' + onActionPerformed="model.setSelectedCategory((SampleCategoryModelEntry) categoryComboBox.getSelectedItem());"/> + </cell> + </row> + + <!-- Sample Total weight --> + <row> + <cell anchor='west'> + <JLabel id='sampleWeightLabel'/> + </cell> + <cell weightx='1.0'> + <JTextField id='sampleWeightField'/> + </cell> + </row> + + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table'/> + </JScrollPane> + </JPanel> + <!-- Form Actions --> <JPanel layout='{new GridLayout(1, 0)}' constraints='BorderLayout.SOUTH'> <JButton id='cancelButton' onActionPerformed='handler.cancel()'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -30,6 +30,9 @@ import fr.ifremer.tutti.persistence.TuttiPersistence; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -38,16 +41,23 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchUIModel; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchTableModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUIModel; import fr.ifremer.tutti.ui.swing.util.Cancelable; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUIModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.SwingUtil; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import javax.swing.DefaultComboBoxModel; import javax.swing.JComponent; import java.awt.Dimension; import java.beans.PropertyChangeEvent; @@ -60,7 +70,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.3 */ -public class CreateBenthosBatchUIHandler extends AbstractTuttiUIHandler<CreateBenthosBatchUIModel, CreateBenthosBatchUI> implements Cancelable { +public class CreateBenthosBatchUIHandler extends AbstractTuttiTableUIHandler<SplitBenthosBatchRowModel, CreateBenthosBatchUIModel, CreateBenthosBatchUI> implements Cancelable { /** Logger. */ private static final Log log = @@ -70,9 +80,13 @@ private final CaracteristicQualitativeValue sortedValue; + protected boolean categoryIsAdjusting; + public CreateBenthosBatchUIHandler(TuttiUI parentUi, CreateBenthosBatchUI ui) { - super(parentUi.getHandler().getContext(), ui); + super(parentUi.getHandler().getContext(), ui, + SplitBenthosBatchRowModel.PROPERTY_CATEGORY_VALUE, + SplitBenthosBatchRowModel.PROPERTY_WEIGHT); this.persistenceService = context.getPersistenceService(); SampleCategoryModel sampleCategoryModel = @@ -95,12 +109,66 @@ } //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public SplitBenthosBatchTableModel getTableModel() { + return (SplitBenthosBatchTableModel) getTable().getModel(); + } + + @Override + public JXTable getTable() { + return ui.getTable(); + } + + @Override + protected boolean isRowValid(SplitBenthosBatchRowModel row) { + return row.isValid(); + } + + @Override + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SplitBenthosBatchRowModel> rowMonitor, + SplitBenthosBatchRowModel row) { + if (rowMonitor.wasModified()) { + + if (row.isValid()) { + if (log.isInfoEnabled()) { + log.info("Change row that was modified and valid"); + } + } + + rowMonitor.clearModified(); + } + } + + @Override + protected void onRowModified(int rowIndex, + SplitBenthosBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + recomputeRowValidState(row); + + if (SplitBenthosBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { + + // Need to recompute the sample weight + computeSampleWeight(row); + } + } + + //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @Override public void beforeInitUI() { - CreateBenthosBatchUIModel model = new CreateBenthosBatchUIModel(); + + SampleCategoryModel sampleCategoryModel = + getDataContext().getSampleCategoryModel(); + CreateBenthosBatchUIModel model = + new CreateBenthosBatchUIModel(sampleCategoryModel); ui.setContextValue(model); listModelIsModify(model); } @@ -122,7 +190,9 @@ Lists.newArrayList(caracteristic.getQualitativeValue()), null); - getModel().addPropertyChangeListener(CreateBenthosBatchUIModel.PROPERTY_SPECIES, new PropertyChangeListener() { + CreateBenthosBatchUIModel model = getModel(); + + model.addPropertyChangeListener(CreateBenthosBatchUIModel.PROPERTY_SPECIES, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -136,11 +206,15 @@ if (newValue == null || source.getSpeciesUsed() == null) { + // reste V/HV category source.setSampleCategory(null); + // reset categories + source.setCategory(null); + } else { - // look for best value : if sorted is available then use it + // look for best value for V/HV category : if sorted is available then use it List<CaracteristicQualitativeValue> qualitativeValues = ui.getSampleCategoryComboBox().getData(); @@ -157,11 +231,134 @@ } } source.setSampleCategory(newCategory); + + // recompute possible categories + List<SampleCategoryModelEntry> categories = Lists.newArrayList(); + + SampleCategoryModel sampleCategoryModel = + getModel().getSampleCategoryModel(); + + // add all categories + categories.addAll(sampleCategoryModel.getCategory()); + + // remove the first one (V/HV) + categories.remove(0); + + // reset selected category + if (log.isInfoEnabled()) { + log.info("Remove selected category before changing the categories..."); + } + source.setSelectedCategory(null); + + categoryIsAdjusting = true; + + try { + + // set universe of categories + if (log.isInfoEnabled()) { + log.info("Categories to use: " + categories); + } + + source.setCategory(categories); + + // force to remove the first selected value of the combo-box + ui.getCategoryComboBox().setSelectedItem(null); + } finally { + categoryIsAdjusting = false; + } + + // compute the selected sample category + + SampleCategoryModelEntry selectedCategory = null; + + if (getDataContext().isProtocolFilled()) { + + // try to find the first category from protocol + TuttiProtocol protocol = getDataContext().getProtocol(); + SpeciesProtocol speciesProtocol = TuttiProtocols.getBenthosProtocol(protocol, newValue); + if (speciesProtocol != null) { + + // species defined in protocol + if (speciesProtocol.sizeMandatorySampleCategoryId() > 1) { + + // use the second category (the first one is V/HV) + Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(1); + selectedCategory = sampleCategoryModel.getCategoryById(categoryId); + if (log.isInfoEnabled()) { + log.info("Use category from protocol: " + categoryId + " :: " + selectedCategory); + } + } + } + } + + if (selectedCategory == null) { + + // by default use the first one + selectedCategory = categories.get(0); + + if (log.isInfoEnabled()) { + log.info("Use default first category: " + selectedCategory); + } + } + + if (log.isInfoEnabled()) { + log.info("Selected category : " + selectedCategory); + } + ui.getCategoryComboBox().setSelectedItem(selectedCategory); } } }); - listenValidatorValid(ui.getValidator(), getModel()); + // when category changed, remove selected category + model.addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_CATEGORY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + +// CreateSpeciesBatchUIModel source = +// (CreateSpeciesBatchUIModel) evt.getSource(); + +// // unselect previous selected category +// source.setSelectedCategory(null); + + // fill comboBox with new list + List<SampleCategoryModelEntry> data = (List<SampleCategoryModelEntry>) evt.getNewValue(); + if (data == null) { + + ui.getCategoryComboBox().setModel(new DefaultComboBoxModel()); + } else { + ui.getCategoryComboBox().setModel(new DefaultComboBoxModel(data.toArray())); + } + } + }); + + // when selected category changed, regenerate the table model + add inside some default rows + model.addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_SELECTED_CATEGORY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + if (!categoryIsAdjusting) { + + // can change the selected category + CreateSpeciesBatchUIModel source = + (CreateSpeciesBatchUIModel) evt.getSource(); + + // when selected category change, sample total weight is reset + source.setSampleWeight(null); + + SampleCategoryModelEntry newValue = + (SampleCategoryModelEntry) evt.getNewValue(); + generateTableModel(newValue); + } + } + }); + + ui.getCategoryComboBox().setRenderer(newListCellRender(SampleCategoryModelEntry.class)); + + generateTableModel(null); + + initTable(getTable()); + + listenValidatorValid(ui.getValidator(), model); } @Override @@ -184,7 +381,6 @@ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class); parent.getHandler().setBenthosSelectedCard(EditCatchesUIHandler.MAIN_CARD); - } @Override @@ -280,4 +476,126 @@ return result; } + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void computeSampleWeight(SplitBenthosBatchRowModel row) { + + if (log.isInfoEnabled()) { + log.info("Will recompute sample weight from row: " + row); + } + + Float result = null; + List<SplitBenthosBatchRowModel> rows = getTableModel().getRows(); + for (SplitBenthosBatchRowModel rowModel : rows) { + Float weight = rowModel.getWeight(); + if (weight != null) { + if (result == null) { + result = 0f; + } + result += weight; + } + } + getModel().setSampleWeight(result); + } + + protected void generateTableModel(SampleCategoryModelEntry category) { + + if (log.isInfoEnabled()) { + log.info("Generate table model for category " + category); + } + // when generate a new table model, then reset previous rows from model + getModel().setRows(null); + + Caracteristic data = null; + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + { // Selection + + addBooleanColumnToModel(columnModel, + SplitBenthosBatchTableModel.SELECTED, + getTable()); + } + + boolean editableCategoryValue = false; + if (category != null) { + + if (!category.getCaracteristic().isQualitativeValueEmpty()) { + + // qualitative category + data = category.getCaracteristic(); + } else { + editableCategoryValue = true; + addFloatColumnToModel(columnModel, + SplitBenthosBatchTableModel.EDITABLE_CATEGORY_VALUE, + TuttiUI.DECIMAL1_PATTERN); + } + + if (data != null) { + + if (log.isInfoEnabled()) { + log.info("Got " + data.sizeQualitativeValue() + " qualitative data to add"); + } + addColumnToModel(columnModel, + null, + newTableCellRender(CaracteristicQualitativeValue.class), + SplitBenthosBatchTableModel.READ_ONLY_CATEGORY_VALUE); + } + { // Weight + + addFloatColumnToModel(columnModel, + SplitBenthosBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + } + + // create table model + SplitBenthosBatchTableModel tableModel = + new SplitBenthosBatchTableModel(columnModel, + getModel(), + editableCategoryValue); + + JXTable table = getTable(); + + // remove all listener on tables we could add before + uninstallTableSaveOnRowChangedSelectionListener(); + uninstallTableKeyListener(); + + if (log.isDebugEnabled()) { + log.debug("Install new table model " + tableModel); + } + table.setModel(tableModel); + table.setColumnModel(columnModel); + + // install table listeners + installTableSaveOnRowChangedSelectionListener(); + installTableKeyListener(columnModel, table); + + // fill datas + + List<SplitBenthosBatchRowModel> rows = Lists.newArrayList(); + + if (data != null) { + + // add a row for each qualitive value + for (CaracteristicQualitativeValue qualitativeValue : data.getQualitativeValue()) { + if (log.isDebugEnabled()) { + log.debug("Add QV: " + qualitativeValue); + } + SplitBenthosBatchRowModel newRow = tableModel.createNewRow(); + newRow.setCategoryValue(qualitativeValue); + rows.add(newRow); + } + } + + if (log.isDebugEnabled()) { + log.debug("Will add " + rows.size() + " rows in table model " + + "(can add a first empty row? " + editableCategoryValue + ")."); + } + + getModel().setRows(rows); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -26,10 +26,14 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SelectedCategoryAble; +import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUI; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,7 +45,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.3 */ -public class CreateBenthosBatchUIModel extends AbstractTuttiBeanUIModel<CreateBenthosBatchUIModel, CreateBenthosBatchUIModel> { +public class CreateBenthosBatchUIModel extends AbstractTuttiTableUIModel<CreateBenthosBatchUIModel, SplitBenthosBatchRowModel, CreateBenthosBatchUIModel> implements SelectedCategoryAble { private final static Log log = LogFactory.getLog(CreateBenthosBatchUIModel.class); @@ -57,6 +61,12 @@ public static final String PROPERTY_BATCH_COUNT = "batchCount"; + public static final String PROPERTY_CATEGORY = "category"; + + public static final String PROPERTY_SELECTED_CATEGORY = "selectedCategory"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + /** * All available species (sets by protocol). * @@ -88,21 +98,54 @@ /** * Batch count. * - * @since 0.3 + * @since 2.5 */ protected Integer batchCount; /** + * Sample categories. + * + * @since 2.5 + */ + protected List<SampleCategoryModelEntry> category; + + /** + * Selected Sample category. + * + * @since 2.5 + */ + protected SampleCategoryModelEntry selectedCategory; + + /** + * Sample weight of split batches. + * + * @since 2.5 + */ + protected Float sampleWeight; + + /** + * Model of sample categories. + * + * @since 2.5 + */ + protected SampleCategoryModel sampleCategoryModel; + + /** * Already used species by sample category. * * @since 0.3 */ protected final Multimap<CaracteristicQualitativeValue, Species> speciesUsed = ArrayListMultimap.create(); - public CreateBenthosBatchUIModel() { + public CreateBenthosBatchUIModel(SampleCategoryModel sampleCategoryModel) { super(CreateBenthosBatchUIModel.class, null, null); + this.sampleCategoryModel = sampleCategoryModel; } + public SampleCategoryModel getSampleCategoryModel() { + return sampleCategoryModel; + } + public List<Species> getAvailableSpecies() { if (log.isDebugEnabled()) { log.debug("getAvailableSpecies " + availableSpecies); @@ -160,6 +203,37 @@ firePropertyChange(PROPERTY_BATCH_COUNT, oldValue, batchCount); } + public List<SampleCategoryModelEntry> getCategory() { + return category; + } + + public void setCategory(List<SampleCategoryModelEntry> category) { + Object oldValue = getCategory(); + this.category = category; + firePropertyChange(PROPERTY_CATEGORY, oldValue, category); + } + + @Override + public SampleCategoryModelEntry getSelectedCategory() { + return selectedCategory; + } + + public void setSelectedCategory(SampleCategoryModelEntry selectedCategory) { + Object oldValue = getSelectedCategory(); + this.selectedCategory = selectedCategory; + firePropertyChange(PROPERTY_SELECTED_CATEGORY, oldValue, selectedCategory); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } + public Multimap<CaracteristicQualitativeValue, Species> getSpeciesUsed() { return speciesUsed; } @@ -178,6 +252,6 @@ @Override protected CreateBenthosBatchUIModel newEntity() { - return new CreateBenthosBatchUIModel(); + return new CreateBenthosBatchUIModel(sampleCategoryModel); } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchTableModel.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchTableModel.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -24,6 +24,7 @@ * #L% */ +import fr.ifremer.tutti.ui.swing.content.operation.catches.SelectedCategoryAble; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import org.jdesktop.swingx.table.TableColumnModelExt; @@ -61,10 +62,10 @@ n_("tutti.splitBenthosBatch.table.header.weight"), n_("tutti.splitBenthosBatch.table.header.weight")); - private final SplitBenthosBatchUIModel uiModel; + private final SelectedCategoryAble uiModel; public SplitBenthosBatchTableModel(TableColumnModelExt columnModel, - SplitBenthosBatchUIModel uiModel, + SelectedCategoryAble uiModel, boolean createEmptyRowIsEmpty) { super(columnModel, createEmptyRowIsEmpty, createEmptyRowIsEmpty); this.uiModel = uiModel; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -31,7 +31,6 @@ import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; @@ -301,7 +300,13 @@ } EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class); - parent.getBenthosTabContent().getHandler().splitBatch(getModel()); + SplitBenthosBatchUIModel model = getModel(); + if (model.isValid()) { + parent.getBenthosTabContent().getHandler().splitBatch( + model.getSelectedCategory(), + model.getRows(), + model.getSampleWeight()); + } // close dialog closeUI(ui); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIModel.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIModel.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -26,6 +26,7 @@ import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SelectedCategoryAble; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; @@ -38,7 +39,7 @@ * @since 0.3 */ public class SplitBenthosBatchUIModel - extends AbstractTuttiTableUIModel<BenthosBatchRowModel, SplitBenthosBatchRowModel, SplitBenthosBatchUIModel> { + extends AbstractTuttiTableUIModel<BenthosBatchRowModel, SplitBenthosBatchRowModel, SplitBenthosBatchUIModel> implements SelectedCategoryAble { private static final long serialVersionUID = 1L; @@ -106,6 +107,7 @@ firePropertyChange(PROPERTY_CATEGORY, oldValue, category); } + @Override public SampleCategoryModelEntry getSelectedCategory() { return selectedCategory; } 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 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -657,6 +657,15 @@ // update speciesUsed addToSpeciesUsed(newRow); + + if (batchRootRowModel.getSelectedCategory() != null) { + + // add first category + splitBatch(batchRootRowModel.getSelectedCategory(), + batchRootRowModel.getRows(), + batchRootRowModel.getSampleWeight() + ); + } } recomputeBatchActionEnable(); @@ -722,8 +731,6 @@ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class); SplitSpeciesBatchUI splitBatchEditor = parent.getSpeciesTabSplitBatch(); -// splitBatchEditor.getHandler().editBatch(parentBatch); -// parent.getHandler().setSpeciesSelectedCard(EditCatchesUIHandler.SPLIT_BATCH_CARD); parent.getHandler().splitSpeciesBatch(parentBatch, splitBatchEditor); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.css 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.css 2013-09-18 16:47:50 UTC (rev 1188) @@ -51,6 +51,10 @@ data: {model.getAvailableSpecies()}; } +#categoryPanel { + visible: {model.getSpecies() != null}; +} + #sampleCategoryLabel { text: "tutti.createSpeciesBatch.field.sampleCategory"; toolTipText: "tutti.createSpeciesBatch.field.sampleCategory.tip"; @@ -93,6 +97,38 @@ bean: {model}; } +#categoryLabel { + text: "tutti.createSpeciesBatch.field.category"; + toolTipText: "tutti.createSpeciesBatch.field.categoryField.tip"; + labelFor: {categoryComboBox}; + _help: {"tutti.createSpeciesBatch.field.categoryField.help"}; +} + +#categoryComboBox { + selectedItem: {model.getSelectedCategory()}; +} + +#sampleWeightLabel { + text: "tutti.createSpeciesBatch.field.sampleWeight"; + toolTipText: "tutti.createSpeciesBatch.field.sampleWeightField.tip"; + labelFor: {sampleWeightField}; + _help: {"tutti.createSpeciesBatch.field.sampleWeightField.help"}; +} + +#sampleWeightField { + editable: false; + enabled: false; + text: {getStringValue(model.getSampleWeight())}; +} + +#table { + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; + enabled: {model.getSelectedCategory() != null} +} + #addSpeciesButton { text: "tutti.createSpeciesBatch.action.addSpecies"; toolTipText: "tutti.createSpeciesBatch.action.addSpecies.tip"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx 2013-09-18 16:47:50 UTC (rev 1188) @@ -28,6 +28,7 @@ <import> fr.ifremer.tutti.persistence.entities.referential.Species fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue + fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry fr.ifremer.tutti.ui.swing.TuttiHelpBroker fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI @@ -39,6 +40,7 @@ jaxx.runtime.swing.editor.NumberEditor java.awt.Color + javax.swing.ListSelectionModel static org.nuiton.i18n.I18n._ static jaxx.runtime.SwingUtil.getStringValue @@ -68,12 +70,15 @@ <field name='sampleCategory' component='sampleCategoryComboBox'/> <field name='batchWeight' component='batchWeightField'/> + <field name='batchCount' component='batchCountField'/> + <field name='selectedCategory' component='categoryComboBox'/> + <field name='sampleWeight' component='sampleWeightField'/> </BeanValidator> <TuttiHelpBroker id='broker' constructorParams='"tutti.createSpeciesBatch.help"'/> - <Table id='configurationPanel' constraints='BorderLayout.CENTER' fill='both'> + <Table id='configurationPanel' constraints='BorderLayout.NORTH' fill='both'> <!-- Species --> <row> @@ -123,6 +128,44 @@ </Table> + <JPanel id='categoryPanel' constraints='BorderLayout.CENTER' + layout='{new BorderLayout()}'> + <Table id='categoryConfigurationPanel' constraints='BorderLayout.NORTH' + fill='both'> + <row> + <cell columns="2"> + <JSeparator/> + </cell> + </row> + + <!-- First SampleCategory choice --> + <row> + <cell anchor='west'> + <JLabel id='categoryLabel'/> + </cell> + <cell weightx='1.0'> + <JComboBox id='categoryComboBox' + onActionPerformed="model.setSelectedCategory((SampleCategoryModelEntry) categoryComboBox.getSelectedItem());"/> + </cell> + </row> + + <!-- Sample Total weight --> + <row> + <cell anchor='west'> + <JLabel id='sampleWeightLabel'/> + </cell> + <cell weightx='1.0'> + <JTextField id='sampleWeightField'/> + </cell> + </row> + + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table'/> + </JScrollPane> + </JPanel> + <!-- Form Actions --> <JPanel layout='{new GridLayout(1, 0)}' constraints='BorderLayout.SOUTH'> <JButton id='cancelButton' onActionPerformed='handler.cancel()'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -30,6 +30,9 @@ import fr.ifremer.tutti.persistence.TuttiPersistence; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -38,16 +41,22 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchTableModel; import fr.ifremer.tutti.ui.swing.util.Cancelable; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUIModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.SwingUtil; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import javax.swing.DefaultComboBoxModel; import javax.swing.JComponent; import java.awt.Dimension; import java.beans.PropertyChangeEvent; @@ -60,7 +69,8 @@ * @author tchemit <chemit@codelutin.com> * @since 0.3 */ -public class CreateSpeciesBatchUIHandler extends AbstractTuttiUIHandler<CreateSpeciesBatchUIModel, CreateSpeciesBatchUI> implements Cancelable { +public class CreateSpeciesBatchUIHandler extends + AbstractTuttiTableUIHandler<SplitSpeciesBatchRowModel, CreateSpeciesBatchUIModel, CreateSpeciesBatchUI> implements Cancelable { /** Logger. */ private static final Log log = @@ -70,9 +80,13 @@ private final CaracteristicQualitativeValue sortedValue; + protected boolean categoryIsAdjusting; + public CreateSpeciesBatchUIHandler(TuttiUI parentUi, CreateSpeciesBatchUI ui) { - super(parentUi.getHandler().getContext(), ui); + super(parentUi.getHandler().getContext(), ui, + SplitSpeciesBatchRowModel.PROPERTY_CATEGORY_VALUE, + SplitSpeciesBatchRowModel.PROPERTY_WEIGHT); this.persistenceService = context.getPersistenceService(); SampleCategoryModel sampleCategoryModel = @@ -90,17 +104,71 @@ break; } } - Preconditions.checkNotNull(vracValue,"Could not found vrac qualitative value"); + Preconditions.checkNotNull(vracValue, "Could not found vrac qualitative value"); sortedValue = vracValue; } //------------------------------------------------------------------------// + //-- AbstractTuttiTableUIHandler methods --// + //------------------------------------------------------------------------// + + @Override + public SplitSpeciesBatchTableModel getTableModel() { + return (SplitSpeciesBatchTableModel) getTable().getModel(); + } + + @Override + public JXTable getTable() { + return ui.getTable(); + } + + @Override + protected boolean isRowValid(SplitSpeciesBatchRowModel row) { + return row.isValid(); + } + + @Override + protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SplitSpeciesBatchRowModel> rowMonitor, + SplitSpeciesBatchRowModel row) { + if (rowMonitor.wasModified()) { + + if (row.isValid()) { + if (log.isInfoEnabled()) { + log.info("Change row that was modified and valid"); + } + } + + rowMonitor.clearModified(); + } + } + + @Override + protected void onRowModified(int rowIndex, + SplitSpeciesBatchRowModel row, + String propertyName, + Object oldValue, + Object newValue) { + + recomputeRowValidState(row); + + if (SplitSpeciesBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { + + // Need to recompute the sample weight + computeSampleWeight(row); + } + } + + //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @Override public void beforeInitUI() { - CreateSpeciesBatchUIModel model = new CreateSpeciesBatchUIModel(); + + SampleCategoryModel sampleCategoryModel = + getDataContext().getSampleCategoryModel(); + CreateSpeciesBatchUIModel model = + new CreateSpeciesBatchUIModel(sampleCategoryModel); ui.setContextValue(model); listModelIsModify(model); } @@ -122,7 +190,9 @@ caracteristic.getQualitativeValue(), null); - getModel().addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_SPECIES, new PropertyChangeListener() { + CreateSpeciesBatchUIModel model = getModel(); + + model.addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_SPECIES, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -136,11 +206,15 @@ if (newValue == null || source.getSpeciesUsed() == null) { + // reste V/HV category source.setSampleCategory(null); + // reset categories + source.setCategory(null); + } else { - // look for best value : if sorted is available then use it + // look for best value for V/HV category : if sorted is available then use it List<CaracteristicQualitativeValue> qualitativeValues = ui.getSampleCategoryComboBox().getData(); @@ -157,11 +231,134 @@ } } source.setSampleCategory(newCategory); + + // recompute possible categories + List<SampleCategoryModelEntry> categories = Lists.newArrayList(); + + SampleCategoryModel sampleCategoryModel = + getModel().getSampleCategoryModel(); + + // add all categories + categories.addAll(sampleCategoryModel.getCategory()); + + // remove the first one (V/HV) + categories.remove(0); + + // reset selected category + if (log.isInfoEnabled()) { + log.info("Remove selected category before changing the categories..."); + } + source.setSelectedCategory(null); + + categoryIsAdjusting = true; + + try { + + // set universe of categories + if (log.isInfoEnabled()) { + log.info("Categories to use: " + categories); + } + + source.setCategory(categories); + + // force to remove the first selected value of the combo-box + ui.getCategoryComboBox().setSelectedItem(null); + } finally { + categoryIsAdjusting = false; + } + + // compute the selected sample category + + SampleCategoryModelEntry selectedCategory = null; + + if (getDataContext().isProtocolFilled()) { + + // try to find the first category from protocol + TuttiProtocol protocol = getDataContext().getProtocol(); + SpeciesProtocol speciesProtocol = TuttiProtocols.getSpeciesProtocol(protocol, newValue); + if (speciesProtocol != null) { + + // species defined in protocol + if (speciesProtocol.sizeMandatorySampleCategoryId() > 1) { + + // use the second category (the first one is V/HV) + Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(1); + selectedCategory = sampleCategoryModel.getCategoryById(categoryId); + if (log.isInfoEnabled()) { + log.info("Use category from protocol: " + categoryId + " :: " + selectedCategory); + } + } + } + } + + if (selectedCategory == null) { + + // by default use the first one + selectedCategory = categories.get(0); + + if (log.isInfoEnabled()) { + log.info("Use default first category: " + selectedCategory); + } + } + + if (log.isInfoEnabled()) { + log.info("Selected category : " + selectedCategory); + } + ui.getCategoryComboBox().setSelectedItem(selectedCategory); } } }); - listenValidatorValid(ui.getValidator(), getModel()); + // when category changed, remove selected category + model.addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_CATEGORY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + +// CreateSpeciesBatchUIModel source = +// (CreateSpeciesBatchUIModel) evt.getSource(); + +// // unselect previous selected category +// source.setSelectedCategory(null); + + // fill comboBox with new list + List<SampleCategoryModelEntry> data = (List<SampleCategoryModelEntry>) evt.getNewValue(); + if (data == null) { + + ui.getCategoryComboBox().setModel(new DefaultComboBoxModel()); + } else { + ui.getCategoryComboBox().setModel(new DefaultComboBoxModel(data.toArray())); + } + } + }); + + // when selected category changed, regenerate the table model + add inside some default rows + model.addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_SELECTED_CATEGORY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + if (!categoryIsAdjusting) { + + // can change the selected category + CreateSpeciesBatchUIModel source = + (CreateSpeciesBatchUIModel) evt.getSource(); + + // when selected category change, sample total weight is reset + source.setSampleWeight(null); + + SampleCategoryModelEntry newValue = + (SampleCategoryModelEntry) evt.getNewValue(); + generateTableModel(newValue); + } + } + }); + + ui.getCategoryComboBox().setRenderer(newListCellRender(SampleCategoryModelEntry.class)); + + generateTableModel(null); + + initTable(getTable()); + + listenValidatorValid(ui.getValidator(), model); } @Override @@ -184,7 +381,6 @@ EditCatchesUI parent = SwingUtil.getParentContainer(ui, EditCatchesUI.class); parent.getHandler().setSpeciesSelectedCard(EditCatchesUIHandler.MAIN_CARD); - } @Override @@ -279,4 +475,127 @@ return result; } + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void computeSampleWeight(SplitSpeciesBatchRowModel row) { + + if (log.isInfoEnabled()) { + log.info("Will recompute sample weight from row: " + row); + } + + Float result = null; + List<SplitSpeciesBatchRowModel> rows = getTableModel().getRows(); + for (SplitSpeciesBatchRowModel rowModel : rows) { + Float weight = rowModel.getWeight(); + if (weight != null) { + if (result == null) { + result = 0f; + } + result += weight; + } + } + getModel().setSampleWeight(result); + } + + protected void generateTableModel(SampleCategoryModelEntry category) { + + if (log.isInfoEnabled()) { + log.info("Generate table model for category " + category); + } + // when generate a new table model, then reset previous rows from model + getModel().setRows(null); + + Caracteristic data = null; + + DefaultTableColumnModelExt columnModel = + new DefaultTableColumnModelExt(); + + { // Selection + + addBooleanColumnToModel(columnModel, + SplitSpeciesBatchTableModel.SELECTED, + getTable()); + } + + boolean editableCategoryValue = false; + if (category != null) { + + if (!category.getCaracteristic().isQualitativeValueEmpty()) { + + // qualitative category + data = category.getCaracteristic(); + } else { + editableCategoryValue = true; + addFloatColumnToModel(columnModel, + SplitSpeciesBatchTableModel.EDITABLE_CATEGORY_VALUE, + TuttiUI.DECIMAL1_PATTERN); + } + + if (data != null) { + + if (log.isInfoEnabled()) { + log.info("Got " + data.sizeQualitativeValue() + " qualitative data to add"); + } + addColumnToModel(columnModel, + null, + newTableCellRender(CaracteristicQualitativeValue.class), + SplitSpeciesBatchTableModel.READ_ONLY_CATEGORY_VALUE); + } + { // Weight + + addFloatColumnToModel(columnModel, + SplitSpeciesBatchTableModel.WEIGHT, + TuttiUI.DECIMAL3_PATTERN); + } + } + + // create table model + SplitSpeciesBatchTableModel tableModel = + new SplitSpeciesBatchTableModel(columnModel, + getModel(), + editableCategoryValue); + + JXTable table = getTable(); + + // remove all listener on tables we could add before + uninstallTableSaveOnRowChangedSelectionListener(); + uninstallTableKeyListener(); + + if (log.isDebugEnabled()) { + log.debug("Install new table model " + tableModel); + } + table.setModel(tableModel); + table.setColumnModel(columnModel); + + // install table listeners + installTableSaveOnRowChangedSelectionListener(); + installTableKeyListener(columnModel, table); + + // fill datas + + List<SplitSpeciesBatchRowModel> rows = Lists.newArrayList(); + + if (data != null) { + + // add a row for each qualitive value + for (CaracteristicQualitativeValue qualitativeValue : data.getQualitativeValue()) { + if (log.isDebugEnabled()) { + log.debug("Add QV: " + qualitativeValue); + } + SplitSpeciesBatchRowModel newRow = tableModel.createNewRow(); + newRow.setCategoryValue(qualitativeValue); + rows.add(newRow); + } + } + + if (log.isDebugEnabled()) { + log.debug("Will add " + rows.size() + " rows in table model " + + "(can add a first empty row? " + editableCategoryValue + ")."); + } + + getModel().setRows(rows); + } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -26,9 +26,13 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SelectedCategoryAble; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,9 +44,10 @@ * @author tchemit <chemit@codelutin.com> * @since 0.3 */ -public class CreateSpeciesBatchUIModel extends AbstractTuttiBeanUIModel<CreateSpeciesBatchUIModel, CreateSpeciesBatchUIModel> { +public class CreateSpeciesBatchUIModel extends AbstractTuttiTableUIModel<CreateSpeciesBatchUIModel, SplitSpeciesBatchRowModel, CreateSpeciesBatchUIModel> implements SelectedCategoryAble { - private final static Log log = LogFactory.getLog(CreateSpeciesBatchUIModel.class); + private final static Log log = + LogFactory.getLog(CreateSpeciesBatchUIModel.class); private static final long serialVersionUID = 1L; @@ -56,6 +61,12 @@ public static final String PROPERTY_BATCH_COUNT = "batchCount"; + public static final String PROPERTY_CATEGORY = "category"; + + public static final String PROPERTY_SELECTED_CATEGORY = "selectedCategory"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + /** * All available species (sets by protocol). * @@ -87,21 +98,54 @@ /** * Batch count. * - * @since 0.3 + * @since 2.5 */ protected Integer batchCount; /** + * Sample categories. + * + * @since 2.5 + */ + protected List<SampleCategoryModelEntry> category; + + /** + * Selected Sample category. + * + * @since 2.5 + */ + protected SampleCategoryModelEntry selectedCategory; + + /** + * Sample weight of split batches. + * + * @since 2.5 + */ + protected Float sampleWeight; + + /** + * Model of sample categories. + * + * @since 2.5 + */ + protected SampleCategoryModel sampleCategoryModel; + + /** * Already used species by sample category. * * @since 0.3 */ protected final Multimap<CaracteristicQualitativeValue, Species> speciesUsed = ArrayListMultimap.create(); - public CreateSpeciesBatchUIModel() { + public CreateSpeciesBatchUIModel(SampleCategoryModel sampleCategoryModel) { super(CreateSpeciesBatchUIModel.class, null, null); + this.sampleCategoryModel = sampleCategoryModel; } + public SampleCategoryModel getSampleCategoryModel() { + return sampleCategoryModel; + } + public List<Species> getAvailableSpecies() { if (log.isDebugEnabled()) { log.debug("getAvailableSpecies " + availableSpecies); @@ -159,6 +203,37 @@ firePropertyChange(PROPERTY_BATCH_COUNT, oldValue, batchCount); } + public List<SampleCategoryModelEntry> getCategory() { + return category; + } + + public void setCategory(List<SampleCategoryModelEntry> category) { + Object oldValue = getCategory(); + this.category = category; + firePropertyChange(PROPERTY_CATEGORY, oldValue, category); + } + + @Override + public SampleCategoryModelEntry getSelectedCategory() { + return selectedCategory; + } + + public void setSelectedCategory(SampleCategoryModelEntry selectedCategory) { + Object oldValue = getSelectedCategory(); + this.selectedCategory = selectedCategory; + firePropertyChange(PROPERTY_SELECTED_CATEGORY, oldValue, selectedCategory); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } + public Multimap<CaracteristicQualitativeValue, Species> getSpeciesUsed() { return speciesUsed; } @@ -177,6 +252,6 @@ @Override protected CreateSpeciesBatchUIModel newEntity() { - return new CreateSpeciesBatchUIModel(); + return new CreateSpeciesBatchUIModel(sampleCategoryModel); } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchTableModel.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchTableModel.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -24,6 +24,7 @@ * #L% */ +import fr.ifremer.tutti.ui.swing.content.operation.catches.SelectedCategoryAble; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import org.jdesktop.swingx.table.TableColumnModelExt; @@ -61,10 +62,10 @@ n_("tutti.splitSpeciesBatch.table.header.weight"), n_("tutti.splitSpeciesBatch.table.header.weight")); - private final SplitSpeciesBatchUIModel uiModel; + private final SelectedCategoryAble uiModel; public SplitSpeciesBatchTableModel(TableColumnModelExt columnModel, - SplitSpeciesBatchUIModel uiModel, + SelectedCategoryAble uiModel, boolean createEmptyRowIsEmpty) { super(columnModel, createEmptyRowIsEmpty, createEmptyRowIsEmpty); this.uiModel = uiModel; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -31,7 +31,6 @@ import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; @@ -69,19 +68,11 @@ private static final Log log = LogFactory.getLog(SplitSpeciesBatchUIHandler.class); -// /** -// * Parent UI. -// * -// * @since 0.3 -// */ -// private final SpeciesBatchUI parentUi; - public SplitSpeciesBatchUIHandler(EditCatchesUI parentUi, SplitSpeciesBatchUI ui) { super(parentUi.getHandler().getContext(), ui, SplitSpeciesBatchRowModel.PROPERTY_CATEGORY_VALUE, SplitSpeciesBatchRowModel.PROPERTY_WEIGHT); -// this.parentUi = parentUi.getSpeciesTabContent(); } //------------------------------------------------------------------------// @@ -251,11 +242,6 @@ //-- Public methods --// //------------------------------------------------------------------------// - public String decorateSpecies(Species object) { - String result = object == null ? "" : super.decorate(object); - return result; - } - public void editBatch(SpeciesBatchRowModel batch) { // get possible the last used Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -26,7 +26,7 @@ import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SelectedCategoryAble; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; @@ -39,14 +39,12 @@ * @since 0.3 */ public class SplitSpeciesBatchUIModel - extends AbstractTuttiTableUIModel<SpeciesBatchRowModel, SplitSpeciesBatchRowModel, SplitSpeciesBatchUIModel> { + extends AbstractTuttiTableUIModel<SpeciesBatchRowModel, SplitSpeciesBatchRowModel, SplitSpeciesBatchUIModel> implements SelectedCategoryAble { private static final long serialVersionUID = 1L; public static final String PROPERTY_CATEGORY = "category"; -// public static final String PROPERTY_SPECIES = "species"; - public static final String PROPERTY_SELECTED_CATEGORY = "selectedCategory"; public static final String PROPERTY_BATCH_WEIGHT = "batchWeight"; @@ -81,6 +79,11 @@ */ protected Float sampleWeight; + /** + * Model of sample categories. + * + * @since 2.4 + */ protected SampleCategoryModel sampleCategoryModel; public SplitSpeciesBatchUIModel(SampleCategoryModel sampleCategoryModel) { @@ -93,18 +96,12 @@ } public void setBatch(SpeciesBatchRowModel batch) { -// Object oldSpecies = getSpecies(); Object oldWeight = getBatchWeight(); this.batch = batch; -// firePropertyChange(PROPERTY_SPECIES, oldSpecies, getSpecies()); firePropertyChange(PROPERTY_BATCH_WEIGHT, oldWeight, getBatchWeight()); } -// public Species getSpecies() { -// return batch == null ? null : batch.getSpecies(); -// } - public List<SampleCategoryModelEntry> getCategory() { return category; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-09-18 16:47:50 UTC (rev 1188) @@ -362,6 +362,11 @@ for (SampleCategoryModelEntry sampleCategoryModelEntry : sampleCategoryModel.getCategory()) { + if (sampleCategoryModelEntry.getOrder() == 0) { + // first category is not editable + continue; + } + MandatorySampleCategoryColumnIdentifier identifier = MandatorySampleCategoryColumnIdentifier.newId( EditProtocolSpeciesRowModel.PROPERTY_MANDATORY_SAMPLE_CATEGORY_ID, sampleCategoryModelEntry.getCategoryId(), Modified: trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel-error-validation.xml =================================================================== --- trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel-error-validation.xml 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIModel-error-validation.xml 2013-09-18 16:47:50 UTC (rev 1188) @@ -70,4 +70,24 @@ </field-validator> </field> + + <field name="sampleWeight"> + + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ sampleWeight == null || sampleWeight > 0 ]]></param> + <message> + tutti.validator.error.splitSpeciesBatch.sampleWeight.invalidValue + </message> + </field-validator> + + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ sampleWeight == null || batchWeight == null || sampleWeight <= batchWeight]]></param> + <message> + tutti.validator.error.splitSpeciesBatch.sampleWeight.sampleBatchGreaterThanBatchWeight + </message> + </field-validator> + + </field> </validators> \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel-error-validation.xml =================================================================== --- trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel-error-validation.xml 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel-error-validation.xml 2013-09-18 16:47:50 UTC (rev 1188) @@ -69,4 +69,24 @@ </field-validator> </field> + + <field name="sampleWeight"> + + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ sampleWeight == null || sampleWeight > 0 ]]></param> + <message> + tutti.validator.error.splitSpeciesBatch.sampleWeight.invalidValue + </message> + </field-validator> + + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ sampleWeight == null || batchWeight == null || sampleWeight <= batchWeight]]></param> + <message> + tutti.validator.error.splitSpeciesBatch.sampleWeight.sampleBatchGreaterThanBatchWeight + </message> + </field-validator> + + </field> </validators> \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-09-18 16:47:50 UTC (rev 1188) @@ -181,8 +181,12 @@ tutti.createBenthosBatch.field.batchCount.tip= tutti.createBenthosBatch.field.batchWeight= tutti.createBenthosBatch.field.batchWeight.tip= +tutti.createBenthosBatch.field.category= +tutti.createBenthosBatch.field.categoryField.tip= tutti.createBenthosBatch.field.sampleCategory= tutti.createBenthosBatch.field.sampleCategory.tip= +tutti.createBenthosBatch.field.sampleWeight= +tutti.createBenthosBatch.field.sampleWeightField.tip= tutti.createBenthosBatch.field.species= tutti.createBenthosBatch.field.species.tip= tutti.createBenthosBatch.title= @@ -241,8 +245,12 @@ tutti.createSpeciesBatch.field.batchCount.tip= tutti.createSpeciesBatch.field.batchWeight= tutti.createSpeciesBatch.field.batchWeight.tip= +tutti.createSpeciesBatch.field.category= +tutti.createSpeciesBatch.field.categoryField.tip= tutti.createSpeciesBatch.field.sampleCategory= tutti.createSpeciesBatch.field.sampleCategory.tip= +tutti.createSpeciesBatch.field.sampleWeight= +tutti.createSpeciesBatch.field.sampleWeightField.tip= tutti.createSpeciesBatch.field.species= tutti.createSpeciesBatch.field.species.tip= tutti.createSpeciesBatch.title= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-09-18 12:38:56 UTC (rev 1187) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-09-18 16:47:50 UTC (rev 1188) @@ -168,8 +168,12 @@ tutti.createBenthosBatch.field.batchCount.tip=Saisir le nombre d'individus dans le lot tutti.createBenthosBatch.field.batchWeight=Poids du lot (kg) tutti.createBenthosBatch.field.batchWeight.tip=Poids du lot (kg) +tutti.createBenthosBatch.field.category=Catégorie +tutti.createBenthosBatch.field.categoryField.tip=Choisir le mode de catégorisation tutti.createBenthosBatch.field.sampleCategory=V / HV tutti.createBenthosBatch.field.sampleCategory.tip=Catégorie Vrac / Hors Vrac +tutti.createBenthosBatch.field.sampleWeight=Poids total catégorisé (kg) +tutti.createBenthosBatch.field.sampleWeightField.tip=Somme des poids saisis ci-dessous (kg) tutti.createBenthosBatch.field.species=Espèce du lot tutti.createBenthosBatch.field.species.tip=Espèce du lot tutti.createBenthosBatch.title=Créer un lot @@ -225,8 +229,12 @@ tutti.createSpeciesBatch.field.batchCount.tip=Saisir le nombre d'individus dans le lot tutti.createSpeciesBatch.field.batchWeight=Poids du lot (kg) tutti.createSpeciesBatch.field.batchWeight.tip=Poids du lot (non obligatoire à ce stade) +tutti.createSpeciesBatch.field.category=Catégorie +tutti.createSpeciesBatch.field.categoryField.tip=Choisir le mode de catégorisation tutti.createSpeciesBatch.field.sampleCategory=V / HV tutti.createSpeciesBatch.field.sampleCategory.tip=Catégorie Vrac / Hors Vrac +tutti.createSpeciesBatch.field.sampleWeight=Poids total catégorisé (kg) +tutti.createSpeciesBatch.field.sampleWeightField.tip=Somme des poids saisis ci-dessous (kg) tutti.createSpeciesBatch.field.species=Espèce du lot tutti.createSpeciesBatch.field.species.tip=Code campagne ou Code Rubin – Nom scientifique du lot à créer tutti.createSpeciesBatch.title=Créer un lot
participants (1)
-
tchemit@users.forge.codelutin.com