View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.observation.operation.measurement.grouped.initGrid;
2   
3   /*
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   *
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   *
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.collect.ArrayListMultimap;
27  import com.google.common.collect.Multimap;
28  import fr.ifremer.quadrige3.ui.swing.model.AbstractEmptyUIModel;
29  import fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO;
30  import fr.ifremer.reefdb.dto.referential.UnitDTO;
31  
32  import java.util.List;
33  
34  /**
35   * Created by Ludovic on 26/05/2015.
36   */
37  public class InitGridUIModel extends AbstractEmptyUIModel<InitGridUIModel> {
38  
39      private List<SamplingOperationDTO> samplingOperations;
40      public static final String PROPERTY_SAMPLING_OPERATIONS = "samplingOperations";
41  
42      private SamplingOperationDTO samplingOperation;
43      public static final String PROPERTY_SAMPLING_OPERATION = "samplingOperation";
44  
45      private SamplingOperationDTO lastSamplingOperation;
46  
47      private boolean allSamplingOperations;
48      public static final String PROPERTY_ALL_SAMPLING_OPERATIONS = "allSamplingOperations";
49  
50      private boolean contiguousSamplingOperations;
51      public static final String PROPERTY_CONTIGUOUS_SAMPLING_OPERATIONS = "contiguousSamplingOperations";
52  
53      private Integer origin;
54      public static final String PROPERTY_ORIGIN = "origin";
55  
56      private Integer transition;
57      public static final String PROPERTY_TRANSITION = "transition";
58  
59      private Integer length;
60      public static final String PROPERTY_LENGTH = "length";
61  
62      private int originPmfmId;
63      private int lengthPmfmId;
64      private int transitionPmfmId;
65  
66      private UnitDTO originUnit;
67      private UnitDTO lengthUnit;
68      private UnitDTO transitionUnit;
69      public static final String PROPERTY_TRANSITION_UNIT = "transitionUnit";
70  
71      // map of result
72      private Multimap<SamplingOperationDTO, Integer> resultMap = ArrayListMultimap.create();
73      private Multimap<SamplingOperationDTO, Integer> currentMap = ArrayListMultimap.create();
74  
75      public Multimap<SamplingOperationDTO, Integer> getResultMap() {
76          return resultMap;
77      }
78  
79      public Multimap<SamplingOperationDTO, Integer> getCurrentMap() {
80          return currentMap;
81      }
82  
83      public List<SamplingOperationDTO> getSamplingOperations() {
84          return samplingOperations;
85      }
86  
87      public void setSamplingOperations(List<SamplingOperationDTO> samplingOperations) {
88          this.samplingOperations = samplingOperations;
89          firePropertyChange(PROPERTY_SAMPLING_OPERATIONS, null, samplingOperations);
90      }
91  
92      public boolean isAllSamplingOperations() {
93          return allSamplingOperations;
94      }
95  
96      public void setAllSamplingOperations(boolean allSamplingOperations) {
97          boolean oldValue = isAllSamplingOperations();
98          this.allSamplingOperations = allSamplingOperations;
99          firePropertyChange(PROPERTY_ALL_SAMPLING_OPERATIONS, oldValue, allSamplingOperations);
100         if (!allSamplingOperations)
101             setContiguousSamplingOperations(false);
102     }
103 
104     public boolean isContiguousSamplingOperations() {
105         return contiguousSamplingOperations;
106     }
107 
108     public void setContiguousSamplingOperations(boolean contiguousSamplingOperations) {
109         boolean oldValue = isContiguousSamplingOperations();
110         this.contiguousSamplingOperations = contiguousSamplingOperations;
111         firePropertyChange(PROPERTY_CONTIGUOUS_SAMPLING_OPERATIONS, oldValue, contiguousSamplingOperations);
112     }
113 
114     public SamplingOperationDTO getSamplingOperation() {
115         return samplingOperation;
116     }
117 
118     public void setSamplingOperation(SamplingOperationDTO samplingOperation) {
119         SamplingOperationDTO oldValue = getSamplingOperation();
120         this.samplingOperation = samplingOperation;
121         firePropertyChange(PROPERTY_SAMPLING_OPERATION, oldValue, samplingOperation);
122     }
123 
124     public SamplingOperationDTO getLastSamplingOperation() {
125         return lastSamplingOperation;
126     }
127 
128     public void setLastSamplingOperation(SamplingOperationDTO lastSamplingOperation) {
129         this.lastSamplingOperation = lastSamplingOperation;
130     }
131 
132     public Integer getOrigin() {
133         return origin;
134     }
135 
136     public void setOrigin(Integer origin) {
137         Integer oldValue = getOrigin();
138         this.origin = origin;
139         firePropertyChange(PROPERTY_ORIGIN, oldValue, origin);
140     }
141 
142     public Integer getTransition() {
143         return transition;
144     }
145 
146     public void setTransition(Integer transition) {
147         Integer oldValue = getTransition();
148         this.transition = transition;
149         firePropertyChange(PROPERTY_TRANSITION, oldValue, transition);
150     }
151 
152     public Integer getLength() {
153         return length;
154     }
155 
156     public void setLength(Integer length) {
157         Integer oldValue = getLength();
158         this.length = length;
159         firePropertyChange(PROPERTY_LENGTH, oldValue, length);
160     }
161 
162     public boolean areValuesValid() {
163 
164         // values must be filled
165         if (getOrigin() == null || getTransition() == null || getLength() == null) return false;
166 
167         if (isAllSamplingOperations() && isContiguousSamplingOperations()) {
168 
169             // the length must be a multiple of number of sampling operations
170             if (getLength() % getSamplingOperations().size() != 0) return false;
171 
172             // the effective length per sampling operation (length/nbSamplingOperation - origin) must be a multiple of transition
173             // wrong test: return (getLength() / getSamplingOperations().size() - getOrigin()) % getTransition() == 0;
174             // Mantis #50450: use this correct test:
175             return (((getLength() - getOrigin()) / getTransition()) + 1) % getSamplingOperations().size() == 0;
176 
177         }
178 
179         // the effective length (length - origin) must be a multiple of transition
180         return (getLength() - getOrigin()) % getTransition() == 0;
181 
182     }
183 
184     public int getOriginPmfmId() {
185         return originPmfmId;
186     }
187 
188     public void setOriginPmfmId(int originPmfmId) {
189         this.originPmfmId = originPmfmId;
190     }
191 
192     public int getLengthPmfmId() {
193         return lengthPmfmId;
194     }
195 
196     public void setLengthPmfmId(int lengthPmfmId) {
197         this.lengthPmfmId = lengthPmfmId;
198     }
199 
200     public int getTransitionPmfmId() {
201         return transitionPmfmId;
202     }
203 
204     public void setTransitionPmfmId(int transitionPmfmId) {
205         this.transitionPmfmId = transitionPmfmId;
206     }
207 
208     public UnitDTO getOriginUnit() {
209         return originUnit;
210     }
211 
212     public void setOriginUnit(UnitDTO originUnit) {
213         this.originUnit = originUnit;
214     }
215 
216     public UnitDTO getLengthUnit() {
217         return lengthUnit;
218     }
219 
220     public void setLengthUnit(UnitDTO lengthUnit) {
221         this.lengthUnit = lengthUnit;
222     }
223 
224     public UnitDTO getTransitionUnit() {
225         return transitionUnit;
226     }
227 
228     public void setTransitionUnit(UnitDTO transitionUnit) {
229         this.transitionUnit = transitionUnit;
230         firePropertyChange(PROPERTY_TRANSITION_UNIT, null, transitionUnit);
231     }
232 }