View Javadoc
1   package fr.ifremer.dali.ui.swing.content.home.survey;
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.StateDTO;
27  import fr.ifremer.dali.dto.SynchronizationStatusDTO;
28  import fr.ifremer.dali.dto.configuration.programStrategy.ProgramDTO;
29  import fr.ifremer.dali.dto.data.survey.CampaignDTO;
30  import fr.ifremer.dali.dto.referential.DepartmentDTO;
31  import fr.ifremer.dali.dto.referential.LocationDTO;
32  import fr.ifremer.dali.dto.referential.PositioningSystemDTO;
33  import fr.ifremer.dali.dto.referential.QualityLevelDTO;
34  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
35  import fr.ifremer.dali.ui.swing.util.table.DaliColumnIdentifier;
36  import fr.ifremer.quadrige3.ui.swing.table.SwingTableColumnModel;
37  
38  import java.time.LocalDate;
39  import java.util.Date;
40  
41  import static org.nuiton.i18n.I18n.n;
42  
43  /**
44   * <p>SurveysTableModel class.</p>
45   *
46   * @author Antoine
47   */
48  public class SurveysTableModel extends AbstractDaliTableModel<SurveysTableRowModel> {
49  
50      /** Constant <code>SYNCHRONIZATION_STATUS</code> */
51      public static final DaliColumnIdentifier<SurveysTableRowModel> SYNCHRONIZATION_STATUS = DaliColumnIdentifier.newId(
52              SurveysTableRowModel.PROPERTY_SYNCHRONIZATION_STATUS,
53              n("dali.property.synchronizationStatus"),
54              n("dali.property.synchronizationStatus"),
55              SynchronizationStatusDTO.class);
56  
57      /** Constant <code>STATE</code> */
58      public static final DaliColumnIdentifier<SurveysTableRowModel> STATE = DaliColumnIdentifier.newId(
59              SurveysTableRowModel.PROPERTY_STATE,
60              n("dali.property.status"),
61              n("dali.property.status"),
62              StateDTO.class);
63  
64      /** Constant <code>LOCATION</code> */
65      public static final DaliColumnIdentifier<SurveysTableRowModel> LOCATION = DaliColumnIdentifier.newId(
66              SurveysTableRowModel.PROPERTY_LOCATION,
67              n("dali.property.location"),
68              n("dali.property.location"),
69              LocationDTO.class,
70              true);
71  
72      /** Constant <code>DATE</code> */
73      public static final DaliColumnIdentifier<SurveysTableRowModel> DATE = DaliColumnIdentifier.newId(
74              SurveysTableRowModel.PROPERTY_DATE,
75              n("dali.property.date"),
76              n("dali.property.date"),
77              LocalDate.class,
78              true);
79  
80      /** Constant <code>BOTTOM_DEPTH</code> */
81      public static final DaliColumnIdentifier<SurveysTableRowModel> BOTTOM_DEPTH = DaliColumnIdentifier.newId(
82              SurveysTableRowModel.PROPERTY_BOTTOM_DEPTH,
83              n("dali.property.depth.bottom"),
84              n("dali.property.depth.bottom"),
85              Double.class);
86  
87      /** Constant <code>PROGRAM</code> */
88      public static final DaliColumnIdentifier<SurveysTableRowModel> PROGRAM = DaliColumnIdentifier.newId(
89              SurveysTableRowModel.PROPERTY_PROGRAM,
90              n("dali.property.program"),
91              n("dali.property.program"),
92              ProgramDTO.class,
93              true);
94  
95  	public static final DaliColumnIdentifier<SurveysTableRowModel> CAMPAIGN = DaliColumnIdentifier.newId(
96  			SurveysTableRowModel.PROPERTY_CAMPAIGN,
97  			n("dali.property.campaign"),
98  			n("dali.property.campaign"),
99  			CampaignDTO.class);
100 
101     /** Constant <code>COMMENT</code> */
102     public static final DaliColumnIdentifier<SurveysTableRowModel> COMMENT = DaliColumnIdentifier.newId(
103             SurveysTableRowModel.PROPERTY_COMMENT,
104             n("dali.property.comment"),
105             n("dali.property.comment"),
106             String.class);
107 
108     /** Constant <code>LATITUDE_MIN</code> */
109     public static final DaliColumnIdentifier<SurveysTableRowModel> LATITUDE_MIN = DaliColumnIdentifier.newId(
110             SurveysTableRowModel.PROPERTY_LATITUDE_MIN,
111             n("dali.survey.coordinates.latitude.min"),
112             n("dali.survey.coordinates.latitude.min"),
113             Double.class);
114 
115     /** Constant <code>LONGITUDE_MIN</code> */
116     public static final DaliColumnIdentifier<SurveysTableRowModel> LONGITUDE_MIN = DaliColumnIdentifier.newId(
117             SurveysTableRowModel.PROPERTY_LONGITUDE_MIN,
118             n("dali.survey.coordinates.longitude.min"),
119             n("dali.survey.coordinates.longitude.min"),
120             Double.class);
121 
122     /** Constant <code>LATITUDE_MIN</code> */
123     public static final DaliColumnIdentifier<SurveysTableRowModel> LATITUDE_MAX = DaliColumnIdentifier.newId(
124             SurveysTableRowModel.PROPERTY_LATITUDE_MAX,
125             n("dali.survey.coordinates.latitude.max"),
126             n("dali.survey.coordinates.latitude.max"),
127             Double.class);
128 
129     /** Constant <code>LONGITUDE_MIN</code> */
130     public static final DaliColumnIdentifier<SurveysTableRowModel> LONGITUDE_MAX = DaliColumnIdentifier.newId(
131             SurveysTableRowModel.PROPERTY_LONGITUDE_MAX,
132             n("dali.survey.coordinates.longitude.max"),
133             n("dali.survey.coordinates.longitude.max"),
134             Double.class);
135 
136     /** Constant <code>POSITIONING</code> */
137     public static final DaliColumnIdentifier<SurveysTableRowModel> POSITIONING = DaliColumnIdentifier.newId(
138             SurveysTableRowModel.PROPERTY_POSITIONING,
139             n("dali.property.positioning.name"),
140             n("dali.property.positioning.name"),
141             PositioningSystemDTO.class);
142 
143     /** Constant <code>POSITIONING_PRECISION</code> */
144     public static final DaliColumnIdentifier<SurveysTableRowModel> POSITIONING_PRECISION = DaliColumnIdentifier.newId(
145             SurveysTableRowModel.PROPERTY_POSITIONING_PRECISION,
146             n("dali.property.positioning.precision"),
147             n("dali.property.positioning.precision"),
148             String.class);
149 
150     /** Constant <code>NAME</code> */
151     public static final DaliColumnIdentifier<SurveysTableRowModel> NAME = DaliColumnIdentifier.newId(
152             SurveysTableRowModel.PROPERTY_NAME,
153             n("dali.property.mnemonic"),
154             n("dali.property.mnemonic"),
155             String.class);
156 
157     /** Constant <code>RECORDER_DEPARTMENT</code> */
158     public static final DaliColumnIdentifier<SurveysTableRowModel> RECORDER_DEPARTMENT = DaliColumnIdentifier.newId(
159             SurveysTableRowModel.PROPERTY_DEPARTMENT,
160             n("dali.property.department.recorder"),
161             n("dali.property.department.recorder"),
162             DepartmentDTO.class);
163 
164     /** Constant <code>TIME</code> */
165     public static final DaliColumnIdentifier<SurveysTableRowModel> TIME = DaliColumnIdentifier.newId(
166             SurveysTableRowModel.PROPERTY_TIME,
167             n("dali.property.survey.time"),
168             n("dali.property.survey.time"),
169             Integer.class);
170 
171     /** Constant <code>UPDATE_DATE</code> */
172     public static final DaliColumnIdentifier<SurveysTableRowModel> UPDATE_DATE = DaliColumnIdentifier.newId(
173             SurveysTableRowModel.PROPERTY_UPDATE_DATE,
174             n("dali.property.date.modification"),
175             n("dali.property.date.modification"),
176             Date.class);
177 
178     /** Constant <code>CONTROL_DATE</code> */
179     public static final DaliColumnIdentifier<SurveysTableRowModel> CONTROL_DATE = DaliColumnIdentifier.newId(
180             SurveysTableRowModel.PROPERTY_CONTROL_DATE,
181             n("dali.property.date.control"),
182             n("dali.property.date.control"),
183             Date.class);
184 
185     /** Constant <code>VALIDATION_DATE</code> */
186     public static final DaliColumnIdentifier<SurveysTableRowModel> VALIDATION_DATE = DaliColumnIdentifier.newId(
187             SurveysTableRowModel.PROPERTY_VALIDATION_DATE,
188             n("dali.property.date.validation"),
189             n("dali.property.date.validation"),
190             Date.class);
191 
192     /** Constant <code>VALIDATION_COMMENT</code> */
193     public static final DaliColumnIdentifier<SurveysTableRowModel> VALIDATION_COMMENT = DaliColumnIdentifier.newId(
194             SurveysTableRowModel.PROPERTY_VALIDATION_COMMENT,
195             n("dali.property.comment.validation"),
196             n("dali.property.comment.validation"),
197             String.class);
198 
199     /** Constant <code>QUALIFICATION_DATE</code> */
200     public static final DaliColumnIdentifier<SurveysTableRowModel> QUALIFICATION_DATE = DaliColumnIdentifier.newId(
201             SurveysTableRowModel.PROPERTY_QUALIFICATION_DATE,
202             n("dali.property.date.qualification"),
203             n("dali.property.date.qualification"),
204             Date.class);
205 
206     /** Constant <code>QUALIFICATION_COMMENT</code> */
207     public static final DaliColumnIdentifier<SurveysTableRowModel> QUALIFICATION_COMMENT = DaliColumnIdentifier.newId(
208             SurveysTableRowModel.PROPERTY_QUALIFICATION_COMMENT,
209             n("dali.property.comment.qualification"),
210             n("dali.property.comment.qualification"),
211             String.class);
212 
213     public static final DaliColumnIdentifier<SurveysTableRowModel> QUALITY_FLAG = DaliColumnIdentifier.newId(
214             SurveysTableRowModel.PROPERTY_QUALITY_LEVEL,
215             n("dali.property.qualityFlag"),
216             n("dali.property.qualityFlag"),
217             QualityLevelDTO.class);
218 
219     /**
220      * <p>Constructor for SurveysTableModel.</p>
221      *
222      */
223     public SurveysTableModel(final SwingTableColumnModel columnModel) {
224         super(columnModel, true, false);
225     }
226 
227     /** {@inheritDoc} */
228     @Override
229     public SurveysTableRowModel createNewRow() {
230         return new SurveysTableRowModel();
231     }
232 
233     /** {@inheritDoc} */
234     @Override
235     public DaliColumnIdentifier<SurveysTableRowModel> getFirstColumnEditing() {
236         return PROGRAM;
237     }
238 
239     /** {@inheritDoc} */
240     @Override
241     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<SurveysTableRowModel> propertyName) {
242 
243         // validation and qualification comments are always editable
244         if (VALIDATION_COMMENT == propertyName || QUALIFICATION_COMMENT == propertyName) return true;
245 
246         boolean editable = true;
247         // Positioning is allowed when coordinate is set
248         if (POSITIONING == propertyName) {
249             SurveysTableRowModel rowModel = getEntry(rowIndex);
250             editable = rowModel.getLatitudeMin() != null || rowModel.getLongitudeMin() != null;
251         }
252 
253         return editable && super.isCellEditable(rowIndex, columnIndex, propertyName);
254     }
255 
256     @Override
257     public SurveysTableUIModel getTableUIModel() {
258         return (SurveysTableUIModel) super.getTableUIModel();
259     }
260 
261     @Override
262     public String getStateContext() {
263 
264         if (getTableUIModel().getMainUIModel() != null) {
265             // Use program code in filter to set state context (Mantis #52357)
266             return getTableUIModel().getMainUIModel().getStateContext();
267         }
268 
269         return super.getStateContext();
270     }
271 }