View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.observation.shared;
2   
3   /*-
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2019 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.reefdb.dto.configuration.control.ControlRuleDTO;
29  import fr.ifremer.reefdb.dto.configuration.control.PreconditionRuleDTO;
30  import fr.ifremer.reefdb.dto.configuration.control.RuleGroupDTO;
31  import fr.ifremer.reefdb.dto.data.measurement.MeasurementDTO;
32  import fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO;
33  import fr.ifremer.reefdb.dto.referential.TaxonDTO;
34  import fr.ifremer.reefdb.dto.referential.TaxonGroupDTO;
35  import fr.ifremer.reefdb.dto.referential.pmfm.PmfmDTO;
36  import fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIHandler;
37  import fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIModel;
38  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableUIModel;
39  import fr.ifremer.reefdb.ui.swing.util.table.ReefDbColumnIdentifier;
40  
41  import java.util.Collection;
42  import java.util.List;
43  import java.util.Map;
44  
45  /**
46   * @author peck7 on 08/01/2019.
47   */
48  public abstract class AbstractMeasurementsGroupedTableUIModel<
49      B extends MeasurementDTO,
50      R extends AbstractMeasurementsGroupedRowModel<B, R>,
51      M extends AbstractMeasurementsGroupedTableUIModel<B, R, M>>
52      extends AbstractReefDbTableUIModel<B, R, M> {
53  
54      public static final String PROPERTY_SURVEY = "survey";
55      public static final String PROPERTY_MEASUREMENT_FILTER = "measurementFilter";
56      public static final String EVENT_INDIVIDUAL_MEASUREMENTS_LOADED = "individualMeasurementsLoaded";
57  
58      // the survey model
59      private ObservationUIModel survey;
60      private ObservationUIHandler observationHandler;
61      // pmfms with unique constraint
62      private List<PmfmDTO> uniquePmfms;
63      // the measurement filter
64      private MeasurementsFilter measurementFilter;
65      // map holding preconditions per pmfm id
66      private Multimap<Integer, PreconditionRuleDTO> preconditionRulesByPmfmIdMap;
67      // map holding groups per pmfm id
68      private Multimap<ControlRuleDTO, Map.Entry<RuleGroupDTO, ? extends ReefDbColumnIdentifier<R>>> identifiersByGroupedRuleMap;
69      private boolean adjusting;
70  
71      /**
72       * <p>Getter for the field <code>survey</code>.</p>
73       *
74       * @return a {@link fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIModel} object.
75       */
76      public ObservationUIModel getSurvey() {
77          return survey;
78      }
79  
80      /**
81       * <p>Setter for the field <code>survey</code>.</p>
82       *
83       * @param survey a {@link fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIModel} object.
84       */
85      public void setSurvey(ObservationUIModel survey) {
86          this.survey = survey;
87          firePropertyChange(PROPERTY_SURVEY, null, survey);
88      }
89  
90      public ObservationUIHandler getObservationUIHandler() {
91          return observationHandler;
92      }
93  
94      public void setObservationHandler(ObservationUIHandler observationHandler) {
95          this.observationHandler = observationHandler;
96      }
97  
98      /**
99       * <p>Getter for the field <code>uniquePmfms</code>.</p>
100      *
101      * @return a {@link java.util.List} object.
102      */
103     public List<PmfmDTO> getUniquePmfms() {
104         return uniquePmfms;
105     }
106 
107     /**
108      * <p>Setter for the field <code>uniquePmfms</code>.</p>
109      *
110      * @param uniquePmfms a {@link java.util.List} object.
111      */
112     public void setUniquePmfms(List<PmfmDTO> uniquePmfms) {
113         this.uniquePmfms = uniquePmfms;
114     }
115 
116     /**
117      * <p>Setter for the field <code>measurementFilter</code>.</p>
118      *
119      * @param measurementFilter a {@link MeasurementsFilter} object.
120      */
121     public void setMeasurementFilter(MeasurementsFilter measurementFilter) {
122         this.measurementFilter = measurementFilter;
123         firePropertyChange(PROPERTY_MEASUREMENT_FILTER, null, measurementFilter);
124     }
125 
126     /**
127      * <p>getTaxonGroupFilter.</p>
128      *
129      * @return a {@link fr.ifremer.reefdb.dto.referential.TaxonGroupDTO} object.
130      */
131     public TaxonGroupDTO getTaxonGroupFilter() {
132         return measurementFilter == null ? null : measurementFilter.getTaxonGroup();
133     }
134 
135     /**
136      * <p>getTaxonFilter.</p>
137      *
138      * @return a {@link fr.ifremer.reefdb.dto.referential.TaxonDTO} object.
139      */
140     public TaxonDTO getTaxonFilter() {
141         return measurementFilter == null ? null : measurementFilter.getTaxon();
142     }
143 
144     /**
145      * <p>getSamplingFilter.</p>
146      *
147      * @return a {@link fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO} object.
148      */
149     public SamplingOperationDTO getSamplingFilter() {
150         return measurementFilter == null ? null : measurementFilter.getSamplingOperation();
151     }
152 
153     public Multimap<Integer, PreconditionRuleDTO> getPreconditionRulesByPmfmIdMap() {
154         if (preconditionRulesByPmfmIdMap == null) preconditionRulesByPmfmIdMap = ArrayListMultimap.create();
155         return preconditionRulesByPmfmIdMap;
156     }
157 
158     public void addPreconditionRuleByPmfmId(Integer pmfmId, PreconditionRuleDTO precondition) {
159         getPreconditionRulesByPmfmIdMap().put(pmfmId, precondition);
160     }
161 
162     public boolean isPmfmIdHasPreconditions(int pmfmId) {
163         return getPreconditionRulesByPmfmIdMap().containsKey(pmfmId);
164     }
165 
166     public Collection<PreconditionRuleDTO> getPreconditionRulesByPmfmId(int pmfmId) {
167         return getPreconditionRulesByPmfmIdMap().get(pmfmId);
168     }
169 
170     public Multimap<ControlRuleDTO, Map.Entry<RuleGroupDTO, ? extends ReefDbColumnIdentifier<R>>> getIdentifiersByGroupedRuleMap() {
171         if (identifiersByGroupedRuleMap == null) identifiersByGroupedRuleMap = ArrayListMultimap.create();
172         return identifiersByGroupedRuleMap;
173     }
174 
175     public ReefDbColumnIdentifier<R> getIdentifierByGroup(RuleGroupDTO group) {
176         for (Map.Entry<RuleGroupDTO, ? extends ReefDbColumnIdentifier<R>> identifierByGroup : getIdentifiersByGroupedRuleMap().values()) {
177             if (identifierByGroup.getKey().equals(group))
178                 return identifierByGroup.getValue();
179         }
180         return null;
181     }
182 
183     public boolean isAdjusting() {
184         return adjusting;
185     }
186 
187     public void setAdjusting(boolean adjusting) {
188         this.adjusting = adjusting;
189     }
190 
191     public void fireMeasurementsLoaded() {
192         firePropertyChange(EVENT_INDIVIDUAL_MEASUREMENTS_LOADED, null, null);
193     }
194 }