1 package fr.ifremer.reefdb.ui.swing.content.observation.operation.measurement.grouped.initGrid;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
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
165 if (getOrigin() == null || getTransition() == null || getLength() == null) return false;
166
167 if (isAllSamplingOperations() && isContiguousSamplingOperations()) {
168
169
170 if (getLength() % getSamplingOperations().size() != 0) return false;
171
172
173
174
175 return (((getLength() - getOrigin()) / getTransition()) + 1) % getSamplingOperations().size() == 0;
176
177 }
178
179
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 }