View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.protocol;
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 fr.ifremer.tutti.persistence.entities.protocol.CalcifiedPiecesSamplingDefinition;
26  import fr.ifremer.tutti.persistence.entities.protocol.Rtp;
27  import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
28  import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocols;
29  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
30  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
31  import fr.ifremer.tutti.persistence.entities.referential.Species;
32  import fr.ifremer.tutti.persistence.entities.referential.Speciess;
33  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
34  import org.nuiton.util.beans.Binder;
35  import org.nuiton.util.beans.BinderFactory;
36  
37  import java.util.Collection;
38  import java.util.LinkedList;
39  import java.util.List;
40  
41  /**
42   * @author kmorin
43   * @since 0.3
44   */
45  public class EditProtocolSpeciesRowModel extends AbstractTuttiBeanUIModel<SpeciesProtocol, EditProtocolSpeciesRowModel> implements SpeciesProtocol {
46  
47      private static final long serialVersionUID = 1L;
48  
49      public static final String PROPERTY_SPECIES_SURVEY_CODE = "speciesSurveyCode";
50  
51      public static final String PROPERTY_SPECIES = "species";
52  
53      public static final String PROPERTY_LENGTH_STEP_PMFM = "lengthStepPmfm";
54  
55      public static final String PROPERTY_WEIGHT_ENABLED = "weightEnabled";
56  
57      public static final String PROPERTY_MATURITY_PMFM = "maturityPmfm";
58  
59      public static final String PROPERTY_CALCIFIED_PIECES_SAMPLING_TYPE = "calcifiedPiecesSamplingType";
60  
61      public static final String PROPERTY_USE_RTP = "useRtp";
62  
63      protected Species species;
64  
65      protected String speciesSurveyCode;
66  
67      protected Caracteristic lengthStepPmfm;
68  
69      protected boolean weightEnabled;
70  
71  //    protected boolean countIfNoFrequencyEnabled;
72  //
73  //    protected boolean calcifySampleEnabled;
74  
75      protected List<Integer> mandatorySampleCategoryId;
76  
77      protected boolean individualObservationEnabled;
78  
79      protected Caracteristic maturityPmfm;
80  
81      protected CaracteristicQualitativeValue calcifiedPiecesSamplingType;
82  
83      protected Rtp rtpMale;
84  
85      protected Rtp rtpFemale;
86  
87      protected Rtp rtpUndefined;
88  
89      Collection<CalcifiedPiecesSamplingDefinition> calcifiedPiecesSamplingDefinition;
90  
91      protected static final Binder<SpeciesProtocol, EditProtocolSpeciesRowModel> fromBeanBinder =
92              BinderFactory.newBinder(SpeciesProtocol.class,
93                      EditProtocolSpeciesRowModel.class);
94  
95      protected static final Binder<EditProtocolSpeciesRowModel, SpeciesProtocol> toBeanBinder =
96              BinderFactory.newBinder(EditProtocolSpeciesRowModel.class,
97                      SpeciesProtocol.class);
98  
99      public EditProtocolSpeciesRowModel() {
100         super(fromBeanBinder, toBeanBinder);
101     }
102 
103     @Override
104     public Integer getSpeciesReferenceTaxonId() {
105         return species.getReferenceTaxonId();
106     }
107 
108     @Override
109     public void setSpeciesReferenceTaxonId(Integer speciesReferenceTaxonId) {
110     }
111 
112     public Species getSpecies() {
113         return species;
114     }
115 
116     public void setSpecies(Species species) {
117         Object oldValue = getSpecies();
118         this.species = species;
119         firePropertyChange(PROPERTY_SPECIES, oldValue, species);
120     }
121 
122     @Override
123     public String getSpeciesSurveyCode() {
124         return speciesSurveyCode;
125     }
126 
127     @Override
128     public void setSpeciesSurveyCode(String speciesSurveyCode) {
129         Object oldValue = getSpeciesSurveyCode();
130         this.speciesSurveyCode = speciesSurveyCode;
131         firePropertyChange(PROPERTY_SPECIES_SURVEY_CODE, oldValue, speciesSurveyCode);
132     }
133 
134     @Override
135     public String getLengthStepPmfmId() {
136         return lengthStepPmfm != null ? lengthStepPmfm.getId() : null;
137     }
138 
139     @Override
140     public void setLengthStepPmfmId(String lengthStepPmfmId) {
141     }
142 
143     @Override
144     public boolean withLengthStepPmfm() {
145         return lengthStepPmfm != null;
146     }
147 
148     @Override
149     public boolean withMaturityPmfm() {
150         return maturityPmfm != null;
151     }
152 
153     @Override
154     public boolean withCalcifiedPiecesSamplingType() {
155         return calcifiedPiecesSamplingType != null;
156     }
157 
158     public Caracteristic getLengthStepPmfm() {
159         return lengthStepPmfm;
160     }
161 
162     public void setLengthStepPmfm(Caracteristic lengthStepPmfm) {
163         Object oldValue = getLengthStepPmfm();
164         this.lengthStepPmfm = lengthStepPmfm;
165         firePropertyChange(PROPERTY_LENGTH_STEP_PMFM, oldValue, lengthStepPmfm);
166     }
167 
168     @Override
169     public boolean isWeightEnabled() {
170         return weightEnabled;
171     }
172 
173     @Override
174     public void setWeightEnabled(boolean weightEnabled) {
175         Object oldValue = isWeightEnabled();
176         this.weightEnabled = weightEnabled;
177         firePropertyChange(PROPERTY_WEIGHT_ENABLED, oldValue, weightEnabled);
178     }
179 
180     @Override
181     public Float getLengthStep() {
182         return null;
183     }
184 
185     @Override
186     public void setLengthStep(Float lengthStep) {
187     }
188 
189     @Override
190     public boolean isMadeFromAReferentTaxon() {
191         return false;
192     }
193 
194     @Override
195     public void setMadeFromAReferentTaxon(boolean madeFromAReferentTaxon) {
196     }
197 
198     @Override
199     protected SpeciesProtocol newEntity() {
200         return SpeciesProtocols.newSpeciesProtocol();
201     }
202 
203     @Override
204     public Integer getMandatorySampleCategoryId(int index) {
205         return getChild(mandatorySampleCategoryId, index);
206     }
207 
208     @Override
209     public boolean isMandatorySampleCategoryIdEmpty() {
210         return mandatorySampleCategoryId == null || mandatorySampleCategoryId.isEmpty();
211     }
212 
213     @Override
214     public int sizeMandatorySampleCategoryId() {
215         return mandatorySampleCategoryId == null ? 0 : mandatorySampleCategoryId.size();
216     }
217 
218     @Override
219     public void addMandatorySampleCategoryId(Integer mandatorySampleCategoryId) {
220         getMandatorySampleCategoryId().add(mandatorySampleCategoryId);
221     }
222 
223     @Override
224     public void addAllMandatorySampleCategoryId(Collection<Integer> mandatorySampleCategoryId) {
225         getMandatorySampleCategoryId().addAll(mandatorySampleCategoryId);
226     }
227 
228     @Override
229     public boolean removeMandatorySampleCategoryId(Integer mandatorySampleCategoryId) {
230         return getMandatorySampleCategoryId().remove(mandatorySampleCategoryId);
231     }
232 
233     @Override
234     public boolean removeAllMandatorySampleCategoryId(Collection<Integer> mandatorySampleCategoryId) {
235         return getMandatorySampleCategoryId().removeAll(mandatorySampleCategoryId);
236     }
237 
238     @Override
239     public boolean containsMandatorySampleCategoryId(Integer mandatorySampleCategoryId) {
240         return getMandatorySampleCategoryId().contains(mandatorySampleCategoryId);
241     }
242 
243     @Override
244     public boolean containsAllMandatorySampleCategoryId(Collection<Integer> mandatorySampleCategoryId) {
245         return getMandatorySampleCategoryId().containsAll(mandatorySampleCategoryId);
246     }
247 
248     @Override
249     public List<Integer> getMandatorySampleCategoryId() {
250         return mandatorySampleCategoryId;
251     }
252 
253     @Override
254     public void setMandatorySampleCategoryId(List<Integer> mandatorySampleCategoryId) {
255         this.mandatorySampleCategoryId = mandatorySampleCategoryId;
256         firePropertyChange(PROPERTY_MANDATORY_SAMPLE_CATEGORY_ID, null, mandatorySampleCategoryId);
257     }
258 
259     @Override
260     public boolean isIndividualObservationEnabled() {
261         return individualObservationEnabled;
262     }
263 
264     @Override
265     public void setIndividualObservationEnabled(boolean individualObservationEnabled) {
266         Object oldValue = isIndividualObservationEnabled();
267         this.individualObservationEnabled = individualObservationEnabled;
268         firePropertyChange(PROPERTY_INDIVIDUAL_OBSERVATION_ENABLED, oldValue, individualObservationEnabled);
269     }
270 
271     @Override
272     public String getMaturityPmfmId() {
273         return maturityPmfm != null ? maturityPmfm.getId() : null;
274     }
275 
276     @Override
277     public void setMaturityPmfmId(String maturityPmfmId) {
278     }
279 
280     public Caracteristic getMaturityPmfm() {
281         return maturityPmfm;
282     }
283 
284     public void setMaturityPmfm(Caracteristic maturityPmfm) {
285         Object oldValue = getMaturityPmfm();
286         this.maturityPmfm = maturityPmfm;
287         firePropertyChange(PROPERTY_MATURITY_PMFM, oldValue, maturityPmfm);
288     }
289 
290     @Override
291     public CaracteristicQualitativeValue getCalcifiedPiecesSamplingType() {
292         return calcifiedPiecesSamplingType;
293     }
294 
295     @Override
296     public void setCalcifiedPiecesSamplingType(CaracteristicQualitativeValue calcifiedPiecesSamplingType) {
297         Object oldValue = getCalcifiedPiecesSamplingType();
298         this.calcifiedPiecesSamplingType = calcifiedPiecesSamplingType;
299         firePropertyChange(PROPERTY_CALCIFIED_PIECES_SAMPLING_TYPE, oldValue, calcifiedPiecesSamplingType);
300     }
301 
302     public boolean isUseRtp() {
303         return withRtpFemale() && withRtpMale() && withRtpUndefined();
304     }
305 
306     public void setUseRtp(boolean useRtp) {
307 //        Object oldValue = isUseRtp();
308 //        this.useRtp = useRtp;
309         // Normalement pas utilisé
310         firePropertyChange(PROPERTY_USE_RTP, null, useRtp);
311     }
312 
313     @Override
314     public Rtp getRtpMale() {
315         return rtpMale;
316     }
317 
318     @Override
319     public void setRtpMale(Rtp rtpMale) {
320         Object oldValue = getRtpMale();
321         this.rtpMale = rtpMale;
322         firePropertyChange(PROPERTY_RTP_MALE, oldValue, rtpMale);
323     }
324 
325     @Override
326     public Rtp getRtpFemale() {
327         return rtpFemale;
328     }
329 
330     @Override
331     public void setRtpFemale(Rtp rtpFemale) {
332         Object oldValue = getRtpFemale();
333         this.rtpFemale = rtpFemale;
334         firePropertyChange(PROPERTY_RTP_FEMALE, oldValue, rtpFemale);
335     }
336 
337     @Override
338     public Rtp getRtpUndefined() {
339         return rtpUndefined;
340     }
341 
342     public void setRtpUndefined(Rtp rtpUndefined) {
343         Object oldValue = getRtpUndefined();
344         this.rtpUndefined = rtpUndefined;
345         firePropertyChange(PROPERTY_RTP_UNDEFINED, oldValue, rtpUndefined);
346     }
347 
348     @Override
349     public CalcifiedPiecesSamplingDefinition getCalcifiedPiecesSamplingDefinition(int index) {
350         return getChild(calcifiedPiecesSamplingDefinition, index);
351     }
352 
353     @Override
354     public boolean isCalcifiedPiecesSamplingDefinitionEmpty() {
355         return calcifiedPiecesSamplingDefinition == null || calcifiedPiecesSamplingDefinition.isEmpty();
356     }
357 
358     @Override
359     public int sizeCalcifiedPiecesSamplingDefinition() {
360         return calcifiedPiecesSamplingDefinition == null ? 0 : calcifiedPiecesSamplingDefinition.size();
361     }
362 
363     @Override
364     public void addCalcifiedPiecesSamplingDefinition(CalcifiedPiecesSamplingDefinition calcifiedPiecesSamplingDefinition) {
365         getCalcifiedPiecesSamplingDefinition().add(calcifiedPiecesSamplingDefinition);
366     }
367 
368     @Override
369     public void addAllCalcifiedPiecesSamplingDefinition(Collection<CalcifiedPiecesSamplingDefinition> calcifiedPiecesSamplingDefinition) {
370         getCalcifiedPiecesSamplingDefinition().addAll(calcifiedPiecesSamplingDefinition);
371     }
372 
373     @Override
374     public boolean removeCalcifiedPiecesSamplingDefinition(CalcifiedPiecesSamplingDefinition calcifiedPiecesSamplingDefinition) {
375         return getCalcifiedPiecesSamplingDefinition().remove(calcifiedPiecesSamplingDefinition);
376     }
377 
378     @Override
379     public boolean removeAllCalcifiedPiecesSamplingDefinition(Collection<CalcifiedPiecesSamplingDefinition> calcifiedPiecesSamplingDefinition) {
380         return getCalcifiedPiecesSamplingDefinition().removeAll(calcifiedPiecesSamplingDefinition);
381     }
382 
383     @Override
384     public boolean containsCalcifiedPiecesSamplingDefinition(CalcifiedPiecesSamplingDefinition calcifiedPiecesSamplingDefinition) {
385         return getCalcifiedPiecesSamplingDefinition().contains(calcifiedPiecesSamplingDefinition);
386     }
387 
388     @Override
389     public boolean containsAllCalcifiedPiecesSamplingDefinition(Collection<CalcifiedPiecesSamplingDefinition> calcifiedPiecesSamplingDefinition) {
390         return getCalcifiedPiecesSamplingDefinition().containsAll(calcifiedPiecesSamplingDefinition);
391     }
392 
393     @Override
394     public Collection<CalcifiedPiecesSamplingDefinition> getCalcifiedPiecesSamplingDefinition() {
395         if (calcifiedPiecesSamplingDefinition == null) {
396             calcifiedPiecesSamplingDefinition = new LinkedList<>();
397         }
398         return calcifiedPiecesSamplingDefinition;
399     }
400 
401     @Override
402     public void setCalcifiedPiecesSamplingDefinition(Collection<CalcifiedPiecesSamplingDefinition> calcifiedPiecesSamplingDefinition) {
403         this.calcifiedPiecesSamplingDefinition = calcifiedPiecesSamplingDefinition;
404     }
405 
406     @Override
407     public boolean withRtpMale() {
408         return rtpMale != null;
409     }
410 
411     @Override
412     public boolean withRtpFemale() {
413         return rtpFemale != null;
414     }
415 
416     @Override
417     public boolean withRtpUndefined() {
418         return rtpUndefined != null;
419     }
420 
421     public Species toSpeciesWithSurveyCode() {
422         Species source = getSpecies();
423         Species target = Speciess.newSpecies(source);
424         target.setSurveyCode(getSpeciesSurveyCode());
425         return target;
426     }
427 }