Author: tchemit Date: 2013-11-05 10:51:46 +0100 (Tue, 05 Nov 2013) New Revision: 1328 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1328 Log: fixes #3675: [DONNEES INDIVIDUELLES] pouvoir copier les mensurations depuis la page ESPECES Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIModel.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java 2013-11-05 08:30:18 UTC (rev 1327) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java 2013-11-05 09:51:46 UTC (rev 1328) @@ -607,11 +607,16 @@ // apply also weight found weight = frequency.getWeight(); - if (weight != null) { - // convert weight units - weight = speciesWeightUnit.toEntity(weight); - weight = weightUnit.fromEntity(weight); + if (weight == null) { + + // try to get it from batch + weight = TuttiEntities.getValueOrComputedValue( + leaf.getWeight(), + leaf.getFinestCategory().getCategoryWeight()); } + // convert weight units + weight = speciesWeightUnit.toEntity(weight); + weight = weightUnit.fromEntity(weight); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java 2013-11-05 08:30:18 UTC (rev 1327) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java 2013-11-05 09:51:46 UTC (rev 1328) @@ -269,24 +269,33 @@ Species species = (Species) evt.getNewValue(); - if (species == null || - !source.isSpeciesFromBatch()) { + source.setValueIsAdjusting(true); - // reset create from batch flag - source.setCreateFromBatch(false); - } + try { + if (species == null || + !source.isSpeciesFromBatch()) { - // compute editors enable property - boolean enabled = species != null && - (!source.isCreateFromBatch() || - !source.isSpeciesFromBatch() || - source.isSpeciesFromBatchWithOneCount()); - if (log.isInfoEnabled()) { - log.info("can edit? " + enabled + " (species changed: " + species + ")"); + // reset create from batch flag + source.setCreateFromBatch(false); + } + + // compute editors enable property + boolean enabled = species != null && + (!source.isCreateFromBatch() || + !source.isSpeciesFromBatch()); +// boolean enabled = species != null && +// (!source.isCreateFromBatch() || +// !source.isSpeciesFromBatch() || +// source.isSpeciesFromBatchWithOneCount()); + if (log.isInfoEnabled()) { + log.info("can edit? " + enabled + " (species changed: " + species + ")"); + } + for (JComponent editorComponent : editorComponents) { + editorComponent.setEnabled(enabled); + } + } finally { + source.setValueIsAdjusting(false); } - for (JComponent editorComponent : editorComponents) { - editorComponent.setEnabled(enabled); - } } }); @@ -296,14 +305,14 @@ public void propertyChange(PropertyChangeEvent evt) { CreateIndividualObservationBatchUIModel source = (CreateIndividualObservationBatchUIModel) evt.getSource(); - Boolean newValue = (Boolean) evt.getNewValue(); newValue = newValue != null && newValue; // compute editors enable property - boolean enabled = !newValue || - !source.isSpeciesFromBatch() || - source.isSpeciesFromBatchWithOneCount(); + boolean enabled = !newValue || !source.isSpeciesFromBatch(); +// boolean enabled = !newValue || +// !source.isSpeciesFromBatch() || +// source.isSpeciesFromBatchWithOneCount(); if (log.isInfoEnabled()) { log.info("can edit? " + enabled + " (createFromBatch changed: " + newValue + ")"); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIModel.java 2013-11-05 08:30:18 UTC (rev 1327) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIModel.java 2013-11-05 09:51:46 UTC (rev 1328) @@ -52,8 +52,6 @@ public static final String PROPERTY_SPECIES_FROM_BATCH = "speciesFromBatch"; - public static final String PROPERTY_SPECIES_FROM_BATCH_WITH_ONE_COUNT = "speciesFromBatchWihtOneCount"; - public static final String PROPERTY_CREATE_FROM_BATCH = "createFromBatch"; public static final String PROPERTY_CARACTERISTICS = "caracteristics"; @@ -80,6 +78,13 @@ protected boolean createFromBatch; /** + * Flag to stop fires when flag is on. + * + * @since 2.8 + */ + protected boolean valueIsAdjusting; + + /** * Delegate edit object. * * @since 1.3 @@ -108,6 +113,14 @@ editObject.setCaracteristics(new CaracteristicMap()); } + public boolean isValueIsAdjusting() { + return valueIsAdjusting; + } + + public void setValueIsAdjusting(boolean valueIsAdjusting) { + this.valueIsAdjusting = valueIsAdjusting; + } + public Species getSpecies() { return editObject.getSpecies(); } @@ -115,11 +128,9 @@ public void setSpecies(Species species) { Object oldValue = getSpecies(); Object oldSpeciesFromBatch = isSpeciesFromBatch(); - Object oldSpeciesFromBatchWithOneCount = isSpeciesFromBatchWithOneCount(); editObject.setSpecies(species); - firePropertyChange(IndividualObservationBatch.PROPERTY_SPECIES, oldValue, species); - firePropertyChange(PROPERTY_SPECIES_FROM_BATCH, oldSpeciesFromBatch, isSpeciesFromBatch()); - firePropertyChange(PROPERTY_SPECIES_FROM_BATCH_WITH_ONE_COUNT, oldSpeciesFromBatchWithOneCount, isSpeciesFromBatchWithOneCount()); + firePropertyChanged(IndividualObservationBatch.PROPERTY_SPECIES, oldValue, species); + firePropertyChanged(PROPERTY_SPECIES_FROM_BATCH, oldSpeciesFromBatch, isSpeciesFromBatch()); } public Float getWeight() { @@ -129,7 +140,7 @@ public void setWeight(Float weight) { Object oldValue = getWeight(); editObject.setWeight(weight); - firePropertyChange(IndividualObservationBatch.PROPERTY_WEIGHT, oldValue, weight); + firePropertyChanged(IndividualObservationBatch.PROPERTY_WEIGHT, oldValue, weight); } public Float getSize() { @@ -139,7 +150,7 @@ public void setSize(Float size) { Object oldValue = getSize(); editObject.setSize(size); - firePropertyChange(IndividualObservationBatch.PROPERTY_SIZE, oldValue, size); + firePropertyChanged(IndividualObservationBatch.PROPERTY_SIZE, oldValue, size); } public Caracteristic getLengthStepCaracteristic() { @@ -149,7 +160,7 @@ public void setLengthStepCaracteristic(Caracteristic lengthStepCaracteristic) { Object oldValue = getLengthStepCaracteristic(); editObject.setLengthStepCaracteristic(lengthStepCaracteristic); - firePropertyChange(IndividualObservationBatch.PROPERTY_LENGTH_STEP_CARACTERISTIC, oldValue, lengthStepCaracteristic); + firePropertyChanged(IndividualObservationBatch.PROPERTY_LENGTH_STEP_CARACTERISTIC, oldValue, lengthStepCaracteristic); } public CaracteristicMap getCaracteristics() { @@ -159,7 +170,7 @@ public void setCaracteristics(CaracteristicMap caracteristics) { editObject.setCaracteristics(caracteristics); - firePropertyChange(IndividualObservationBatch.PROPERTY_CARACTERISTICS, null, caracteristics); + firePropertyChanged(IndividualObservationBatch.PROPERTY_CARACTERISTICS, null, caracteristics); } @@ -169,7 +180,7 @@ public void setAvailableSpecies(List<Species> availableSpecies) { this.availableSpecies = availableSpecies; - firePropertyChange(PROPERTY_AVAILABLE_SPECIES, null, availableSpecies); + firePropertyChanged(PROPERTY_AVAILABLE_SPECIES, null, availableSpecies); } public Map<Species, Integer> getBatchSpecies() { @@ -182,19 +193,14 @@ batchSpecies.containsKey(getSpecies()); } - public boolean isSpeciesFromBatchWithOneCount() { - return isSpeciesFromBatch() && batchSpecies.get(getSpecies()) == 1; - } - public boolean isSpeciesFromBatchWithCount() { - return isSpeciesFromBatch() && batchSpecies.get(getSpecies()) >0; + return isSpeciesFromBatch() && batchSpecies.get(getSpecies()) > 0; } public void setBatchSpecies(Map<Species, Integer> batchSpecies) { this.batchSpecies = batchSpecies; - firePropertyChange(PROPERTY_BATCH_SPECIES, null, batchSpecies); - firePropertyChange(PROPERTY_SPECIES_FROM_BATCH, null, isSpeciesFromBatch()); - firePropertyChange(PROPERTY_SPECIES_FROM_BATCH_WITH_ONE_COUNT, null, isSpeciesFromBatchWithOneCount()); + firePropertyChanged(PROPERTY_BATCH_SPECIES, null, batchSpecies); + firePropertyChanged(PROPERTY_SPECIES_FROM_BATCH, null, isSpeciesFromBatch()); setCreateFromBatch(isCreateFromBatch()); } @@ -205,7 +211,7 @@ public void setCreateFromBatch(boolean createFromBatch) { Object oldValue = isCreateFromBatch(); this.createFromBatch = createFromBatch; - firePropertyChange(PROPERTY_CREATE_FROM_BATCH, oldValue, createFromBatch); + firePropertyChanged(PROPERTY_CREATE_FROM_BATCH, oldValue, createFromBatch); } @Override @@ -216,6 +222,7 @@ public void reset() { setAvailableSpecies(Lists.<Species>newArrayList()); setBatchSpecies(Maps.<Species, Integer>newHashMap()); + setCreateFromBatch(false); setSpecies(null); setWeight(null); setSize(null); @@ -259,7 +266,7 @@ this.property = property; getCaracteristics().put(caracteristic, property); if (ObjectUtils.notEqual(oldValue, property)) { - firePropertyChange(PROPERTY_PROPERTY, oldValue, property); + firePropertyChanged(PROPERTY_PROPERTY, oldValue, property); CreateIndividualObservationBatchUIModel.this.firePropertyChanged(PROPERTY_CARACTERISTICS, null, getCaracteristics()); } } @@ -268,4 +275,13 @@ this.caracteristic = caracteristic; } } + + @Override + public void firePropertyChanged(String propertyName, + Object oldValue, + Object newValue) { + if (!valueIsAdjusting) { + firePropertyChange(propertyName, oldValue, newValue); + } + } }