r200 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species: . frequency split
Author: tchemit Date: 2013-01-15 10:39:18 +0100 (Tue, 15 Jan 2013) New Revision: 200 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/200 Log: refs #1805: [Onglet Poisson] Assistance ?\195?\160 la saisie des lots de poissons 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/SpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.css 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-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-01-15 09:39:18 UTC (rev 200) @@ -25,7 +25,6 @@ */ import com.google.common.base.Preconditions; -import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; @@ -58,6 +57,9 @@ import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.ErrorDialogUI; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -84,6 +86,9 @@ private static final Log log = LogFactory.getLog(SpeciesBatchUIHandler.class); + public static JAXXContextEntryDef<List<Caracteristic>> FREQUENCY_LENGTH_CONTEXT_ENTRY = + JAXXUtil.newListContextEntryDef("frequencyLength"); + public static final Set<String> SAMPLING_PROPERTIES = Sets.newHashSet( SpeciesBatchRowModel.PROPERTY_SAMPLE_CATEGORY, SpeciesBatchRowModel.PROPERTY_SPECIES, @@ -145,9 +150,6 @@ SpeciesBatchUIModel model = getModel(); - Multimap<CaracteristicQualitativeValue, Species> speciesUsed = - ArrayListMultimap.create(); - List<SpeciesBatchRowModel> rows; if (empty) { @@ -176,12 +178,16 @@ SpeciesBatchRowModel rootRow = loadSpeciesBatch(aBatch, null, rows); - speciesUsed.put(rootRow.getSortedUnsortedCategoryValue(), rootRow.getSpecies()); + + if (log.isInfoEnabled()) { + log.info("Loaded root batch " + + decorate(rootRow.getSpecies()) + " - " + + decorate(rootRow.getSortedUnsortedCategoryValue())); + } } } } - model.setSpeciesUsed(speciesUsed); model.setRows(rows); recomputeBatchActionEnable(); } @@ -283,8 +289,18 @@ @Override protected void onModelRowsChanged(List<SpeciesBatchRowModel> rows) { super.onModelRowsChanged(rows); - // build the new sampling tree from the new rows to edit -// getModel().getSamplingTreeModel().populate(rows); + + // clear speciesUsed + getModel().getSpeciesUsed().clear(); + + for (SpeciesBatchRowModel row : rows) { + updateTotalFromFrequencies(row); + if (row.isBatchRoot()) { + + // update speciesUsed + addToSpeciesUsed(row); + } + } } @Override @@ -313,9 +329,6 @@ //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// - public static final String SPECIES_FREQUENCY_LENGHTS = - "SPECIES_FREQUENCY_LENGHTS"; - @Override protected SpeciesBatchUIModel getModel() { return ui.getModel(); @@ -339,7 +352,7 @@ context.getService(PersistenceService.class); List<Caracteristic> lengthCaracterics = service.getAllSpeciesLengthStepCaracteristic(); - ui.setContextValue(lengthCaracterics, SPECIES_FREQUENCY_LENGHTS); + FREQUENCY_LENGTH_CONTEXT_ENTRY.setContextValue(ui, lengthCaracterics); } @Override @@ -599,8 +612,8 @@ saveRow(newRow); - // update species used map - getModel().getSpeciesUsed().put(sortedUnsortedCategory, species); + // update speciesUsed + addToSpeciesUsed(newRow); } // reset create ui @@ -706,7 +719,6 @@ if (!selectedBatch.isBatchRoot()) { // remove all sub batches of his parent - SpeciesBatchRowModel parentBatch = selectedBatch.getBatchParent(); // get parent row index @@ -722,37 +734,43 @@ // remove selected batch and all his children - // collect of rows to remove from model - Set<SpeciesBatchRowModel> rowToRemove = - Sets.newHashSet(selectedBatch); + try { - collectChilds(selectedBatch, rowToRemove); + // remove parent batch (will destroy all his childs from db) + persistenceService.deleteSpeciesBatch(selectedBatch.getId()); - // remove all rows from the model - getModel().getRows().removeAll(rowToRemove); + // update speciesUsed + removeFromSpeciesUsed(selectedBatch); - // remove childs from parent batch - selectedBatch.setBatchChilds(null); + // collect of rows to remove from model + Set<SpeciesBatchRowModel> rowToRemove = + Sets.newHashSet(selectedBatch); - // save parent batch (will destroy all his childs from db) - persistenceService.deleteSpeciesBatch(selectedBatch.getId()); + collectChilds(selectedBatch, rowToRemove); - // refresh table from parent batch row index to the end - tableModel.fireTableDataChanged(); + // remove all rows from the model + getModel().getRows().removeAll(rowToRemove); - if (tableModel.getRowCount() > 0) { + // refresh table from parent batch row index to the end + tableModel.fireTableDataChanged(); - // select first row - AbstractSelectTableAction.doSelectCell(table, 0, 0); - } else { + if (tableModel.getRowCount() > 0) { - table.clearSelection(); - } + // select first row + AbstractSelectTableAction.doSelectCell(table, 0, 0); + } else { - if (table.isEditing()) { + table.clearSelection(); + } - // but no edit it - table.getCellEditor().stopCellEditing(); + if (table.isEditing()) { + + // but no edit it + table.getCellEditor().stopCellEditing(); + } + } catch (Exception e) { + + ErrorDialogUI.showError(e); } } } @@ -771,31 +789,44 @@ Preconditions.checkState(!TuttiEntities.isNew(parentBatch), "Can't remove sub batch if batch is not persisted"); - // collect of rows to remove from model - Set<SpeciesBatchRowModel> rowToRemove = Sets.newHashSet(); + try { - collectChilds(parentBatch, rowToRemove); + // save parent batch (will destroy all his childs from db) + persistenceService.deleteSpeciesSubBatch(parentBatch.getId()); - // remove all rows from the model - getModel().getRows().removeAll(rowToRemove); + if (parentBatch.isBatchRoot()) { - // remove childs from parent batch - parentBatch.setBatchChilds(null); + // update speciesUsed + removeFromSpeciesUsed(parentBatch); + } - // save parent batch (will destroy all his childs from db) - persistenceService.deleteSpeciesSubBatch(parentBatch.getId()); + // collect of rows to remove from model + Set<SpeciesBatchRowModel> rowToRemove = Sets.newHashSet(); - // refresh table from parent batch row index to the end - getTableModel().fireTableDataChanged(); + collectChilds(parentBatch, rowToRemove); - // select parent batch row - AbstractSelectTableAction.doSelectCell(table, rowIndex, 0); + // remove all rows from the model + getModel().getRows().removeAll(rowToRemove); - if (table.isEditing()) { + // remove childs from parent batch + parentBatch.setBatchChilds(null); - // but no edit it - table.getCellEditor().stopCellEditing(); + // refresh table from parent batch row index to the end + getTableModel().fireTableDataChanged(); + + // select parent batch row + AbstractSelectTableAction.doSelectCell(table, rowIndex, 0); + + if (table.isEditing()) { + + // but no edit it + table.getCellEditor().stopCellEditing(); + } + } catch (Exception e) { + + ErrorDialogUI.showError(e); } + } public SplitSpeciesBatchUI getSplitSpeciesBatchEditor() { @@ -952,7 +983,6 @@ // getModel().setTotalVracWeight(totalVrac); } - protected void recomputeBatchActionEnable() { int rowIndex = getTable().getSelectedRow(); @@ -1118,4 +1148,26 @@ columnIdentifier); } + protected void removeFromSpeciesUsed(SpeciesBatchRowModel row) { + Preconditions.checkNotNull(row); + Preconditions.checkNotNull(row.getSpecies()); + Preconditions.checkNotNull(row.getSortedUnsortedCategoryValue()); + if (log.isInfoEnabled()) { + log.info("Remove from speciesUsed: " + decorate(row.getSortedUnsortedCategoryValue()) + " - " + decorate(row.getSpecies())); + } + getModel().getSpeciesUsed().remove(row.getSortedUnsortedCategoryValue(), + row.getSpecies()); + } + + protected void addToSpeciesUsed(SpeciesBatchRowModel row) { + Preconditions.checkNotNull(row); + Preconditions.checkNotNull(row.getSpecies()); + Preconditions.checkNotNull(row.getSortedUnsortedCategoryValue()); + if (log.isInfoEnabled()) { + log.info("Add to speciesUsed: " + decorate(row.getSortedUnsortedCategoryValue()) + " - " + decorate(row.getSpecies())); + } + getModel().getSpeciesUsed().put(row.getSortedUnsortedCategoryValue(), + row.getSpecies()); + } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-01-15 09:39:18 UTC (rev 200) @@ -24,6 +24,7 @@ * #L% */ +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -40,11 +41,8 @@ private static final long serialVersionUID = 1L; - public static final String PROPERTY_TABLE_VIEW_MODE = "tableViewMode"; - public static final String PROPERTY_SPECIES_USED = "speciesUsed"; - public static final String PROPERTY_ALL_SPECIES = "allSpecies"; public static final String PROPERTY_CREATE_SPECIES_BATCH_ENABLED = "createSpeciesBatchEnabled"; @@ -80,7 +78,8 @@ * * @since 0.3 */ - protected Multimap<CaracteristicQualitativeValue, Species> speciesUsed; + protected final Multimap<CaracteristicQualitativeValue, Species> + speciesUsed = ArrayListMultimap.create(); /** * What to show in the table. @@ -204,12 +203,6 @@ return speciesUsed; } - public void setSpeciesUsed(Multimap<CaracteristicQualitativeValue, Species> speciesUsed) { - this.speciesUsed = speciesUsed; - firePropertyChange(PROPERTY_SPECIES_USED, null, speciesUsed); - } - - public boolean isCreateSpeciesBatchEnabled() { return createSpeciesBatchEnabled; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-01-15 09:39:18 UTC (rev 200) @@ -235,16 +235,16 @@ return result; } - @Override - public boolean stopCellEditing() { - boolean b = super.stopCellEditing(); - if (b) { - rowIndex = null; - editRow = null; - columnIndex = null; - } - return b; - } +// @Override +// public boolean stopCellEditing() { +// boolean b = super.stopCellEditing(); +// if (b) { +// rowIndex = null; +// editRow = null; +// columnIndex = null; +// } +// return b; +// } @Override public void cancelCellEditing() { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-01-15 09:39:18 UTC (rev 200) @@ -151,9 +151,7 @@ initUI(ui); List<Caracteristic> lengthStepCaracterics = - ui.getContextValue( - List.class, - SpeciesBatchUIHandler.SPECIES_FREQUENCY_LENGHTS); + SpeciesBatchUIHandler.FREQUENCY_LENGTH_CONTEXT_ENTRY.getContextValue(ui); Preconditions.checkNotNull(lengthStepCaracterics); SpeciesFrequencyUIModel model = getModel(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css 2013-01-15 09:39:18 UTC (rev 200) @@ -77,12 +77,14 @@ #saveButton { actionIcon: save; + mnemonic: E; text: "tutti.action.save"; enabled: {model.isValid()}; } #cancelButton { actionIcon: cancel; + mnemonic: A; text: "tutti.action.cancel"; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java 2013-01-15 09:39:18 UTC (rev 200) @@ -24,7 +24,6 @@ * #L% */ -import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.TuttiPersistence; @@ -124,7 +123,7 @@ Species newValue = (Species) evt.getNewValue(); if (log.isInfoEnabled()) { - log.info("New Selected species "+(newValue==null?null:newValue.getCodeMemo())); + log.info("New Selected species " + (newValue == null ? null : newValue.getCodeMemo())); } if (newValue == null || source.getSpeciesUsed() == null) { @@ -212,17 +211,13 @@ List<Species> speciesToUse = Lists.newArrayList(); - Multimap<CaracteristicQualitativeValue, Species> speciesUsed; - boolean reset = batchModel == null; - if (reset) { - speciesUsed = ArrayListMultimap.create(); - } else { - speciesUsed = batchModel.getSpeciesUsed(); - } + Multimap<CaracteristicQualitativeValue, Species> speciesUsed = + model.getSpeciesUsed(); + speciesUsed.clear(); - model.setSpeciesUsed(speciesUsed); + if (batchModel != null) { - if (!reset) { + speciesUsed.putAll(batchModel.getSpeciesUsed()); // compute which species can still be used Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIModel.java 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIModel.java 2013-01-15 09:39:18 UTC (rev 200) @@ -24,6 +24,7 @@ * #L% */ +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -82,7 +83,7 @@ * * @since 0.3 */ - protected Multimap<CaracteristicQualitativeValue, Species> speciesUsed; + protected final Multimap<CaracteristicQualitativeValue, Species> speciesUsed = ArrayListMultimap.create(); public CreateSpeciesBatchUIModel() { super(CreateSpeciesBatchUIModel.class, null, null); @@ -128,10 +129,6 @@ firePropertyChange(PROPERTY_BATCH_WEIGHT, oldValue, batchWeight); } - public void setSpeciesUsed(Multimap<CaracteristicQualitativeValue, Species> speciesUsed) { - this.speciesUsed = speciesUsed; - } - public Multimap<CaracteristicQualitativeValue, Species> getSpeciesUsed() { return speciesUsed; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.css 2013-01-15 07:18:44 UTC (rev 199) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.css 2013-01-15 09:39:18 UTC (rev 200) @@ -94,13 +94,13 @@ #cancelButton { actionIcon: cancel; - mnemonic: C; + mnemonic: A; text: "tutti.action.cancel"; } #saveButton { actionIcon: save; - mnemonic: S; + mnemonic: E; text: "tutti.action.save"; enabled: {model.isValid()}; }
participants (1)
-
tchemit@users.forge.codelutin.com