View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.program.pmfms;
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.decorator.DecoratorService;
27  import fr.ifremer.dali.dto.referential.UnitDTO;
28  import fr.ifremer.dali.dto.referential.pmfm.*;
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  import org.nuiton.jaxx.application.swing.table.ColumnIdentifier;
33  
34  import java.util.Optional;
35  
36  import static org.nuiton.i18n.I18n.n;
37  
38  /**
39   * Le modele pour le tableau des programmes.
40   */
41  public class PmfmsTableModel extends AbstractDaliTableModel<PmfmsTableRowModel> {
42  
43      public static final DaliColumnIdentifier<PmfmsTableRowModel> PMFM_ID = DaliColumnIdentifier.newReadOnlyId(
44              PmfmsTableRowModel.PROPERTY_PMFM + '.' + PmfmDTO.PROPERTY_ID,
45              n("dali.property.pmfm.id"),
46              n("dali.property.pmfm.id"),
47              Integer.class);
48  
49      /**
50       * Identifiant pour la colonne libelle parametre.
51       */
52      public static final DaliColumnIdentifier<PmfmsTableRowModel> PMFM_NAME = DaliColumnIdentifier.newPmfmNameId(
53              PmfmsTableRowModel.PROPERTY_PMFM,
54              n("dali.property.pmfm.name"),
55              n("dali.program.pmfm.name.tip"));
56  
57      /**
58       * Identifiant pour la colonne code parametre.
59       */
60      public static final DaliColumnIdentifier<PmfmsTableRowModel> PARAMETER_CODE = DaliColumnIdentifier.newReadOnlyId(
61              PmfmsTableRowModel.PROPERTY_PMFM + '.' + PmfmDTO.PROPERTY_PARAMETER,
62              n("dali.property.pmfm.parameter.code"),
63              n("dali.program.pmfm.parameter.code.tip"),
64              ParameterDTO.class);
65  
66      /**
67       * Identifiant pour la colonne support.
68       */
69      public static final DaliColumnIdentifier<PmfmsTableRowModel> MATRIX = DaliColumnIdentifier.newReadOnlyId(
70              PmfmsTableRowModel.PROPERTY_PMFM + '.' + PmfmDTO.PROPERTY_MATRIX,
71              n("dali.property.pmfm.matrix"),
72              n("dali.program.pmfm.matrix"),
73              MatrixDTO.class);
74  
75      /**
76       * Identifiant pour la colonne fraction.
77       */
78      public static final DaliColumnIdentifier<PmfmsTableRowModel> FRACTION = DaliColumnIdentifier.newReadOnlyId(
79              PmfmsTableRowModel.PROPERTY_PMFM + '.' + PmfmDTO.PROPERTY_FRACTION,
80              n("dali.property.pmfm.fraction"),
81              n("dali.program.pmfm.fraction.tip"),
82              FractionDTO.class);
83  
84      /**
85       * Identifiant pour la colonne methode.
86       */
87      public static final DaliColumnIdentifier<PmfmsTableRowModel> METHOD = DaliColumnIdentifier.newReadOnlyId(
88              PmfmsTableRowModel.PROPERTY_PMFM + '.' + PmfmDTO.PROPERTY_METHOD,
89              n("dali.property.pmfm.method"),
90              n("dali.program.pmfm.method.tip"),
91              MethodDTO.class);
92  
93      /**
94       * Identifiant pour la colonne unite.
95       */
96      public static final DaliColumnIdentifier<PmfmsTableRowModel> UNIT = DaliColumnIdentifier.newReadOnlyId(
97              PmfmsTableRowModel.PROPERTY_PMFM + '.' + PmfmDTO.PROPERTY_UNIT,
98              n("dali.property.pmfm.unit"),
99              n("dali.program.pmfm.unit.tip"),
100             UnitDTO.class);
101 
102     /**
103      * Identifiant pour la colonne passage.
104      */
105     public static final DaliColumnIdentifier<PmfmsTableRowModel> SURVEY = DaliColumnIdentifier.newId(
106             PmfmsTableRowModel.PROPERTY_SURVEY,
107             n("dali.program.pmfm.survey.short"),
108             n("dali.program.pmfm.survey.tip"),
109             Boolean.class);
110 
111     /**
112      * Identifiant pour la colonne prelevement.
113      */
114     public static final DaliColumnIdentifier<PmfmsTableRowModel> SAMPLING = DaliColumnIdentifier.newId(
115             PmfmsTableRowModel.PROPERTY_SAMPLING,
116             n("dali.program.pmfm.samplingOperation.short"),
117             n("dali.program.pmfm.samplingOperation.tip"),
118             Boolean.class);
119 
120     /**
121      * Identifiant pour la colonne regroupement.
122      */
123     public static final DaliColumnIdentifier<PmfmsTableRowModel> GROUPING = DaliColumnIdentifier.newId(
124             PmfmsTableRowModel.PROPERTY_GROUPING,
125             n("dali.program.pmfm.grouping.short"),
126             n("dali.program.pmfm.grouping.tip"),
127             Boolean.class);
128 
129     /**
130      * Identifiant pour la colonne unicite.
131      */
132     public static final DaliColumnIdentifier<PmfmsTableRowModel> UNIQUE = DaliColumnIdentifier.newId(
133             PmfmsTableRowModel.PROPERTY_UNIQUE,
134             n("dali.program.pmfm.unique.short"),
135             n("dali.program.pmfm.unique.tip"),
136             Boolean.class);
137 
138     public static final DaliColumnIdentifier<PmfmsTableRowModel> QUALITATIVE_VALUES = DaliColumnIdentifier.newId(
139         PmfmsTableRowModel.PROPERTY_QUALITATIVE_VALUES,
140         n("dali.property.pmfm.parameter.associatedQualitativeValue"),
141         n("dali.property.pmfm.parameter.associatedQualitativeValue"),
142         QualitativeValueDTO.class,
143         DecoratorService.COLLECTION_SIZE);
144 
145     /**
146      * Constructor.
147      *
148      * @param columnModel Le modele pour les colonnes
149      */
150     public PmfmsTableModel(final SwingTableColumnModel columnModel) {
151         super(columnModel, false, false);
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public PmfmsTableRowModel createNewRow() {
157         return new PmfmsTableRowModel();
158     }
159 
160     /** {@inheritDoc} */
161     @Override
162     public DaliColumnIdentifier<PmfmsTableRowModel> getFirstColumnEditing() {
163         return SURVEY;
164     }
165 
166     @Override
167     public boolean isCellEditable(int rowIndex, int columnIndex, ColumnIdentifier<PmfmsTableRowModel> propertyName) {
168         if (propertyName.equals(QUALITATIVE_VALUES)) {
169             PmfmsTableRowModel row = getEntry(rowIndex);
170             return Optional.ofNullable(row.getPmfm()).map(PmfmDTO::getParameter).map(ParameterDTO::isQualitative).orElse(false);
171         } else {
172             return super.isCellEditable(rowIndex, columnIndex, propertyName);
173         }
174     }
175 }