View Javadoc
1   package fr.ifremer.dali.ui.swing.content.home.operation;
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.data.sampling.SamplingOperationDTO;
27  import fr.ifremer.dali.dto.data.survey.SurveyDTO;
28  import fr.ifremer.dali.dto.referential.*;
29  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
30  import fr.ifremer.dali.ui.swing.util.table.DaliColumnIdentifier;
31  import fr.ifremer.quadrige3.ui.swing.table.SwingTableColumnModel;
32  
33  import static org.nuiton.i18n.I18n.n;
34  
35  /**
36   * Le modele pour le tableau de prelevements pour l'ecran d accueil.
37   */
38  public class OperationsTableModel extends AbstractDaliTableModel<OperationsTableRowModel> {
39  
40      /**
41       * Identifiant pour la colonne mnemonique.
42       */
43      public static final DaliColumnIdentifier<OperationsTableRowModel> NAME = DaliColumnIdentifier.newId(
44              OperationsTableRowModel.PROPERTY_NAME,
45              n("dali.property.mnemonic"),
46              n("dali.property.mnemonic"),
47              String.class,
48              true);
49      /**
50       * Identifiant pour la colonne engin.
51       */
52      public static final DaliColumnIdentifier<OperationsTableRowModel> SAMPLING_EQUIPMENT = DaliColumnIdentifier.newId(
53              OperationsTableRowModel.PROPERTY_SAMPLING_EQUIPMENT,
54              n("dali.property.samplingEquipment"),
55              n("dali.property.samplingEquipment"),
56              SamplingEquipmentDTO.class,
57              true);
58      /**
59       * Identifiant pour la colonne heure.
60       */
61      public static final DaliColumnIdentifier<OperationsTableRowModel> TIME = DaliColumnIdentifier.newId(
62              OperationsTableRowModel.PROPERTY_TIME,
63              n("dali.property.time"),
64              n("dali.property.time"),
65              Integer.class);
66      /**
67       * Identifiant pour la colonne taille.
68       */
69      public static final DaliColumnIdentifier<OperationsTableRowModel> SIZE = DaliColumnIdentifier.newId(
70              OperationsTableRowModel.PROPERTY_SIZE,
71              n("dali.property.size"),
72              n("dali.property.size"),
73              Double.class);
74      /**
75       * Identifiant pour la colonne unite taille.
76       */
77      public static final DaliColumnIdentifier<OperationsTableRowModel> SIZE_UNIT = DaliColumnIdentifier.newId(
78              OperationsTableRowModel.PROPERTY_SIZE_UNIT,
79              n("dali.property.unit"),
80              n("dali.property.unit"),
81              UnitDTO.class);
82      /**
83       * Identifiant pour la colonne commentaire.
84       */
85      public static final DaliColumnIdentifier<OperationsTableRowModel> COMMENT = DaliColumnIdentifier.newId(
86              OperationsTableRowModel.PROPERTY_COMMENT,
87              n("dali.property.comment"),
88              n("dali.property.comment"),
89              String.class);
90      /**
91       * Identifiant pour la colonne service preleveur.
92       */
93      public static final DaliColumnIdentifier<OperationsTableRowModel> SAMPLING_DEPARTMENT = DaliColumnIdentifier.newId(
94              OperationsTableRowModel.PROPERTY_SAMPLING_DEPARTMENT,
95              n("dali.property.department.sampler"),
96              n("dali.home.samplingOperation.department.sampler.tip"),
97              DepartmentDTO.class, true);
98      /**
99       * Identifiant pour la colonne analyst.
100      */
101     public static final DaliColumnIdentifier<OperationsTableRowModel> ANALYST = DaliColumnIdentifier.newId(
102             OperationsTableRowModel.PROPERTY_ANALYST,
103             n("dali.property.analyst"),
104             n("dali.home.samplingOperation.department.analyst.tip"),
105             DepartmentDTO.class);
106 
107     /**
108      * Identifiant pour la colonne immersion.
109      */
110     public static final DaliColumnIdentifier<OperationsTableRowModel> DEPTH = DaliColumnIdentifier.newId(
111             OperationsTableRowModel.PROPERTY_DEPTH,
112             n("dali.property.depth.precise"),
113             n("dali.home.samplingOperation.depth.precise.tip"),
114             Double.class);
115 
116     /**
117      * Identifiant pour la colonne niveau.
118      */
119     public static final DaliColumnIdentifier<OperationsTableRowModel> DEPTH_LEVEL = DaliColumnIdentifier.newId(
120             OperationsTableRowModel.PROPERTY_DEPTH_LEVEL,
121             n("dali.property.level"),
122             n("dali.property.level"),
123             LevelDTO.class);
124 
125     /**
126      * Identifiant pour la colonne immersion min.
127      */
128     public static final DaliColumnIdentifier<OperationsTableRowModel> MIN_DEPTH = DaliColumnIdentifier.newId(
129             OperationsTableRowModel.PROPERTY_MIN_DEPTH,
130             n("dali.property.depth.precise.min"),
131             n("dali.home.samplingOperation.depth.precise.min.tip"),
132             Double.class);
133     /**
134      * Identifiant pour la colonne immersion.
135      */
136     public static final DaliColumnIdentifier<OperationsTableRowModel> MAX_DEPTH = DaliColumnIdentifier.newId(
137             OperationsTableRowModel.PROPERTY_MAX_DEPTH,
138             n("dali.property.depth.precise.max"),
139             n("dali.home.samplingOperation.depth.precise.max.tip"),
140             Double.class);
141     /**
142      * Identifiant pour la colonne coordonnees (latitude).
143      */
144     public static final DaliColumnIdentifier<OperationsTableRowModel> LATITUDE = DaliColumnIdentifier.newId(
145             OperationsTableRowModel.PROPERTY_LATITUDE,
146             n("dali.property.latitude.real"),
147             n("dali.home.samplingOperation.latitude.tip"),
148             Double.class);
149     /**
150      * Identifiant pour la colonne coordonnees (longitude).
151      */
152     public static final DaliColumnIdentifier<OperationsTableRowModel> LONGITUDE = DaliColumnIdentifier.newId(
153             OperationsTableRowModel.PROPERTY_LONGITUDE,
154             n("dali.property.longitude.real"),
155             n("dali.home.samplingOperation.longitude.tip"),
156             Double.class);
157     /**
158      * Identifiant pour la colonne positionnement.
159      */
160     public static final DaliColumnIdentifier<OperationsTableRowModel> POSITIONING = DaliColumnIdentifier.newId(
161             OperationsTableRowModel.PROPERTY_POSITIONING,
162             n("dali.property.positioning.name"),
163             n("dali.home.samplingOperation.positioning.name.tip"),
164             PositioningSystemDTO.class);
165 
166     /**
167      * Constant <code>POSITIONING_PRECISION</code>
168      */
169     public static final DaliColumnIdentifier<OperationsTableRowModel> POSITIONING_PRECISION = DaliColumnIdentifier.newReadOnlyId(
170             OperationsTableRowModel.PROPERTY_POSITIONING_PRECISION,
171             n("dali.property.positioning.precision"),
172             n("dali.home.samplingOperation.positioning.precision.tip"),
173             String.class);
174 
175     private boolean readOnly;
176     private boolean nameInModel;
177 
178     /**
179      * Constructor.
180      *
181      * @param columnModel Le modele pour les colonnes
182      */
183     public OperationsTableModel(final SwingTableColumnModel columnModel, boolean createNewRow) {
184         super(columnModel, createNewRow, false);
185         readOnly = false;
186         try {
187             columnModel.getColumnIndex(NAME);
188             nameInModel = true;
189         } catch (IllegalArgumentException e) {
190             nameInModel = false;
191         }
192     }
193 
194     /**
195      * {@inheritDoc}
196      */
197     @Override
198     public OperationsTableRowModel createNewRow() {
199         return new OperationsTableRowModel(readOnly);
200     }
201 
202     /**
203      * {@inheritDoc}
204      */
205     @Override
206     public DaliColumnIdentifier<OperationsTableRowModel> getFirstColumnEditing() {
207         return nameInModel ? NAME : SAMPLING_EQUIPMENT;
208     }
209 
210     /**
211      * <p>Setter for the field <code>readOnly</code>.</p>
212      *
213      * @param readOnly a boolean.
214      */
215     public void setReadOnly(boolean readOnly) {
216         this.readOnly = readOnly;
217     }
218 
219     /**
220      * {@inheritDoc}
221      */
222     @Override
223     public AbstractOperationsTableUIModel getTableUIModel() {
224         return (AbstractOperationsTableUIModel) super.getTableUIModel();
225     }
226 
227     /**
228      * {@inheritDoc}
229      */
230     @Override
231     public String getStateContext() {
232         if (getTableUIModel().getSurvey() != null && getTableUIModel().getSurvey().getProgram() != null) {
233 
234             return SurveyDTO.PROPERTY_SAMPLING_OPERATIONS + '_'
235                     + SamplingOperationDTO.PROPERTY_PMFMS + '_'
236                     + getTableUIModel().getSurvey().getProgram().getCode();
237 
238         }
239 
240         return super.getStateContext();
241     }
242 
243     /**
244      * {@inheritDoc}
245      */
246     @Override
247     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<OperationsTableRowModel> propertyName) {
248 
249         boolean editable = true;
250         // Positioning is allowed when coordinate is set
251         if (POSITIONING == propertyName) {
252             OperationsTableRowModel rowModel = getEntry(rowIndex);
253             editable = rowModel.getLatitude() != null || rowModel.getLongitude() != null;
254         }
255 
256         return editable && super.isCellEditable(rowIndex, columnIndex, propertyName);
257     }
258 }