View Javadoc
1   package fr.ifremer.dali.ui.swing.content.home;
2   
3   /*
4    * #%L
5    * Dali :: 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.dali.dto.SearchDateDTO;
27  import fr.ifremer.dali.dto.StateDTO;
28  import fr.ifremer.dali.dto.SynchronizationStatusDTO;
29  import fr.ifremer.dali.dto.configuration.context.ContextDTO;
30  import fr.ifremer.dali.dto.configuration.programStrategy.ProgramDTO;
31  import fr.ifremer.dali.dto.data.survey.CampaignDTO;
32  import fr.ifremer.dali.dto.referential.LocationDTO;
33  import fr.ifremer.dali.ui.swing.content.home.map.SurveysMapUIModel;
34  import fr.ifremer.dali.ui.swing.content.home.operation.OperationsTableUIModel;
35  import fr.ifremer.dali.ui.swing.content.home.survey.SurveysTableRowModel;
36  import fr.ifremer.dali.ui.swing.content.home.survey.SurveysTableUIModel;
37  import fr.ifremer.dali.ui.swing.util.map.MapParentUIModel;
38  import fr.ifremer.quadrige3.ui.swing.model.AbstractEmptyUIModel;
39  import fr.ifremer.quadrige3.ui.swing.table.AbstractTableModel;
40  import org.apache.commons.lang3.StringUtils;
41  
42  import java.time.LocalDate;
43  import java.util.Optional;
44  
45  /**
46   * Home model.
47   */
48  public class HomeUIModel extends AbstractEmptyUIModel<HomeUIModel> implements MapParentUIModel {
49  
50      public static final String PROPERTY_CONTEXT = "context";
51      public static final String PROPERTY_PROGRAM = "program";
52      public static final String PROPERTY_PROGRAMS_FILTERED = "programsFiltered";
53      public static final String PROPERTY_CAMPAIGN = "campaign";
54      public static final String PROPERTY_CAMPAIGNS_FILTERED = "campaignsFiltered";
55      public static final String PROPERTY_LOCATION = "location";
56      public static final String PROPERTY_LOCATIONS_FILTERED = "locationsFiltered";
57      public static final String PROPERTY_STATE = "state";
58      public static final String PROPERTY_SYNCHRONIZATION_STATUS = "synchronizationStatus";
59      public static final String PROPERTY_SEARCH_DATE = "searchDate";
60      public static final String PROPERTY_NAME = "name";
61      public static final String PROPERTY_COMMENT = "comment";
62      public static final String PROPERTY_START_DATE = "startDate";
63      public static final String PROPERTY_END_DATE = "endDate";
64      public static final String PROPERTY_SELECTED_SURVEY = "selectedSurvey";
65      public static final String STATE_CONTEXT_PREFIX = "surveys_";
66      private ContextDTO context;
67      private ProgramDTO program;
68      private boolean programsFiltered;
69      private boolean forceNoProgramFilter;
70      private CampaignDTO campaign;
71      private boolean campaignsFiltered;
72      private boolean forceNoCampaignFilter;
73      private LocationDTO location;
74      private boolean locationsFiltered;
75      private boolean forceNoLocationFilter;
76      private StateDTO state;
77      private SynchronizationStatusDTO synchronizationStatus;
78      private SearchDateDTO searchDate;
79      private String name;
80      private String comment;
81      private LocalDate startDate;
82      private LocalDate endDate;
83      private boolean adjusting;
84      // Survey table model.
85      private SurveysTableUIModel surveysTableUIModel;
86      // Sampling operation table model.
87      private OperationsTableUIModel operationsTableUIModel;
88      // Survey map mode
89      private SurveysMapUIModel surveysMapUIModel;
90      // Selected survey
91      private SurveysTableRowModel selectedSurvey;
92  
93      /**
94       * {@inheritDoc}
95       */
96      @Override
97      public boolean isModify() {
98          return super.isModify();
99      }
100 
101     /**
102      * {@inheritDoc}
103      */
104     @Override
105     public void setModify(boolean modify) {
106         super.setModify(modify);
107     }
108 
109     /**
110      * <p>isAdjusting.</p>
111      *
112      * @return a boolean.
113      */
114     public boolean isAdjusting() {
115         return adjusting;
116     }
117 
118     /**
119      * <p>Setter for the field <code>adjusting</code>.</p>
120      *
121      * @param adjusting a boolean.
122      */
123     public void setAdjusting(boolean adjusting) {
124         this.adjusting = adjusting;
125     }
126 
127     /**
128      * <p>Getter for the field <code>context</code>.</p>
129      *
130      * @return a {@link fr.ifremer.dali.dto.configuration.context.ContextDTO} object.
131      */
132     public ContextDTO getContext() {
133         return context;
134     }
135 
136     /**
137      * <p>Setter for the field <code>context</code>.</p>
138      *
139      * @param context a {@link fr.ifremer.dali.dto.configuration.context.ContextDTO} object.
140      */
141     public void setContext(ContextDTO context) {
142         ContextDTO oldContext = getContext();
143         this.context = context;
144         firePropertyChange(PROPERTY_CONTEXT, oldContext, context);
145     }
146 
147     public CampaignDTO getCampaign() {
148         return campaign;
149     }
150 
151     public Integer getCampaignId() {
152         return getCampaign() == null ? null : getCampaign().getId();
153     }
154 
155     public void setCampaign(CampaignDTO campaign) {
156         CampaignDTO oldCampaign = getCampaign();
157         this.campaign = campaign;
158         firePropertyChange(PROPERTY_CAMPAIGN, oldCampaign, campaign);
159     }
160 
161     /**
162      * <p>Getter for the field <code>program</code>.</p>
163      *
164      * @return a {@link fr.ifremer.dali.dto.configuration.programStrategy.ProgramDTO} object.
165      */
166     public ProgramDTO getProgram() {
167         return program;
168     }
169 
170     /**
171      * <p>Setter for the field <code>program</code>.</p>
172      *
173      * @param program a {@link fr.ifremer.dali.dto.configuration.programStrategy.ProgramDTO} object.
174      */
175     public void setProgram(ProgramDTO program) {
176         ProgramDTO oldValue = getProgram();
177         this.program = program;
178         firePropertyChange(PROPERTY_PROGRAM, oldValue, program);
179     }
180 
181     /**
182      * <p>getProgramCode.</p>
183      *
184      * @return a {@link java.lang.String} object.
185      */
186     public String getProgramCode() {
187         return getProgram() == null ? null : getProgram().getCode();
188     }
189 
190     public String getStateContext() {
191         return Optional.ofNullable(getProgramCode()).map(STATE_CONTEXT_PREFIX::concat).orElse(AbstractTableModel.DEFAULT_STATE_CONTEXT);
192     }
193 
194     /**
195      * <p>Getter for the field <code>comment</code>.</p>
196      *
197      * @return a {@link java.lang.String} object.
198      */
199     public String getComment() {
200         return comment;
201     }
202 
203     /**
204      * <p>Setter for the field <code>comment</code>.</p>
205      *
206      * @param comment a {@link java.lang.String} object.
207      */
208     public void setComment(String comment) {
209         String oldValue = getComment();
210         this.comment = StringUtils.isEmpty(comment) ? null : comment;
211         firePropertyChange(PROPERTY_COMMENT, oldValue, comment);
212     }
213 
214     public String getName() {
215         return name;
216     }
217 
218     public void setName(String name) {
219         String oldValue = getName();
220         this.name = StringUtils.isEmpty(name) ? null : name;
221         firePropertyChange(PROPERTY_NAME, oldValue, name);
222     }
223 
224     /**
225      * <p>isProgramsFiltered.</p>
226      *
227      * @return a boolean.
228      */
229     public boolean isProgramsFiltered() {
230         return programsFiltered;
231     }
232 
233     /**
234      * <p>Setter for the field <code>programsFiltered</code>.</p>
235      *
236      * @param programsFiltered a boolean.
237      */
238     public void setProgramsFiltered(boolean programsFiltered) {
239         boolean oldValue = isProgramsFiltered();
240         this.programsFiltered = programsFiltered;
241         firePropertyChange(PROPERTY_PROGRAMS_FILTERED, oldValue, programsFiltered);
242     }
243 
244     /**
245      * <p>isForceNoProgramFilter.</p>
246      *
247      * @return a boolean.
248      */
249     public boolean isForceNoProgramFilter() {
250         return forceNoProgramFilter;
251     }
252 
253     /**
254      * <p>Setter for the field <code>forceNoProgramFilter</code>.</p>
255      *
256      * @param forceNoProgramFilter a boolean.
257      */
258     public void setForceNoProgramFilter(boolean forceNoProgramFilter) {
259         this.forceNoProgramFilter = forceNoProgramFilter;
260     }
261 
262     /**
263      * <p>isCampaignsFiltered.</p>
264      *
265      * @return a boolean.
266      */
267     public boolean isCampaignsFiltered() {
268         return campaignsFiltered;
269     }
270 
271     /**
272      * <p>Setter for the field <code>campaignsFiltered</code>.</p>
273      *
274      * @param campaignsFiltered a boolean.
275      */
276     public void setCampaignsFiltered(boolean campaignsFiltered) {
277         boolean oldValue = isCampaignsFiltered();
278         this.campaignsFiltered = campaignsFiltered;
279         firePropertyChange(PROPERTY_CAMPAIGNS_FILTERED, oldValue, campaignsFiltered);
280     }
281 
282     /**
283      * <p>isForceNoCampaignFilter.</p>
284      *
285      * @return a boolean.
286      */
287     public boolean isForceNoCampaignFilter() {
288         return forceNoCampaignFilter;
289     }
290 
291     /**
292      * <p>Setter for the field <code>forceNoCampaignFilter</code>.</p>
293      *
294      * @param forceNoCampaignFilter a boolean.
295      */
296     public void setForceNoCampaignFilter(boolean forceNoCampaignFilter) {
297         this.forceNoCampaignFilter = forceNoCampaignFilter;
298     }
299 
300     /**
301      * <p>Getter for the field <code>searchDate</code>.</p>
302      *
303      * @return a {@link fr.ifremer.dali.dto.SearchDateDTO} object.
304      */
305     public SearchDateDTO getSearchDate() {
306         return searchDate;
307     }
308 
309     /**
310      * <p>Setter for the field <code>searchDate</code>.</p>
311      *
312      * @param searchDate a {@link fr.ifremer.dali.dto.SearchDateDTO} object.
313      */
314     public void setSearchDate(SearchDateDTO searchDate) {
315         SearchDateDTO oldSearchDate = getSearchDate();
316         this.searchDate = searchDate;
317         firePropertyChange(PROPERTY_SEARCH_DATE, oldSearchDate, searchDate);
318     }
319 
320     /**
321      * <p>getSearchDateId.</p>
322      *
323      * @return a {@link java.lang.Integer} object.
324      */
325     public Integer getSearchDateId() {
326         return getSearchDate() == null ? null : getSearchDate().getId();
327     }
328 
329     /**
330      * <p>Getter for the field <code>startDate</code>.</p>
331      *
332      * @return a {@link java.util.Date} object.
333      */
334     public LocalDate getStartDate() {
335         return startDate;
336     }
337 
338     /**
339      * <p>Setter for the field <code>startDate</code>.</p>
340      *
341      * @param startDate a {@link java.util.Date} object.
342      */
343     public void setStartDate(LocalDate startDate) {
344         LocalDate oldDate = getStartDate();
345         this.startDate = startDate;
346         firePropertyChange(PROPERTY_START_DATE, oldDate, startDate);
347     }
348 
349     /**
350      * <p>Getter for the field <code>endDate</code>.</p>
351      *
352      * @return a {@link java.util.Date} object.
353      */
354     public LocalDate getEndDate() {
355         return endDate;
356     }
357 
358     /**
359      * <p>Setter for the field <code>endDate</code>.</p>
360      *
361      * @param endDate a {@link java.util.Date} object.
362      */
363     public void setEndDate(LocalDate endDate) {
364         LocalDate oldDate = getEndDate();
365         this.endDate = endDate;
366         firePropertyChange(PROPERTY_END_DATE, oldDate, endDate);
367     }
368 
369     /**
370      * <p>Getter for the field <code>location</code>.</p>
371      *
372      * @return a {@link fr.ifremer.dali.dto.referential.LocationDTO} object.
373      */
374     public LocationDTO getLocation() {
375         return location;
376     }
377 
378     /**
379      * <p>Setter for the field <code>location</code>.</p>
380      *
381      * @param location a {@link fr.ifremer.dali.dto.referential.LocationDTO} object.
382      */
383     public void setLocation(LocationDTO location) {
384         LocationDTO oldLocation = getLocation();
385         this.location = location;
386         firePropertyChange(PROPERTY_LOCATION, oldLocation, location);
387     }
388 
389     /**
390      * <p>getLocationId.</p>
391      *
392      * @return a {@link java.lang.Integer} object.
393      */
394     public Integer getLocationId() {
395         return getLocation() == null ? null : getLocation().getId();
396     }
397 
398     /**
399      * <p>isLocationsFiltered.</p>
400      *
401      * @return a boolean.
402      */
403     public boolean isLocationsFiltered() {
404         return locationsFiltered;
405     }
406 
407     /**
408      * <p>Setter for the field <code>locationsFiltered</code>.</p>
409      *
410      * @param locationsFiltered a boolean.
411      */
412     public void setLocationsFiltered(boolean locationsFiltered) {
413         boolean oldValue = isLocationsFiltered();
414         this.locationsFiltered = locationsFiltered;
415         firePropertyChange(PROPERTY_LOCATIONS_FILTERED, oldValue, locationsFiltered);
416     }
417 
418     /**
419      * <p>isForceNoLocationFilter.</p>
420      *
421      * @return a boolean.
422      */
423     public boolean isForceNoLocationFilter() {
424         return forceNoLocationFilter;
425     }
426 
427     /**
428      * <p>Setter for the field <code>forceNoLocationFilter</code>.</p>
429      *
430      * @param forceNoLocationFilter a boolean.
431      */
432     public void setForceNoLocationFilter(boolean forceNoLocationFilter) {
433         this.forceNoLocationFilter = forceNoLocationFilter;
434     }
435 
436     /**
437      * <p>Getter for the field <code>state</code>.</p>
438      *
439      * @return a {@link fr.ifremer.dali.dto.StateDTO} object.
440      */
441     public StateDTO getState() {
442         return state;
443     }
444 
445     /**
446      * <p>Setter for the field <code>state</code>.</p>
447      *
448      * @param state a {@link fr.ifremer.dali.dto.StateDTO} object.
449      */
450     public void setState(StateDTO state) {
451         StateDTO oldState = getState();
452         this.state = state;
453         firePropertyChange(PROPERTY_STATE, oldState, state);
454     }
455 
456     /**
457      * <p>getStateId.</p>
458      *
459      * @return a {@link java.lang.Integer} object.
460      */
461     public Integer getStateId() {
462         return getState() == null ? null : getState().getId();
463     }
464 
465     /**
466      * <p>Getter for the field <code>synchronizationStatus</code>.</p>
467      *
468      * @return a {@link fr.ifremer.dali.dto.SynchronizationStatusDTO} object.
469      */
470     public SynchronizationStatusDTO getSynchronizationStatus() {
471         return synchronizationStatus;
472     }
473 
474     /**
475      * <p>Setter for the field <code>synchronizationStatus</code>.</p>
476      *
477      * @param synchronizationStatus a {@link fr.ifremer.dali.dto.SynchronizationStatusDTO} object.
478      */
479     public void setSynchronizationStatus(SynchronizationStatusDTO synchronizationStatus) {
480         SynchronizationStatusDTO oldSynchronizationStatus = getSynchronizationStatus();
481         this.synchronizationStatus = synchronizationStatus;
482         firePropertyChange(PROPERTY_SYNCHRONIZATION_STATUS, oldSynchronizationStatus, synchronizationStatus);
483     }
484 
485     /**
486      * <p>getSynchronizationStatusId.</p>
487      *
488      * @return a {@link java.lang.Integer} object.
489      */
490     public Integer getSynchronizationStatusId() {
491         return getSynchronizationStatus() == null ? null : getSynchronizationStatus().getId();
492     }
493 
494     /**
495      * <p>Getter for the field <code>surveysTableUIModel</code>.</p>
496      *
497      * @return a {@link fr.ifremer.dali.ui.swing.content.home.survey.SurveysTableUIModel} object.
498      */
499     public SurveysTableUIModel getSurveysTableUIModel() {
500         return surveysTableUIModel;
501     }
502 
503     /**
504      * <p>Setter for the field <code>surveysTableUIModel</code>.</p>
505      *
506      * @param surveysTableUIModel a {@link fr.ifremer.dali.ui.swing.content.home.survey.SurveysTableUIModel} object.
507      */
508     public void setSurveysTableUIModel(SurveysTableUIModel surveysTableUIModel) {
509         this.surveysTableUIModel = surveysTableUIModel;
510         surveysTableUIModel.setMainUIModel(this);
511     }
512 
513     /**
514      * <p>Getter for the field <code>operationsTableUIModel</code>.</p>
515      *
516      * @return a {@link fr.ifremer.dali.ui.swing.content.home.operation.OperationsTableUIModel} object.
517      */
518     public OperationsTableUIModel getOperationsTableUIModel() {
519         return operationsTableUIModel;
520     }
521 
522     /**
523      * <p>Setter for the field <code>operationsTableUIModel</code>.</p>
524      *
525      * @param operationsTableUIModel a {@link fr.ifremer.dali.ui.swing.content.home.operation.OperationsTableUIModel} object.
526      */
527     public void setOperationsTableUIModel(OperationsTableUIModel operationsTableUIModel) {
528         this.operationsTableUIModel = operationsTableUIModel;
529         operationsTableUIModel.setMainUIModel(this);
530     }
531 
532     @Override
533     public SurveysMapUIModel getMapUIModel() {
534         return surveysMapUIModel;
535     }
536 
537     @Override
538     public void fireOpenFullScreenEvent() {
539         fireEvent(EVENT_OPEN_FULLSCREEN);
540     }
541 
542     @Override
543     public void fireCloseFullScreenEvent() {
544         fireEvent(EVENT_CLOSE_FULLSCREEN);
545     }
546 
547     private void fireEvent(String event) {
548         boolean modify = isModify();
549         firePropertyChanged(event, null, true);
550         setModify(modify);
551     }
552 
553     public void setMapUIModel(SurveysMapUIModel surveysMapUIModel) {
554         this.surveysMapUIModel = surveysMapUIModel;
555         this.surveysMapUIModel.setParentUIModel(this);
556     }
557 
558     /**
559      * <p>Getter for the field <code>selectedSurvey</code>.</p>
560      *
561      * @return a {@link fr.ifremer.dali.ui.swing.content.home.survey.SurveysTableRowModel} object.
562      */
563     public SurveysTableRowModel getSelectedSurvey() {
564         return selectedSurvey;
565     }
566 
567     /**
568      * <p>Setter for the field <code>selectedSurvey</code>.</p>
569      *
570      * @param selectedSurvey a {@link fr.ifremer.dali.ui.swing.content.home.survey.SurveysTableRowModel} object.
571      */
572     public void setSelectedSurvey(SurveysTableRowModel selectedSurvey) {
573         this.selectedSurvey = selectedSurvey;
574         firePropertyChange(PROPERTY_SELECTED_SURVEY, null, selectedSurvey);
575     }
576 
577 }