View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.location.table;
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.CoordinateDTO;
27  import fr.ifremer.dali.dto.DaliBeanFactory;
28  import fr.ifremer.dali.dto.ErrorAware;
29  import fr.ifremer.dali.dto.ErrorDTO;
30  import fr.ifremer.dali.dto.data.CoordinateAreaAware;
31  import fr.ifremer.dali.dto.data.PositioningPrecisionAware;
32  import fr.ifremer.dali.dto.referential.GroupingDTO;
33  import fr.ifremer.dali.dto.referential.HarbourDTO;
34  import fr.ifremer.dali.dto.referential.LocationDTO;
35  import fr.ifremer.dali.dto.referential.PositioningSystemDTO;
36  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliRowUIModel;
37  import fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
38  import org.nuiton.util.beans.Binder;
39  import org.nuiton.util.beans.BinderFactory;
40  
41  import java.util.ArrayList;
42  import java.util.Collection;
43  import java.util.Date;
44  import java.util.List;
45  
46  /**
47   * Row model.
48   */
49  public class LocationTableRowModel extends AbstractDaliRowUIModel<LocationDTO, LocationTableRowModel> implements LocationDTO, ErrorAware, CoordinateAreaAware, PositioningPrecisionAware {
50  
51      private static final Binder<LocationDTO, LocationTableRowModel> FROM_BEAN_BINDER =
52              BinderFactory.newBinder(LocationDTO.class, LocationTableRowModel.class);
53  
54      private static final Binder<LocationTableRowModel, LocationDTO> TO_BEAN_BINDER =
55              BinderFactory.newBinder(LocationTableRowModel.class, LocationDTO.class);
56  
57      private final List<ErrorDTO> errors;
58  
59      /**
60       * <p>Constructor for LocationTableRowModel.</p>
61       *
62       * @param readOnly a boolean.
63       */
64      public LocationTableRowModel(boolean readOnly) {
65          super(FROM_BEAN_BINDER, TO_BEAN_BINDER);
66          errors = new ArrayList<>();
67          setReadOnly(readOnly);
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public boolean isEditable() {
73          return !isReadOnly() && super.isEditable();
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      protected LocationDTO newBean() {
79          return DaliBeanFactory.newLocationDTO();
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public String getLabel() {
85          return delegateObject.getLabel();
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public void setLabel(String identifiant) {
91          delegateObject.setLabel(identifiant);
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public String getName() {
97          return delegateObject.getName();
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public void setName(String libelle) {
103         delegateObject.setName(libelle);
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public GroupingDTO getGrouping() {
109         return delegateObject.getGrouping();
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public void setGrouping(GroupingDTO grouping) {
115         delegateObject.setGrouping(grouping);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public HarbourDTO getHarbour() {
121         return delegateObject.getHarbour();
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     public void setHarbour(HarbourDTO harbour) {
127         delegateObject.setHarbour(harbour);
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     public Double getBathymetry() {
133         return delegateObject.getBathymetry();
134     }
135 
136     /** {@inheritDoc} */
137     @Override
138     public void setBathymetry(Double bathymetrie) {
139         delegateObject.setBathymetry(bathymetrie);
140     }
141 
142     /** {@inheritDoc} */
143     @Override
144     public String getComment() {
145         return delegateObject.getComment();
146     }
147 
148     /** {@inheritDoc} */
149     @Override
150     public void setComment(String commentaire) {
151         delegateObject.setComment(commentaire);
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public Double getUtFormat() {
157         return delegateObject.getUtFormat();
158     }
159 
160     /** {@inheritDoc} */
161     @Override
162     public void setUtFormat(Double deltaUTHiver) {
163         delegateObject.setUtFormat(deltaUTHiver);
164     }
165 
166     /** {@inheritDoc} */
167     @Override
168     public Boolean getDayLightSavingTime() {
169         return delegateObject.getDayLightSavingTime();
170     }
171 
172     /** {@inheritDoc} */
173     @Override
174     public void setDayLightSavingTime(Boolean appliquerChangementHeure) {
175         delegateObject.setDayLightSavingTime(appliquerChangementHeure);
176     }
177 
178     /** {@inheritDoc} */
179     @Override
180     public PositioningSystemDTO getPositioning() {
181         return delegateObject.getPositioning();
182     }
183 
184     /** {@inheritDoc} */
185     @Override
186     public void setPositioning(PositioningSystemDTO positionnement) {
187         delegateObject.setPositioning(positionnement);
188     }
189 
190     /** {@inheritDoc} */
191     @Override
192     public CoordinateDTO getCoordinate() {
193         return delegateObject.getCoordinate();
194     }
195 
196     /** {@inheritDoc} */
197     @Override
198     public void setCoordinate(CoordinateDTO coordonnee) {
199         delegateObject.setCoordinate(coordonnee);
200     }
201 
202     /** {@inheritDoc} */
203     @Override
204     public StatusDTO getStatus() {
205         return delegateObject.getStatus();
206     }
207 
208     /** {@inheritDoc} */
209     @Override
210     public void setStatus(StatusDTO status) {
211         delegateObject.setStatus(status);
212     }
213 
214     /** {@inheritDoc} */
215     @Override
216     public boolean isDirty() {
217         return delegateObject.isDirty();
218     }
219 
220     /** {@inheritDoc} */
221     @Override
222     public void setDirty(boolean dirty) {
223         delegateObject.setDirty(dirty);
224     }
225 
226     @Override
227     public boolean isReadOnly() {
228         return delegateObject.isReadOnly();
229     }
230 
231     @Override
232     public void setReadOnly(boolean readOnly) {
233         delegateObject.setReadOnly(readOnly);
234     }
235 
236     @Override
237     public Date getCreationDate() {
238         return delegateObject.getCreationDate();
239     }
240 
241     @Override
242     public void setCreationDate(Date date) {
243         delegateObject.setCreationDate(date);
244     }
245 
246     @Override
247     public Date getUpdateDate() {
248         return delegateObject.getUpdateDate();
249     }
250 
251     @Override
252     public void setUpdateDate(Date date) {
253         delegateObject.setUpdateDate(date);
254     }
255 
256     /** {@inheritDoc} */
257     @Override
258     public Collection<ErrorDTO> getErrors() {
259         return errors;
260     }
261 
262     /** {@inheritDoc} */
263     @Override
264     public Double getMinLatitude() {
265         return getCoordinateToModify().getMinLatitude();
266     }
267 
268     /** {@inheritDoc} */
269     @Override
270     public void setMinLatitude(Double minLatitude) {
271         Double oldValue = getMinLatitude();
272         getCoordinateToModify().setMinLatitude(minLatitude);
273         firePropertyChange(PROPERTY_MIN_LATITUDE, oldValue, minLatitude);
274     }
275 
276     /** {@inheritDoc} */
277     @Override
278     public Double getMinLongitude() {
279         return getCoordinateToModify().getMinLongitude();
280     }
281 
282     /** {@inheritDoc} */
283     @Override
284     public void setMinLongitude(Double minLongitude) {
285         Double oldValue = getMinLongitude();
286         getCoordinateToModify().setMinLongitude(minLongitude);
287         firePropertyChange(PROPERTY_MIN_LONGITUDE, oldValue, minLongitude);
288     }
289 
290     /** {@inheritDoc} */
291     @Override
292     public Double getMaxLatitude() {
293         return getCoordinateToModify().getMaxLatitude();
294     }
295 
296     /** {@inheritDoc} */
297     @Override
298     public void setMaxLatitude(Double maxLatitude) {
299         Double oldValue = getMaxLatitude();
300         getCoordinateToModify().setMaxLatitude(maxLatitude);
301         firePropertyChange(PROPERTY_MAX_LATITUDE, oldValue, maxLatitude);
302     }
303 
304     /** {@inheritDoc} */
305     @Override
306     public Double getMaxLongitude() {
307         return getCoordinateToModify().getMaxLongitude();
308     }
309 
310     /** {@inheritDoc} */
311     @Override
312     public void setMaxLongitude(Double maxLongitude) {
313         Double oldValue = getMaxLongitude();
314         getCoordinateToModify().setMaxLongitude(maxLongitude);
315         firePropertyChange(PROPERTY_MAX_LONGITUDE, oldValue, maxLongitude);
316     }
317 
318     private CoordinateDTO getCoordinateToModify() {
319         if (getCoordinate() == null) {
320             setCoordinate(DaliBeanFactory.newCoordinateDTO());
321         }
322         return getCoordinate();
323     }
324 
325     /** {@inheritDoc} */
326     @Override
327     public String getPositioningPrecision() {
328         return getPositioning() == null ? null : getPositioning().getPrecision();
329     }
330 }