View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.protocol.maturity;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2016 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (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 General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
28  import org.jdesktop.beans.AbstractSerializableBean;
29  
30  import java.util.ArrayList;
31  import java.util.Collection;
32  import java.util.HashSet;
33  import java.util.List;
34  import java.util.Objects;
35  
36  /**
37   * @author Kevin Morin (Code Lutin)
38   * @since 4.5
39   */
40  public class EditMaturityCaracteristicPopupUIModel extends AbstractSerializableBean {
41  
42      public static final String PROPERTY_ALL_MATURITY_STATES = "allMaturityStates";
43  
44      public static final String PROPERTY_MATURE_STATE_IDS = "matureStateIds";
45  
46      /**
47       * Is the model valid?
48       */
49      protected boolean valid;
50  
51      protected final List<CaracteristicQualitativeValue> allMaturityStates = new ArrayList<>();
52  
53      protected final Collection<String> matureStateIds = new HashSet<>();
54  
55      public List<CaracteristicQualitativeValue> getAllMaturityStates() {
56          return allMaturityStates;
57      }
58  
59      public void setAllMaturityStates(List<CaracteristicQualitativeValue> allMaturityStates) {
60          this.allMaturityStates.clear();
61          if (allMaturityStates != null) {
62              this.allMaturityStates.addAll(allMaturityStates);
63          }
64          firePropertyChange(PROPERTY_ALL_MATURITY_STATES, null, this.allMaturityStates);
65      }
66  
67      public Collection<String> getMatureStateIds() {
68          return matureStateIds;
69      }
70  
71      public void setMatureStateIds(Collection<String> matureStateIds) {
72          this.matureStateIds.clear();
73          if (matureStateIds != null) {
74              this.matureStateIds.addAll(matureStateIds);
75          }
76          firePropertyChange(PROPERTY_MATURE_STATE_IDS, null, this.matureStateIds);
77      }
78  
79      public void addMatureState(CaracteristicQualitativeValue state) {
80          Objects.requireNonNull(state);
81          addMatureState(state.getId());
82      }
83  
84      public void addMatureState(String stateId) {
85          matureStateIds.add(stateId);
86          firePropertyChange(PROPERTY_MATURE_STATE_IDS, null, matureStateIds);
87      }
88  
89      public void removeMatureState(CaracteristicQualitativeValue state) {
90          Objects.requireNonNull(state);
91          removeMatureState(state.getId());
92      }
93  
94      public void removeMatureState(String stateId) {
95          matureStateIds.remove(stateId);
96          firePropertyChange(PROPERTY_MATURE_STATE_IDS, null, matureStateIds);
97      }
98  
99      public boolean isMature(CaracteristicQualitativeValue state) {
100         Objects.requireNonNull(state);
101         return isMature(state.getId());
102     }
103 
104     public boolean isMature(String id) {
105         return matureStateIds.contains(id);
106     }
107 
108     public boolean hasMatureValues() {
109         return matureStateIds.size() > 0;
110     }
111 
112     public boolean hasImmatureValues() {
113         return matureStateIds.size() < allMaturityStates.size();
114     }
115 
116     public boolean isValid() {
117         return valid;
118     }
119 
120     public void setValid(boolean valid) {
121         this.valid = valid;
122     }
123 }