View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.collect.ArrayListMultimap;
26  import com.google.common.collect.HashMultimap;
27  import com.google.common.collect.Lists;
28  import com.google.common.collect.Multimap;
29  import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode;
30  import fr.ifremer.tutti.persistence.entities.data.Attachment;
31  import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
32  import fr.ifremer.tutti.persistence.entities.data.CatchBatchs;
33  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
34  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
35  import fr.ifremer.tutti.persistence.entities.referential.Species;
36  import fr.ifremer.tutti.type.WeightUnit;
37  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
38  import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware;
39  import fr.ifremer.tutti.ui.swing.util.computable.ComputableData;
40  import org.apache.commons.collections4.CollectionUtils;
41  import org.nuiton.jaxx.application.swing.tab.TabContentModel;
42  import org.nuiton.util.beans.Binder;
43  import org.nuiton.util.beans.BinderFactory;
44  
45  import java.util.Collection;
46  import java.util.List;
47  
48  import static org.nuiton.i18n.I18n.t;
49  
50  /**
51   * @author Tony Chemit - chemit@codelutin.com
52   * @since 0.3
53   */
54  public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, EditCatchesUIModel> implements AttachmentModelAware, TabContentModel, CatchBatch {
55  
56      private static final long serialVersionUID = 1L;
57  
58      public static final String PROPERTY_VALIDATION_CONTEXT = "validationContext";
59  
60      public static final String PROPERTY_CATCH_BATCH = "catchBatch";
61  
62      protected static final Binder<CatchBatch, EditCatchesUIModel> fromBeanBinder = BinderFactory.newBinder(CatchBatch.class, EditCatchesUIModel.class);
63  
64      protected static final Binder<EditCatchesUIModel, CatchBatch> toBeanBinder = BinderFactory.newBinder(EditCatchesUIModel.class, CatchBatch.class);
65  
66      protected Float speciesTotalComputedWeight;
67  
68      protected ComputableData<Float> speciesTotalSortedComputedOrNotWeight = new ComputableData<>();
69  
70      protected Float speciesTotalUnsortedComputedWeight;
71  
72      protected Float speciesTotalSampleSortedComputedWeight;
73  
74      protected ComputableData<Float> speciesTotalInertComputedOrNotWeight = new ComputableData<>();
75  
76      protected ComputableData<Float> speciesTotalLivingNotItemizedComputedOrNotWeight = new ComputableData<>();
77  
78      protected Float benthosTotalComputedWeight;
79  
80      protected ComputableData<Float> benthosTotalSortedComputedOrNotWeight = new ComputableData<>();
81  
82      protected Float benthosTotalUnsortedComputedWeight;
83  
84      protected Float benthosTotalSampleSortedComputedWeight;
85  
86      protected ComputableData<Float> benthosTotalInertComputedOrNotWeight = new ComputableData<>();
87  
88      protected ComputableData<Float> benthosTotalLivingNotItemizedComputedOrNotWeight = new ComputableData<>();
89  
90      protected ComputableData<Float> marineLitterTotalComputedOrNotWeight = new ComputableData<>();
91  
92      protected ComputableData<Float> catchTotalComputedOrNotWeight = new ComputableData<>();
93  
94      protected Float catchTotalSortedComputedWeight;
95  
96      protected Float catchTotalSortedSortedComputedWeight;
97  
98      protected Float catchTotalUnsortedComputedWeight;
99  
100     protected Float catchTotalSortedTremisWeight;
101 
102     protected Float catchTotalSortedCarousselWeight;
103 
104     protected ComputableData<Float> catchTotalRejectedComputedOrNotWeight = new ComputableData<>();
105 
106     protected FishingOperation fishingOperation;
107 
108     protected String validationContext;
109 
110     protected final CatchBatch editObject = CatchBatchs.newCatchBatch();
111 
112     protected final List<Attachment> attachment = Lists.newArrayList();
113 
114     /**
115      * Species already used in some batches.
116      *
117      * @since 0.3
118      */
119     protected final Multimap<CaracteristicQualitativeValue, Species>
120             speciesUsed = HashMultimap.create();
121 
122     /**
123      * Categories already used in some batches.
124      *
125      * @since 1.4
126      */
127     protected final Multimap<CaracteristicQualitativeValue, CaracteristicQualitativeValue>
128             marineLitterCategoriesUsed = ArrayListMultimap.create();
129 
130     protected boolean loadingData;
131 
132     /**
133      * Catch weight unit.
134      *
135      * @since 2.5
136      */
137     protected final WeightUnit catchWeightUnit;
138 
139     /**
140      * Species weight unit.
141      *
142      * @since 2.5
143      */
144     protected final WeightUnit speciesWeightUnit;
145 
146     /**
147      * Benthos weight unit.
148      *
149      * @since 2.5
150      */
151     protected final WeightUnit benthosWeightUnit;
152 
153     /**
154      * Marine Litter weight unit.
155      *
156      * @since 2.5
157      */
158     protected final WeightUnit marineLitterWeightUnit;
159 
160     /**
161      * Pour ne pas vérifier si on peut quitter l'écran des mensurations.
162      *
163      * @since 4.5
164      */
165     private boolean doNotCheckLeavingFrequencyScreen;
166 
167     public EditCatchesUIModel(WeightUnit speciesWeightUnit,
168                               WeightUnit benthosWeightUnit,
169                               WeightUnit marineLitterWeightUnit) {
170         super(fromBeanBinder, toBeanBinder);
171         //FIXME See if this can be configurable or guess from other weightUnits
172         if (WeightUnit.G == speciesWeightUnit &&
173             WeightUnit.G == benthosWeightUnit) {
174             this.catchWeightUnit = WeightUnit.G;
175         } else {
176             this.catchWeightUnit = WeightUnit.KG;
177         }
178         this.speciesWeightUnit = speciesWeightUnit;
179         this.benthosWeightUnit = benthosWeightUnit;
180         this.marineLitterWeightUnit = marineLitterWeightUnit;
181 
182         speciesTotalSortedComputedOrNotWeight.addPropagateListener(
183                 PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, this);
184         speciesTotalInertComputedOrNotWeight.addPropagateListener(
185                 PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, this);
186         speciesTotalLivingNotItemizedComputedOrNotWeight.addPropagateListener(
187                 PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, this);
188 
189         benthosTotalSortedComputedOrNotWeight.addPropagateListener(
190                 PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, this);
191         benthosTotalInertComputedOrNotWeight.addPropagateListener(
192                 PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, this);
193         benthosTotalLivingNotItemizedComputedOrNotWeight.addPropagateListener(
194                 PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, this);
195 
196         marineLitterTotalComputedOrNotWeight.addPropagateListener(
197                 PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, this);
198 
199         catchTotalComputedOrNotWeight.addPropagateListener(
200                 PROPERTY_CATCH_TOTAL_WEIGHT, this);
201         catchTotalRejectedComputedOrNotWeight.addPropagateListener(
202                 PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, this);
203     }
204 
205     public WeightUnit getCatchWeightUnit() {
206         return catchWeightUnit;
207     }
208 
209     public boolean isLoadingData() {
210         return loadingData;
211     }
212 
213     public void setLoadingData(boolean loadingData) {
214         this.loadingData = loadingData;
215     }
216 
217     @Override
218     public String getTitle() {
219         return t("tutti.label.tab.catchesCaracteristics");
220     }
221 
222     @Override
223     protected CatchBatch newEntity() {
224 //        return editObject;
225         return CatchBatchs.newCatchBatch();
226     }
227 
228     @Override
229     public void fromEntity(CatchBatch entity) {
230 
231         Object oldObjectId = getObjectId();
232 
233         super.fromEntity(entity);
234 
235         // id was bind to #id but not to editObject#id
236         editObject.setId(getId());
237 
238         firePropertyChange(PROPERTY_CATCH_BATCH, null, entity);
239         firePropertyChange(PROPERTY_OBJECT_ID, oldObjectId, getObjectId());
240 
241         setFishingOperation(entity == null ? null : entity.getFishingOperation());
242 
243         if (entity != null) {
244 
245             // convert total weights
246 
247             setCatchTotalComputedWeight(catchWeightUnit.fromEntity(entity.getCatchTotalComputedWeight()));
248             setCatchTotalRejectedComputedWeight(catchWeightUnit.fromEntity(entity.getCatchTotalRejectedComputedWeight()));
249             setCatchTotalRejectedWeight(catchWeightUnit.fromEntity(entity.getCatchTotalRejectedWeight()));
250             setCatchTotalSortedCarousselWeight(catchWeightUnit.fromEntity(entity.getCatchTotalSortedCarousselWeight()));
251             setCatchTotalSortedComputedWeight(catchWeightUnit.fromEntity(entity.getCatchTotalSortedComputedWeight()));
252             setCatchTotalSortedSortedComputedWeight(catchWeightUnit.fromEntity(entity.getCatchTotalSortedSortedComputedWeight()));
253             setCatchTotalSortedTremisWeight(catchWeightUnit.fromEntity(entity.getCatchTotalSortedTremisWeight()));
254             setCatchTotalUnsortedComputedWeight(catchWeightUnit.fromEntity(entity.getCatchTotalUnsortedComputedWeight()));
255             setCatchTotalWeight(catchWeightUnit.fromEntity(entity.getCatchTotalWeight()));
256 
257             // convert species weights
258 
259             setSpeciesTotalComputedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalComputedWeight()));
260             setSpeciesTotalInertComputedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalInertComputedWeight()));
261             setSpeciesTotalInertWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalInertWeight()));
262             setSpeciesTotalLivingNotItemizedComputedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalLivingNotItemizedComputedWeight()));
263             setSpeciesTotalLivingNotItemizedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalLivingNotItemizedWeight()));
264             setSpeciesTotalSampleSortedComputedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalSampleSortedComputedWeight()));
265             setSpeciesTotalSortedComputedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalSortedComputedWeight()));
266             setSpeciesTotalSortedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalSortedWeight()));
267             setSpeciesTotalUnsortedComputedWeight(speciesWeightUnit.fromEntity(entity.getSpeciesTotalUnsortedComputedWeight()));
268 
269             // convert benthos weights
270 
271             setBenthosTotalComputedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalComputedWeight()));
272             setBenthosTotalInertComputedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalInertComputedWeight()));
273             setBenthosTotalInertWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalInertWeight()));
274             setBenthosTotalLivingNotItemizedComputedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalLivingNotItemizedComputedWeight()));
275             setBenthosTotalLivingNotItemizedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalLivingNotItemizedWeight()));
276             setBenthosTotalSampleSortedComputedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalSampleSortedComputedWeight()));
277             setBenthosTotalSortedComputedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalSortedComputedWeight()));
278             setBenthosTotalSortedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalSortedWeight()));
279             setBenthosTotalUnsortedComputedWeight(benthosWeightUnit.fromEntity(entity.getBenthosTotalUnsortedComputedWeight()));
280 
281             // convert marine litter weights
282 
283             setMarineLitterTotalComputedWeight(marineLitterWeightUnit.fromEntity(entity.getMarineLitterTotalComputedWeight()));
284             setMarineLitterTotalWeight(marineLitterWeightUnit.fromEntity(entity.getMarineLitterTotalWeight()));
285         }
286     }
287 
288     @Override
289     public CatchBatch toEntity() {
290         CatchBatch result = super.toEntity();
291 
292         // convert total weights
293 
294         result.setCatchTotalComputedWeight(catchWeightUnit.toEntity(getCatchTotalComputedWeight()));
295         result.setCatchTotalRejectedComputedWeight(catchWeightUnit.toEntity(getCatchTotalRejectedComputedWeight()));
296         result.setCatchTotalRejectedWeight(catchWeightUnit.toEntity(getCatchTotalRejectedWeight()));
297         result.setCatchTotalSortedCarousselWeight(catchWeightUnit.toEntity(getCatchTotalSortedCarousselWeight()));
298         result.setCatchTotalSortedComputedWeight(catchWeightUnit.toEntity(getCatchTotalSortedComputedWeight()));
299         result.setCatchTotalSortedSortedComputedWeight(catchWeightUnit.toEntity(getCatchTotalSortedSortedComputedWeight()));
300         result.setCatchTotalSortedTremisWeight(catchWeightUnit.toEntity(getCatchTotalSortedTremisWeight()));
301         result.setCatchTotalUnsortedComputedWeight(catchWeightUnit.toEntity(getCatchTotalUnsortedComputedWeight()));
302         result.setCatchTotalWeight(catchWeightUnit.toEntity(getCatchTotalWeight()));
303 
304         // convert species weights
305 
306         result.setSpeciesTotalComputedWeight(speciesWeightUnit.toEntity(getSpeciesTotalComputedWeight()));
307         result.setSpeciesTotalInertComputedWeight(speciesWeightUnit.toEntity(getSpeciesTotalInertComputedWeight()));
308         result.setSpeciesTotalInertWeight(speciesWeightUnit.toEntity(getSpeciesTotalInertWeight()));
309         result.setSpeciesTotalLivingNotItemizedComputedWeight(speciesWeightUnit.toEntity(getSpeciesTotalLivingNotItemizedComputedWeight()));
310         result.setSpeciesTotalLivingNotItemizedWeight(speciesWeightUnit.toEntity(getSpeciesTotalLivingNotItemizedWeight()));
311         result.setSpeciesTotalSampleSortedComputedWeight(speciesWeightUnit.toEntity(getSpeciesTotalSampleSortedComputedWeight()));
312         result.setSpeciesTotalSortedComputedWeight(speciesWeightUnit.toEntity(getSpeciesTotalSortedComputedWeight()));
313         result.setSpeciesTotalSortedWeight(speciesWeightUnit.toEntity(getSpeciesTotalSortedWeight()));
314         result.setSpeciesTotalUnsortedComputedWeight(speciesWeightUnit.toEntity(getSpeciesTotalUnsortedComputedWeight()));
315 
316         // convert benthos weights
317 
318         result.setBenthosTotalComputedWeight(benthosWeightUnit.toEntity(getBenthosTotalComputedWeight()));
319         result.setBenthosTotalInertComputedWeight(benthosWeightUnit.toEntity(getBenthosTotalInertComputedWeight()));
320         result.setBenthosTotalInertWeight(benthosWeightUnit.toEntity(getBenthosTotalInertWeight()));
321         result.setBenthosTotalLivingNotItemizedComputedWeight(benthosWeightUnit.toEntity(getBenthosTotalLivingNotItemizedComputedWeight()));
322         result.setBenthosTotalLivingNotItemizedWeight(benthosWeightUnit.toEntity(getBenthosTotalLivingNotItemizedWeight()));
323         result.setBenthosTotalSampleSortedComputedWeight(benthosWeightUnit.toEntity(getBenthosTotalSampleSortedComputedWeight()));
324         result.setBenthosTotalSortedComputedWeight(benthosWeightUnit.toEntity(getBenthosTotalSortedComputedWeight()));
325         result.setBenthosTotalSortedWeight(benthosWeightUnit.toEntity(getBenthosTotalSortedWeight()));
326         result.setBenthosTotalUnsortedComputedWeight(benthosWeightUnit.toEntity(getBenthosTotalUnsortedComputedWeight()));
327 
328         // convert marine litter weights
329 
330         result.setMarineLitterTotalComputedWeight(marineLitterWeightUnit.toEntity(getMarineLitterTotalComputedWeight()));
331         result.setMarineLitterTotalWeight(marineLitterWeightUnit.toEntity(getMarineLitterTotalWeight()));
332 
333         return result;
334     }
335 
336     @Override
337     public boolean isEmpty() {
338         return getCatchTotalWeight() == null
339                && getCatchTotalRejectedWeight() == null
340                && CollectionUtils.isEmpty(getAttachment());
341     }
342 
343     @Override
344     public String getIcon() {
345         return null;
346     }
347 
348     @Override
349     public FishingOperation getFishingOperation() {
350         return fishingOperation;
351     }
352 
353     @Override
354     public void setFishingOperation(FishingOperation fishingOperation) {
355         Object oldValue = getFishingOperation();
356         this.fishingOperation = fishingOperation;
357         firePropertyChange(PROPERTY_FISHING_OPERATION, oldValue, fishingOperation);
358     }
359 
360     @Override
361     public boolean isCloseable() {
362         return false;
363     }
364 
365     public String getValidationContext() {
366         return validationContext;
367     }
368 
369     public void setValidationContext(String validationContext) {
370         Object oldValue = getValidationContext();
371         this.validationContext = validationContext;
372         firePropertyChange(PROPERTY_VALIDATION_CONTEXT, oldValue, validationContext);
373     }
374 
375     public Multimap<CaracteristicQualitativeValue, Species> getSpeciesUsed() {
376         return speciesUsed;
377     }
378 
379     public void replaceCaracteristicValue(Species species,
380                                           CaracteristicQualitativeValue oldValue,
381                                           CaracteristicQualitativeValue newValue) {
382 
383         speciesUsed.remove(oldValue, species);
384         speciesUsed.put(newValue, species);
385 
386     }
387 
388     public Multimap<CaracteristicQualitativeValue, CaracteristicQualitativeValue> getMarineLitterCategoriesUsed() {
389         return marineLitterCategoriesUsed;
390     }
391 
392     //------------------------------------------------------------------------//
393     //-- Total                                                              --//
394     //------------------------------------------------------------------------//
395 
396     public ComputableData<Float> getCatchTotalComputedOrNotWeight() {
397         return catchTotalComputedOrNotWeight;
398     }
399 
400     @Override
401     public Float getCatchTotalWeight() {
402         return catchTotalComputedOrNotWeight.getData();
403     }
404 
405     @Override
406     public void setCatchTotalWeight(Float catchTotalWeight) {
407         Object oldValue = getCatchTotalWeight();
408         this.catchTotalComputedOrNotWeight.setData(catchTotalWeight);
409         firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT, oldValue, catchTotalWeight);
410     }
411 
412     @Override
413     public Float getCatchTotalComputedWeight() {
414         return catchTotalComputedOrNotWeight.getComputedData();
415     }
416 
417     @Override
418     public void setCatchTotalComputedWeight(Float catchTotalComputedWeight) {
419         Object oldValue = getCatchTotalComputedWeight();
420         this.catchTotalComputedOrNotWeight.setComputedData(catchTotalComputedWeight);
421         firePropertyChange(PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, oldValue, catchTotalComputedWeight);
422     }
423 
424     @Override
425     public Float getCatchTotalSortedComputedWeight() {
426         return catchTotalSortedComputedWeight;
427     }
428 
429     @Override
430     public void setCatchTotalSortedComputedWeight(Float catchTotalSortedComputedWeight) {
431         Object oldValue = getCatchTotalSortedComputedWeight();
432         this.catchTotalSortedComputedWeight = catchTotalSortedComputedWeight;
433         firePropertyChange(PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, oldValue, catchTotalSortedComputedWeight);
434     }
435 
436     @Override
437     public Float getCatchTotalUnsortedComputedWeight() {
438         return catchTotalUnsortedComputedWeight;
439     }
440 
441     @Override
442     public void setCatchTotalUnsortedComputedWeight(Float catchTotalUnsortedComputedWeight) {
443         Object oldValue = getCatchTotalUnsortedComputedWeight();
444         this.catchTotalUnsortedComputedWeight = catchTotalUnsortedComputedWeight;
445         firePropertyChange(PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, oldValue, catchTotalUnsortedComputedWeight);
446     }
447 
448     @Override
449     public Float getCatchTotalSortedTremisWeight() {
450         return catchTotalSortedTremisWeight;
451     }
452 
453     @Override
454     public void setCatchTotalSortedTremisWeight(Float catchTotalSortedTremisWeight) {
455         Object oldValue = getCatchTotalSortedTremisWeight();
456         this.catchTotalSortedTremisWeight = catchTotalSortedTremisWeight;
457         firePropertyChange(PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, oldValue, catchTotalSortedTremisWeight);
458     }
459 
460     @Override
461     public Float getCatchTotalSortedCarousselWeight() {
462         return catchTotalSortedCarousselWeight;
463     }
464 
465     @Override
466     public void setCatchTotalSortedCarousselWeight(Float catchTotalSortedCarousselWeight) {
467         Object oldValue = getCatchTotalSortedCarousselWeight();
468         this.catchTotalSortedCarousselWeight = catchTotalSortedCarousselWeight;
469         firePropertyChange(PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, oldValue, catchTotalSortedCarousselWeight);
470     }
471 
472     public ComputableData<Float> getCatchTotalRejectedComputedOrNotWeight() {
473         return catchTotalRejectedComputedOrNotWeight;
474     }
475 
476     @Override
477     public Float getCatchTotalRejectedWeight() {
478         return catchTotalRejectedComputedOrNotWeight.getData();
479     }
480 
481     @Override
482     public void setCatchTotalRejectedWeight(Float catchTotalRejectedWeight) {
483         Object oldValue = getCatchTotalRejectedWeight();
484         this.catchTotalRejectedComputedOrNotWeight.setData(catchTotalRejectedWeight);
485         firePropertyChange(PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, oldValue, catchTotalRejectedWeight);
486     }
487 
488     @Override
489     public Float getCatchTotalRejectedComputedWeight() {
490         return catchTotalRejectedComputedOrNotWeight.getComputedData();
491     }
492 
493     @Override
494     public void setCatchTotalRejectedComputedWeight(Float catchTotalRejectedComputedWeight) {
495         Object oldValue = getCatchTotalRejectedComputedWeight();
496         this.catchTotalRejectedComputedOrNotWeight.setComputedData(catchTotalRejectedComputedWeight);
497         firePropertyChange(PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, oldValue, catchTotalRejectedComputedWeight);
498     }
499 
500     //------------------------------------------------------------------------//
501     //-- Species                                                            --//
502     //------------------------------------------------------------------------//
503 
504     @Override
505     public Float getSpeciesTotalComputedWeight() {
506         return speciesTotalComputedWeight;
507     }
508 
509     @Override
510     public void setSpeciesTotalComputedWeight(Float speciesTotalComputedWeight) {
511         Object oldValue = getSpeciesTotalComputedWeight();
512         this.speciesTotalComputedWeight = speciesTotalComputedWeight;
513         firePropertyChange(PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, oldValue, speciesTotalComputedWeight);
514     }
515 
516     public ComputableData<Float> getSpeciesTotalSortedComputedOrNotWeight() {
517         return speciesTotalSortedComputedOrNotWeight;
518     }
519 
520     @Override
521     public Float getSpeciesTotalSortedWeight() {
522         return speciesTotalSortedComputedOrNotWeight.getData();
523     }
524 
525     @Override
526     public void setSpeciesTotalSortedWeight(Float speciesTotalSortedWeight) {
527         Object oldValue = getSpeciesTotalSortedWeight();
528         this.speciesTotalSortedComputedOrNotWeight.setData(speciesTotalSortedWeight);
529         firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, oldValue, speciesTotalSortedWeight);
530     }
531 
532     @Override
533     public Float getSpeciesTotalSortedComputedWeight() {
534         return speciesTotalSortedComputedOrNotWeight.getComputedData();
535     }
536 
537     @Override
538     public void setSpeciesTotalSortedComputedWeight(Float speciesTotalSortedComputedWeight) {
539         Object oldValue = getSpeciesTotalSortedComputedWeight();
540         this.speciesTotalSortedComputedOrNotWeight.setComputedData(speciesTotalSortedComputedWeight);
541         firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, oldValue, speciesTotalSortedComputedWeight);
542     }
543 
544     @Override
545     public Float getSpeciesTotalSampleSortedComputedWeight() {
546         return speciesTotalSampleSortedComputedWeight;
547     }
548 
549     @Override
550     public void setSpeciesTotalSampleSortedComputedWeight(Float speciesTotalSampleSortedComputedWeight) {
551         Object oldValue = getSpeciesTotalSampleSortedComputedWeight();
552         this.speciesTotalSampleSortedComputedWeight = speciesTotalSampleSortedComputedWeight;
553         firePropertyChange(PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, oldValue, speciesTotalSampleSortedComputedWeight);
554     }
555 
556     @Override
557     public Float getSpeciesTotalUnsortedComputedWeight() {
558         return speciesTotalUnsortedComputedWeight;
559     }
560 
561     @Override
562     public void setSpeciesTotalUnsortedComputedWeight(Float speciesTotalUnsortedComputedWeight) {
563         Object oldValue = getSpeciesTotalUnsortedComputedWeight();
564         this.speciesTotalUnsortedComputedWeight = speciesTotalUnsortedComputedWeight;
565         firePropertyChange(PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, oldValue, speciesTotalUnsortedComputedWeight);
566     }
567 
568     public ComputableData<Float> getSpeciesTotalInertComputedOrNotWeight() {
569         return speciesTotalInertComputedOrNotWeight;
570     }
571 
572     @Override
573     public Float getSpeciesTotalInertWeight() {
574         return speciesTotalInertComputedOrNotWeight.getData();
575     }
576 
577     @Override
578     public void setSpeciesTotalInertWeight(Float speciesTotalInertWeight) {
579         Object oldValue = getSpeciesTotalInertWeight();
580         this.speciesTotalInertComputedOrNotWeight.setData(speciesTotalInertWeight);
581         firePropertyChange(PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, oldValue, speciesTotalInertWeight);
582     }
583 
584     @Override
585     public Float getSpeciesTotalInertComputedWeight() {
586         return speciesTotalInertComputedOrNotWeight.getComputedData();
587     }
588 
589     @Override
590     public void setSpeciesTotalInertComputedWeight(Float speciesTotalInertComputedWeight) {
591         Object oldValue = getSpeciesTotalInertComputedWeight();
592         this.speciesTotalInertComputedOrNotWeight.setComputedData(speciesTotalInertComputedWeight);
593         firePropertyChange(PROPERTY_SPECIES_TOTAL_INERT_COMPUTED_WEIGHT, oldValue, speciesTotalInertComputedWeight);
594     }
595 
596     public ComputableData<Float> getSpeciesTotalLivingNotItemizedComputedOrNotWeight() {
597         return speciesTotalLivingNotItemizedComputedOrNotWeight;
598     }
599 
600     @Override
601     public Float getSpeciesTotalLivingNotItemizedWeight() {
602         return speciesTotalLivingNotItemizedComputedOrNotWeight.getData();
603     }
604 
605     @Override
606     public void setSpeciesTotalLivingNotItemizedWeight(Float speciesTotalLivingNotItemizedWeight) {
607         Object oldValue = getSpeciesTotalLivingNotItemizedComputedWeight();
608         this.speciesTotalLivingNotItemizedComputedOrNotWeight.setData(speciesTotalLivingNotItemizedWeight);
609         firePropertyChange(PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, oldValue, speciesTotalLivingNotItemizedWeight);
610     }
611 
612     @Override
613     public Float getSpeciesTotalLivingNotItemizedComputedWeight() {
614         return speciesTotalLivingNotItemizedComputedOrNotWeight.getComputedData();
615     }
616 
617     @Override
618     public void setSpeciesTotalLivingNotItemizedComputedWeight(Float speciesTotalLivingNotItemizedComputedWeight) {
619         Object oldValue = getSpeciesTotalLivingNotItemizedComputedWeight();
620         this.speciesTotalLivingNotItemizedComputedOrNotWeight.setComputedData(speciesTotalLivingNotItemizedComputedWeight);
621         firePropertyChange(PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_COMPUTED_WEIGHT, oldValue, speciesTotalLivingNotItemizedComputedWeight);
622     }
623 
624     /**
625      * Les espèces observées sont en warning lorsque :
626      *
627      * * pas de poids vrac non trié (ou = 0)
628      * * poids espèce observé (hors vrac) présent et &gt; 0
629      * * poids espèce observé (vrac) vaut poids espèce trié (vrac)
630      *
631      * @return {@code true} quand le les espèces observées sont en warning, {@code false} dans les autres cas.
632      */
633     public boolean isSpeciesTotalUnsortedComputedWeightInWarning() {
634         Float catchTotalRejectedWeight = getCatchTotalRejectedComputedOrNotWeight().getDataOrComputedData();
635         Float speciesTotalSortedWeight = getSpeciesTotalSortedComputedOrNotWeight().getDataOrComputedData();
636 
637         boolean noCatchTotalRejected = WeightUnit.KG.isNullOrZero(catchTotalRejectedWeight);
638         boolean noTotalUnsortedWeight = speciesTotalUnsortedComputedWeight != null && WeightUnit.KG.isGreaterThanZero(speciesTotalUnsortedComputedWeight);
639         boolean speciesWeightEquals = speciesTotalSortedWeight != null && speciesTotalSampleSortedComputedWeight !=null
640                                       && WeightUnit.KG.isEquals(speciesTotalSortedWeight, speciesTotalSampleSortedComputedWeight);
641 
642         return noTotalUnsortedWeight && noCatchTotalRejected && speciesWeightEquals;
643     }
644 
645     //------------------------------------------------------------------------//
646     //-- Benthos                                                            --//
647     //------------------------------------------------------------------------//
648 
649     @Override
650     public Float getBenthosTotalComputedWeight() {
651         return benthosTotalComputedWeight;
652     }
653 
654     @Override
655     public void setBenthosTotalComputedWeight(Float benthosTotalComputedWeight) {
656         Object oldValue = getBenthosTotalComputedWeight();
657         this.benthosTotalComputedWeight = benthosTotalComputedWeight;
658         firePropertyChange(PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, oldValue, benthosTotalComputedWeight);
659     }
660 
661     public ComputableData<Float> getBenthosTotalSortedComputedOrNotWeight() {
662         return benthosTotalSortedComputedOrNotWeight;
663     }
664 
665     @Override
666     public Float getBenthosTotalSortedWeight() {
667         return benthosTotalSortedComputedOrNotWeight.getData();
668     }
669 
670     @Override
671     public void setBenthosTotalSortedWeight(Float benthosTotalSortedWeight) {
672         Object oldValue = getBenthosTotalSortedWeight();
673         this.benthosTotalSortedComputedOrNotWeight.setData(benthosTotalSortedWeight);
674         firePropertyChange(PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, oldValue, benthosTotalSortedWeight);
675     }
676 
677     @Override
678     public Float getBenthosTotalSortedComputedWeight() {
679         return benthosTotalSortedComputedOrNotWeight.getComputedData();
680     }
681 
682     @Override
683     public void setBenthosTotalSortedComputedWeight(Float benthosTotalSortedComputedWeight) {
684         Object oldValue = getBenthosTotalSortedComputedWeight();
685         this.benthosTotalSortedComputedOrNotWeight.setComputedData(benthosTotalSortedComputedWeight);
686         firePropertyChange(PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, oldValue, benthosTotalSortedComputedWeight);
687     }
688 
689     @Override
690     public Float getBenthosTotalSampleSortedComputedWeight() {
691         return benthosTotalSampleSortedComputedWeight;
692     }
693 
694     @Override
695     public void setBenthosTotalSampleSortedComputedWeight(Float benthosTotalSampleSortedComputedWeight) {
696         Object oldValue = getBenthosTotalSampleSortedComputedWeight();
697         this.benthosTotalSampleSortedComputedWeight = benthosTotalSampleSortedComputedWeight;
698         firePropertyChange(PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, oldValue, benthosTotalSampleSortedComputedWeight);
699     }
700 
701     @Override
702     public Float getBenthosTotalUnsortedComputedWeight() {
703         return benthosTotalUnsortedComputedWeight;
704     }
705 
706     @Override
707     public void setBenthosTotalUnsortedComputedWeight(Float benthosTotalUnsortedComputedWeight) {
708         Object oldValue = getBenthosTotalUnsortedComputedWeight();
709         this.benthosTotalUnsortedComputedWeight = benthosTotalUnsortedComputedWeight;
710         firePropertyChange(PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, oldValue, benthosTotalUnsortedComputedWeight);
711     }
712 
713     public ComputableData<Float> getBenthosTotalInertComputedOrNotWeight() {
714         return benthosTotalInertComputedOrNotWeight;
715     }
716 
717     @Override
718     public Float getBenthosTotalInertWeight() {
719         return benthosTotalInertComputedOrNotWeight.getData();
720     }
721 
722     @Override
723     public void setBenthosTotalInertWeight(Float benthosTotalInertWeight) {
724         Object oldValue = getBenthosTotalInertWeight();
725         this.benthosTotalInertComputedOrNotWeight.setData(benthosTotalInertWeight);
726         firePropertyChange(PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, oldValue, benthosTotalInertWeight);
727     }
728 
729     @Override
730     public Float getBenthosTotalInertComputedWeight() {
731         return benthosTotalInertComputedOrNotWeight.getComputedData();
732     }
733 
734     @Override
735     public void setBenthosTotalInertComputedWeight(Float benthosTotalInertComputedWeight) {
736         Object oldValue = getBenthosTotalInertComputedWeight();
737         this.benthosTotalInertComputedOrNotWeight.setComputedData(benthosTotalInertComputedWeight);
738         firePropertyChange(PROPERTY_BENTHOS_TOTAL_INERT_COMPUTED_WEIGHT, oldValue, benthosTotalInertComputedWeight);
739     }
740 
741     public ComputableData<Float> getBenthosTotalLivingNotItemizedComputedOrNotWeight() {
742         return benthosTotalLivingNotItemizedComputedOrNotWeight;
743     }
744 
745     @Override
746     public Float getBenthosTotalLivingNotItemizedWeight() {
747         return benthosTotalLivingNotItemizedComputedOrNotWeight.getData();
748     }
749 
750     @Override
751     public void setBenthosTotalLivingNotItemizedWeight(Float benthosTotalLivingNotItemizedWeight) {
752         Object oldValue = getBenthosTotalLivingNotItemizedComputedWeight();
753         this.benthosTotalLivingNotItemizedComputedOrNotWeight.setData(benthosTotalLivingNotItemizedWeight);
754         firePropertyChange(PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, oldValue, benthosTotalLivingNotItemizedWeight);
755     }
756 
757     @Override
758     public Float getBenthosTotalLivingNotItemizedComputedWeight() {
759         return benthosTotalLivingNotItemizedComputedOrNotWeight.getComputedData();
760     }
761 
762     @Override
763     public void setBenthosTotalLivingNotItemizedComputedWeight(Float benthosTotalLivingNotItemizedComputedWeight) {
764         Object oldValue = getBenthosTotalLivingNotItemizedComputedWeight();
765         this.benthosTotalLivingNotItemizedComputedOrNotWeight.setComputedData(benthosTotalLivingNotItemizedComputedWeight);
766         firePropertyChange(PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_COMPUTED_WEIGHT, oldValue, benthosTotalLivingNotItemizedComputedWeight);
767     }
768 
769     /**
770      * Le benthos observé est en warning lorsque :
771      *
772      * * pas de poids vrac non trié (ou = 0)
773      * * poids benthos observé (hors vrac) présent et &gt; 0
774      * * poids benthos observé (vrac) vaut poids benthos trié (vrac)
775      *
776      * @return {@code true} quand le le benthos est en warning, {@code false} dans les autres cas.
777      */
778     public boolean isBenthosTotalUnsortedComputedWeightInWarning() {
779         Float catchTotalRejectedWeight = getCatchTotalRejectedComputedOrNotWeight().getDataOrComputedData();
780         Float benthosTotalSortedWeight = getBenthosTotalSortedComputedOrNotWeight().getDataOrComputedData();
781 
782         boolean noCatchTotalRejected = WeightUnit.KG.isNullOrZero(catchTotalRejectedWeight);
783         boolean noTotalUnsortedWeight = benthosTotalUnsortedComputedWeight != null && WeightUnit.KG.isGreaterThanZero(benthosTotalUnsortedComputedWeight);
784         boolean benthosWeightEquals = benthosTotalSortedWeight != null && benthosTotalSampleSortedComputedWeight !=null
785                                       && WeightUnit.KG.isEquals(benthosTotalSortedWeight, benthosTotalSampleSortedComputedWeight);
786 
787         return noTotalUnsortedWeight && noCatchTotalRejected && benthosWeightEquals;
788 
789     }
790 
791     //------------------------------------------------------------------------//
792     //-- Marine Litter                                                      --//
793     //------------------------------------------------------------------------//
794 
795     public ComputableData<Float> getMarineLitterTotalComputedOrNotWeight() {
796         return marineLitterTotalComputedOrNotWeight;
797     }
798 
799     @Override
800     public Float getMarineLitterTotalWeight() {
801         return marineLitterTotalComputedOrNotWeight.getData();
802     }
803 
804     @Override
805     public void setMarineLitterTotalWeight(Float marineLitterTotalWeight) {
806         Object oldValue = getMarineLitterTotalWeight();
807         this.marineLitterTotalComputedOrNotWeight.setData(marineLitterTotalWeight);
808         firePropertyChange(PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, oldValue, marineLitterTotalWeight);
809     }
810 
811     @Override
812     public Float getMarineLitterTotalComputedWeight() {
813         return marineLitterTotalComputedOrNotWeight.getComputedData();
814     }
815 
816     @Override
817     public void setMarineLitterTotalComputedWeight(Float marineLitterTotalComputedWeight) {
818         Object oldValue = getMarineLitterTotalComputedWeight();
819         this.marineLitterTotalComputedOrNotWeight.setComputedData(marineLitterTotalComputedWeight);
820         firePropertyChange(PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, oldValue, marineLitterTotalComputedWeight);
821     }
822 
823     //------------------------------------------------------------------------//
824     //-- Attachment                                                         --//
825     //------------------------------------------------------------------------//
826 
827     @Override
828     public ObjectTypeCode getObjectType() {
829         return ObjectTypeCode.CATCH_BATCH;
830     }
831 
832     @Override
833     public Integer getObjectId() {
834         return editObject == null ? null : editObject.getIdAsInt();
835     }
836 
837     @Override
838     public List<Attachment> getAttachment() {
839         return attachment;
840     }
841 
842     @Override
843     public void addAllAttachment(Collection<Attachment> attachments) {
844         this.attachment.addAll(attachments);
845         firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment());
846     }
847 
848     @Override
849     public void addAttachment(Attachment attachment) {
850         this.attachment.add(attachment);
851         firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment());
852     }
853 
854     @Override
855     public void removeAllAttachment(Collection<Attachment> attachments) {
856         this.attachment.removeAll(attachments);
857         firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment());
858     }
859 
860     @Override
861     public void removeAttachment(Attachment attachment) {
862         this.attachment.remove(attachment);
863         firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment());
864     }
865 
866     @Override
867     public String getSynchronizationStatus() {
868         return editObject.getSynchronizationStatus();
869     }
870 
871     @Override
872     public void setSynchronizationStatus(String synchronizationStatus) {
873         String oldValue = getSynchronizationStatus();
874         editObject.setSynchronizationStatus(synchronizationStatus);
875         firePropertyChange(PROPERTY_SYNCHRONIZATION_STATUS, oldValue, synchronizationStatus);
876     }
877 
878     @Override
879     public Float getCatchTotalSortedSortedComputedWeight() {
880         return catchTotalSortedSortedComputedWeight;
881     }
882 
883     @Override
884     public void setCatchTotalSortedSortedComputedWeight(Float catchTotalSortedSortedComputedWeight) {
885         Object oldValue = getCatchTotalSortedSortedComputedWeight();
886         this.catchTotalSortedSortedComputedWeight = catchTotalSortedSortedComputedWeight;
887         firePropertyChange(PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, oldValue, catchTotalSortedSortedComputedWeight);
888     }
889 
890     @Override
891     public Integer getSpeciesDistinctSortedSpeciesCount() {
892         return editObject.getSpeciesDistinctSortedSpeciesCount();
893     }
894 
895     @Override
896     public void setSpeciesDistinctSortedSpeciesCount(Integer speciesDistinctSortedSpeciesCount) {
897         Object oldValue = getSpeciesDistinctSortedSpeciesCount();
898         this.editObject.setSpeciesDistinctSortedSpeciesCount(speciesDistinctSortedSpeciesCount);
899         firePropertyChange(PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT, oldValue, speciesDistinctSortedSpeciesCount);
900     }
901 
902     @Override
903     public Integer getBenthosDistinctSortedSpeciesCount() {
904         return editObject.getBenthosDistinctSortedSpeciesCount();
905     }
906 
907     @Override
908     public void setBenthosDistinctSortedSpeciesCount(Integer benthosDistinctSortedSpeciesCount) {
909         Object oldValue = getBenthosDistinctSortedSpeciesCount();
910         this.editObject.setBenthosDistinctSortedSpeciesCount(benthosDistinctSortedSpeciesCount);
911         firePropertyChange(PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT, oldValue, benthosDistinctSortedSpeciesCount);
912     }
913 
914     @Override
915     public Integer getBenthosDistinctUnsortedSpeciesCount() {
916         return editObject.getBenthosDistinctUnsortedSpeciesCount();
917     }
918 
919     @Override
920     public Integer getSpeciesDistinctUnsortedSpeciesCount() {
921         return editObject.getSpeciesDistinctUnsortedSpeciesCount();
922     }
923 
924     @Override
925     public void setSpeciesDistinctUnsortedSpeciesCount(Integer speciesDistinctUnsortedSpeciesCount) {
926         Object oldValue = getSpeciesDistinctUnsortedSpeciesCount();
927         this.editObject.setSpeciesDistinctUnsortedSpeciesCount(speciesDistinctUnsortedSpeciesCount);
928         firePropertyChange(PROPERTY_SPECIES_DISTINCT_UNSORTED_SPECIES_COUNT, oldValue, speciesDistinctUnsortedSpeciesCount);
929     }
930 
931     @Override
932     public void setBenthosDistinctUnsortedSpeciesCount(Integer benthosDistinctUnsortedSpeciesCount) {
933         Object oldValue = getBenthosDistinctUnsortedSpeciesCount();
934         this.editObject.setBenthosDistinctUnsortedSpeciesCount(benthosDistinctUnsortedSpeciesCount);
935         firePropertyChange(PROPERTY_BENTHOS_DISTINCT_UNSORTED_SPECIES_COUNT, oldValue, benthosDistinctUnsortedSpeciesCount);
936     }
937 
938     public void reset() {
939         setSpeciesTotalInertComputedWeight(null);
940         setSpeciesTotalLivingNotItemizedComputedWeight(null);
941         setSpeciesTotalSampleSortedComputedWeight(null);
942         setSpeciesTotalSortedComputedWeight(null);
943         setSpeciesTotalUnsortedComputedWeight(null);
944         setSpeciesTotalComputedWeight(null);
945         setBenthosTotalInertComputedWeight(null);
946         setBenthosTotalLivingNotItemizedComputedWeight(null);
947         setBenthosTotalSampleSortedComputedWeight(null);
948         setBenthosTotalSortedComputedWeight(null);
949         setBenthosTotalUnsortedComputedWeight(null);
950         setBenthosTotalComputedWeight(null);
951         setMarineLitterTotalComputedWeight(null);
952         setCatchTotalRejectedComputedWeight(null);
953         setCatchTotalSortedComputedWeight(null);
954         setCatchTotalSortedSortedComputedWeight(null);
955         setCatchTotalUnsortedComputedWeight(null);
956         setCatchTotalComputedWeight(null);
957         removeAllAttachment(getAttachment());
958         getSpeciesUsed().clear();
959         getMarineLitterCategoriesUsed().clear();
960         setSpeciesDistinctSortedSpeciesCount(null);
961         setBenthosDistinctSortedSpeciesCount(null);
962         setSpeciesDistinctUnsortedSpeciesCount(null);
963         setBenthosDistinctUnsortedSpeciesCount(null);
964     }
965 
966     public boolean isDoNotCheckLeavingFrequencyScreen() {
967         return doNotCheckLeavingFrequencyScreen;
968     }
969 
970     public void setDoNotCheckLeavingFrequencyScreen(boolean doNotCheckLeavingFrequencyScreen) {
971         this.doNotCheckLeavingFrequencyScreen = doNotCheckLeavingFrequencyScreen;
972     }
973 }