View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.rule.controlrule;
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 fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
27  import fr.ifremer.reefdb.dto.ErrorDTO;
28  import fr.ifremer.reefdb.dto.FunctionDTO;
29  import fr.ifremer.reefdb.dto.ReefDbBeanFactory;
30  import fr.ifremer.reefdb.dto.ReefDbBeans;
31  import fr.ifremer.reefdb.dto.configuration.control.*;
32  import fr.ifremer.reefdb.dto.enums.ControlFunctionValues;
33  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbRowUIModel;
34  import org.nuiton.util.beans.Binder;
35  import org.nuiton.util.beans.BinderFactory;
36  
37  import java.util.Collection;
38  import java.util.Date;
39  import java.util.function.Predicate;
40  
41  /**
42   * <p>ControlRuleRowModel class.</p>
43   *
44   * @author Antoine
45   */
46  public class ControlRuleRowModel extends AbstractReefDbRowUIModel<ControlRuleDTO, ControlRuleRowModel> implements ControlRuleDTO {
47  
48      private static final Binder<ControlRuleDTO, ControlRuleRowModel> FROM_BEAN_BINDER =
49              BinderFactory.newBinder(ControlRuleDTO.class, ControlRuleRowModel.class);
50  
51      private static final Binder<ControlRuleRowModel, ControlRuleDTO> TO_BEAN_BINDER =
52              BinderFactory.newBinder(ControlRuleRowModel.class, ControlRuleDTO.class);
53  
54      static final Predicate<ControlRuleRowModel> qualitativeValuePredicate = ReefDbBeans::isQualitativeControlRule;
55  
56      static final Predicate<ControlRuleRowModel> preconditionQualitativePredicate = rule -> ControlFunctionValues.PRECONDITION_QUALITATIVE.equals(rule.getFunction());
57  
58      static final Predicate<ControlRuleRowModel> preconditionNumericalPredicate = rule -> ControlFunctionValues.PRECONDITION_NUMERICAL.equals(rule.getFunction());
59  
60      public static final String PROPERTY_PMFM_VALID = "pmfmValid";
61      private boolean pmfmValid;
62  
63      /**
64       * <p>Constructor for ControlRuleRowModel.</p>
65       */
66      public ControlRuleRowModel() {
67          super(FROM_BEAN_BINDER, TO_BEAN_BINDER);
68      }
69  
70      public boolean isPmfmValid() {
71          return pmfmValid;
72      }
73  
74      public void setPmfmValid(boolean pmfmValid) {
75          boolean oldValue = isPmfmValid();
76          this.pmfmValid = pmfmValid;
77          firePropertyChange(PROPERTY_PMFM_VALID, oldValue, pmfmValid);
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      protected ControlRuleDTO newBean() {
83          return ReefDbBeanFactory.newControlRuleDTO();
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public String getCode() {
89          return delegateObject.getCode();
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public void setCode(String code) {
95          delegateObject.setCode(code);
96      }
97  
98      /** {@inheritDoc} */
99      @Override
100     public FunctionDTO getFunction() {
101         return delegateObject.getFunction();
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     public void setFunction(FunctionDTO Function) {
107         delegateObject.setFunction(Function);
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public ErrorDTO getErrors(int index) {
113         return delegateObject.getErrors(index);
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     public boolean isErrorsEmpty() {
119         return delegateObject.isErrorsEmpty();
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public int sizeErrors() {
125         return delegateObject.sizeErrors();
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     public void addErrors(ErrorDTO errors) {
131         delegateObject.addErrors(errors);
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public void addAllErrors(Collection<ErrorDTO> errors) {
137         delegateObject.addAllErrors(errors);
138     }
139 
140     /** {@inheritDoc} */
141     @Override
142     public boolean removeErrors(ErrorDTO errors) {
143         return delegateObject.removeErrors(errors);
144     }
145 
146     /** {@inheritDoc} */
147     @Override
148     public boolean removeAllErrors(Collection<ErrorDTO> errors) {
149         return delegateObject.removeAllErrors(errors);
150     }
151 
152     /** {@inheritDoc} */
153     @Override
154     public boolean containsErrors(ErrorDTO errors) {
155         return delegateObject.containsErrors(errors);
156     }
157 
158     /** {@inheritDoc} */
159     @Override
160     public boolean containsAllErrors(Collection<ErrorDTO> errors) {
161         return delegateObject.containsAllErrors(errors);
162     }
163 
164     /** {@inheritDoc} */
165     @Override
166     public Collection<ErrorDTO> getErrors() {
167         return delegateObject.getErrors();
168     }
169 
170     /** {@inheritDoc} */
171     @Override
172     public void setErrors(Collection<ErrorDTO> errors) {
173         delegateObject.setErrors(errors);
174     }
175 
176     @Override
177     public PreconditionRuleDTO getPreconditions(int index) {
178         return delegateObject.getPreconditions(index);
179     }
180 
181     @Override
182     public boolean isPreconditionsEmpty() {
183         return delegateObject.isPreconditionsEmpty();
184     }
185 
186     @Override
187     public int sizePreconditions() {
188         return delegateObject.sizePreconditions();
189     }
190 
191     @Override
192     public void addPreconditions(PreconditionRuleDTO preconditions) {
193         delegateObject.addPreconditions(preconditions);
194     }
195 
196     @Override
197     public void addAllPreconditions(Collection<PreconditionRuleDTO> preconditions) {
198         delegateObject.addAllPreconditions(preconditions);
199     }
200 
201     @Override
202     public boolean removePreconditions(PreconditionRuleDTO preconditions) {
203         return delegateObject.removePreconditions(preconditions);
204     }
205 
206     @Override
207     public boolean removeAllPreconditions(Collection<PreconditionRuleDTO> preconditions) {
208         return delegateObject.removeAllPreconditions(preconditions);
209     }
210 
211     @Override
212     public boolean containsPreconditions(PreconditionRuleDTO preconditions) {
213         return delegateObject.containsPreconditions(preconditions);
214     }
215 
216     @Override
217     public boolean containsAllPreconditions(Collection<PreconditionRuleDTO> preconditions) {
218         return delegateObject.containsAllPreconditions(preconditions);
219     }
220 
221     @Override
222     public Collection<PreconditionRuleDTO> getPreconditions() {
223         return delegateObject.getPreconditions();
224     }
225 
226     @Override
227     public void setPreconditions(Collection<PreconditionRuleDTO> preconditions) {
228         delegateObject.setPreconditions(preconditions);
229     }
230 
231     @Override
232     public RuleGroupDTO getGroups(int index) {
233         return delegateObject.getGroups(index);
234     }
235 
236     @Override
237     public boolean isGroupsEmpty() {
238         return delegateObject.isGroupsEmpty();
239     }
240 
241     @Override
242     public int sizeGroups() {
243         return delegateObject.sizeGroups();
244     }
245 
246     @Override
247     public void addGroups(RuleGroupDTO groups) {
248         delegateObject.addGroups(groups);
249     }
250 
251     @Override
252     public void addAllGroups(Collection<RuleGroupDTO> groups) {
253         delegateObject.addAllGroups(groups);
254     }
255 
256     @Override
257     public boolean removeGroups(RuleGroupDTO groups) {
258         return delegateObject.removeGroups(groups);
259     }
260 
261     @Override
262     public boolean removeAllGroups(Collection<RuleGroupDTO> groups) {
263         return delegateObject.removeAllGroups(groups);
264     }
265 
266     @Override
267     public boolean containsGroups(RuleGroupDTO groups) {
268         return delegateObject.containsGroups(groups);
269     }
270 
271     @Override
272     public boolean containsAllGroups(Collection<RuleGroupDTO> groups) {
273         return delegateObject.containsAllGroups(groups);
274     }
275 
276     @Override
277     public Collection<RuleGroupDTO> getGroups() {
278         return delegateObject.getGroups();
279     }
280 
281     @Override
282     public void setGroups(Collection<RuleGroupDTO> groups) {
283         delegateObject.setGroups(groups);
284     }
285 
286     /** {@inheritDoc} */
287     @Override
288     public ControlElementDTO getControlElement() {
289         return delegateObject.getControlElement();
290     }
291 
292     /** {@inheritDoc} */
293     @Override
294     public void setControlElement(ControlElementDTO controlElement) {
295 
296         // Remove caracteristique controle value if change element controle
297         final ControlElementDTO oldValue = delegateObject.getControlElement();
298         if (oldValue != null && (controlElement == null || !oldValue.getName().equals(controlElement.getName()))) {
299             setControlFeature(null);
300         }
301         delegateObject.setControlElement(controlElement);
302     }
303 
304     /** {@inheritDoc} */
305     @Override
306     public ControlFeatureDTO getControlFeature() {
307         return delegateObject.getControlFeature();
308     }
309 
310     /** {@inheritDoc} */
311     @Override
312     public void setControlFeature(ControlFeatureDTO ControlFeature) {
313         delegateObject.setControlFeature(ControlFeature);
314     }
315 
316     /** {@inheritDoc} */
317     @Override
318     public boolean isActive() {
319         return delegateObject.isActive();
320     }
321 
322     /** {@inheritDoc} */
323     @Override
324     public void setActive(boolean Active) {
325         delegateObject.setActive(Active);
326     }
327 
328     /** {@inheritDoc} */
329     @Override
330     public boolean isBlocking() {
331         return delegateObject.isBlocking();
332     }
333 
334     /** {@inheritDoc} */
335     @Override
336     public void setBlocking(boolean Blocking) {
337         delegateObject.setBlocking(Blocking);
338     }
339 
340     /** {@inheritDoc} */
341     @Override
342     public Object getMin() {
343         return delegateObject.getMin();
344     }
345 
346     /** {@inheritDoc} */
347     @Override
348     public void setMin(Object min) {
349         delegateObject.setMin(min);
350     }
351 
352     /** {@inheritDoc} */
353     @Override
354     public Object getMax() {
355         return delegateObject.getMax();
356     }
357 
358     /** {@inheritDoc} */
359     @Override
360     public void setMax(Object max) {
361         delegateObject.setMax(max);
362     }
363 
364     /** {@inheritDoc} */
365     @Override
366     public String getAllowedValues() {
367         return delegateObject.getAllowedValues();
368     }
369 
370     /** {@inheritDoc} */
371     @Override
372     public void setAllowedValues(String allowedValues) {
373         delegateObject.setAllowedValues(allowedValues);
374     }
375 
376     /** {@inheritDoc} */
377     @Override
378     public RulePmfmDTO getRulePmfms(int index) {
379         return delegateObject.getRulePmfms(index);
380     }
381 
382     /** {@inheritDoc} */
383     @Override
384     public boolean isRulePmfmsEmpty() {
385         return delegateObject.isRulePmfmsEmpty();
386     }
387 
388     /** {@inheritDoc} */
389     @Override
390     public int sizeRulePmfms() {
391         return delegateObject.sizeRulePmfms();
392     }
393 
394     /** {@inheritDoc} */
395     @Override
396     public void addRulePmfms(RulePmfmDTO rulePmfm) {
397         delegateObject.addRulePmfms(rulePmfm);
398     }
399 
400     /** {@inheritDoc} */
401     @Override
402     public void addAllRulePmfms(Collection<RulePmfmDTO> rulePmfms) {
403         delegateObject.addAllRulePmfms(rulePmfms);
404     }
405 
406     /** {@inheritDoc} */
407     @Override
408     public boolean removeRulePmfms(RulePmfmDTO rulePmfm) {
409         return delegateObject.removeRulePmfms(rulePmfm);
410     }
411 
412     /** {@inheritDoc} */
413     @Override
414     public boolean removeAllRulePmfms(Collection<RulePmfmDTO> rulePmfms) {
415         return delegateObject.removeAllRulePmfms(rulePmfms);
416     }
417 
418     /** {@inheritDoc} */
419     @Override
420     public boolean containsRulePmfms(RulePmfmDTO rulePmfm) {
421         return delegateObject.containsRulePmfms(rulePmfm);
422     }
423 
424     /** {@inheritDoc} */
425     @Override
426     public boolean containsAllRulePmfms(Collection<RulePmfmDTO> rulePmfms) {
427         return delegateObject.containsAllRulePmfms(rulePmfms);
428     }
429 
430     /** {@inheritDoc} */
431     @Override
432     public Collection<RulePmfmDTO> getRulePmfms() {
433         return delegateObject.getRulePmfms();
434     }
435 
436     /** {@inheritDoc} */
437     @Override
438     public void setRulePmfms(Collection<RulePmfmDTO> rulePmfms) {
439         delegateObject.setRulePmfms(rulePmfms);
440     }
441 
442     /** {@inheritDoc} */
443     @Override
444     public String getMessage() {
445         return delegateObject.getMessage();
446     }
447 
448     /** {@inheritDoc} */
449     @Override
450     public void setMessage(String Message) {
451         delegateObject.setMessage(Message);
452     }
453 
454     /** {@inheritDoc} */
455     @Override
456     public String getDescription() {
457         return delegateObject.getDescription();
458     }
459 
460     /** {@inheritDoc} */
461     @Override
462     public void setDescription(String description) {
463         delegateObject.setDescription(description);
464     }
465 
466     /** {@inheritDoc} */
467     @Override
468     public boolean isNewCode() {
469         return delegateObject.isNewCode();
470     }
471 
472     /** {@inheritDoc} */
473     @Override
474     public void setNewCode(boolean newCode) {
475         delegateObject.setNewCode(newCode);
476     }
477 
478     @Override
479     public String getName() {
480         return delegateObject.getName();
481     }
482 
483     @Override
484     public void setName(String name) {
485         delegateObject.setName(name);
486     }
487 
488     @Override
489     public boolean isDirty() {
490         return delegateObject.isDirty();
491     }
492 
493     @Override
494     public void setDirty(boolean dirty) {
495         delegateObject.setDirty(dirty);
496     }
497 
498     @Override
499     public boolean isReadOnly() {
500         return delegateObject.isReadOnly();
501     }
502 
503     @Override
504     public void setReadOnly(boolean readOnly) {
505         delegateObject.setReadOnly(readOnly);
506     }
507 
508     @Override
509     public StatusDTO getStatus() {
510         return delegateObject.getStatus();
511     }
512 
513     @Override
514     public void setStatus(StatusDTO status) {
515         delegateObject.setStatus(status);
516     }
517 
518     @Override
519     public Date getCreationDate() {
520         return delegateObject.getCreationDate();
521     }
522 
523     @Override
524     public void setCreationDate(Date date) {
525         delegateObject.setCreationDate(date);
526     }
527 
528     @Override
529     public Date getUpdateDate() {
530         return delegateObject.getUpdateDate();
531     }
532 
533     @Override
534     public void setUpdateDate(Date date) {
535         delegateObject.setUpdateDate(date);
536     }
537 
538 }