View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.table;
2   
3   /*
4    * #%L
5    * Reef DB :: 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.reefdb.decorator.DecoratorService;
27  import fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
28  import fr.ifremer.reefdb.dto.referential.UnitDTO;
29  import fr.ifremer.reefdb.dto.referential.pmfm.*;
30  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableModel;
31  import fr.ifremer.reefdb.ui.swing.util.table.ReefDbColumnIdentifier;
32  import org.jdesktop.swingx.table.TableColumnModelExt;
33  
34  import java.util.Date;
35  
36  import static org.nuiton.i18n.I18n.n;
37  
38  /**
39   * Model.
40   */
41  public class PmfmTableModel extends AbstractReefDbTableModel<PmfmTableRowModel> {
42  
43      public static final ReefDbColumnIdentifier<PmfmTableRowModel> PMFM_ID = ReefDbColumnIdentifier.newReadOnlyId(
44              PmfmTableRowModel.PROPERTY_ID,
45              n("reefdb.property.pmfm.id"),
46              n("reefdb.property.pmfm.id"),
47              Integer.class);
48  
49      /** Constant <code>NAME</code> */
50      public static final ReefDbColumnIdentifier<PmfmTableRowModel> NAME = ReefDbColumnIdentifier.newPmfmNameId(
51              n("reefdb.property.name"),
52              n("reefdb.property.name"));
53  
54      /** Constant <code>PARAMETER</code> */
55      public static final ReefDbColumnIdentifier<PmfmTableRowModel> PARAMETER = ReefDbColumnIdentifier.newId(
56              PmfmTableRowModel.PROPERTY_PARAMETER,
57              n("reefdb.property.pmfm.parameter"),
58              n("reefdb.property.pmfm.parameter"),
59              ParameterDTO.class,
60              true);
61  
62      /** Constant <code>SUPPORT</code> */
63      public static final ReefDbColumnIdentifier<PmfmTableRowModel> SUPPORT = ReefDbColumnIdentifier.newId(
64              PmfmTableRowModel.PROPERTY_MATRIX,
65              n("reefdb.property.pmfm.matrix"),
66              n("reefdb.property.pmfm.matrix"),
67              MatrixDTO.class,
68              true);
69  
70      /** Constant <code>FRACTION</code> */
71      public static final ReefDbColumnIdentifier<PmfmTableRowModel> FRACTION = ReefDbColumnIdentifier.newId(
72              PmfmTableRowModel.PROPERTY_FRACTION,
73              n("reefdb.property.pmfm.fraction"),
74              n("reefdb.property.pmfm.fraction"),
75              FractionDTO.class,
76              true);
77  
78      /** Constant <code>METHOD</code> */
79      public static final ReefDbColumnIdentifier<PmfmTableRowModel> METHOD = ReefDbColumnIdentifier.newId(
80              PmfmTableRowModel.PROPERTY_METHOD,
81              n("reefdb.property.pmfm.method"),
82              n("reefdb.property.pmfm.method"),
83              MethodDTO.class,
84              true);
85  
86      /** Constant <code>UNIT</code> */
87      public static final ReefDbColumnIdentifier<PmfmTableRowModel> UNIT = ReefDbColumnIdentifier.newId(
88              PmfmTableRowModel.PROPERTY_UNIT,
89              n("reefdb.property.pmfm.unit"),
90              n("reefdb.property.pmfm.unit"),
91              UnitDTO.class,
92              true);
93  
94      // qualitative values
95      /** Constant <code>QUALITATIVE_VALUES</code> */
96      public static final ReefDbColumnIdentifier<PmfmTableRowModel> QUALITATIVE_VALUES = ReefDbColumnIdentifier.newId(
97              PmfmTableRowModel.PROPERTY_QUALITATIVE_VALUES,
98              n("reefdb.property.pmfm.parameter.associatedQualitativeValue"),
99              n("reefdb.property.pmfm.parameter.associatedQualitativeValue"),
100             QualitativeValueDTO.class,
101             DecoratorService.COLLECTION_SIZE);
102 
103     /** Constant <code>STATUS</code> */
104     public static final ReefDbColumnIdentifier<PmfmTableRowModel> STATUS = ReefDbColumnIdentifier.newId(
105             PmfmTableRowModel.PROPERTY_STATUS,
106             n("reefdb.property.status"),
107             n("reefdb.property.status"),
108             StatusDTO.class,
109             true);
110 
111     // TODO : threshold, maxDecimal and SignificativeNb are not used in this table... remove ?
112 
113 //	public static final ReefDbColumnIdentifier<PmfmTableRowModel> THRESHOLD = ReefDbColumnIdentifier.newId(
114 //			PmfmTableRowModel.PROPERTY_THRESHOLD,
115 //			n("reefdb.property.pmfm.threshold"),
116 //			n("reefdb.property.pmfm.threshold"),
117 //			Double.class);
118 //	public static final ReefDbColumnIdentifier<PmfmTableRowModel> MAX_DECIMAL_NUMBER = ReefDbColumnIdentifier.newId(
119 //			PmfmTableRowModel.PROPERTY_MAX_DECIMAL_NB,
120 //			n("reefdb.property.pmfm.maxDecimalNumber"),
121 //			n("reefdb.property.pmfm.maxDecimalNumber"),
122 //			Integer.class);
123 //	public static final ReefDbColumnIdentifier<PmfmTableRowModel> SIGNIFICANT_DIGITS_NUMBER = ReefDbColumnIdentifier.newId(
124 //			PmfmTableRowModel.PROPERTY_SIGNIFICATIVE_FIGURES_NB,
125 //			n("reefdb.property.pmfm.significantDigitsNumber"),
126 //			n("reefdb.property.pmfm.significantDigitsNumber"),
127 //			Integer.class);
128 
129 
130     public static final ReefDbColumnIdentifier<PmfmTableRowModel> COMMENT = ReefDbColumnIdentifier.newId(
131         PmfmTableRowModel.PROPERTY_COMMENT,
132         n("reefdb.property.comment"),
133         n("reefdb.property.comment"),
134         String.class,
135         false);
136 
137     public static final ReefDbColumnIdentifier<PmfmTableRowModel> CREATION_DATE = ReefDbColumnIdentifier.newReadOnlyId(
138         PmfmTableRowModel.PROPERTY_CREATION_DATE,
139         n("reefdb.property.date.creation"),
140         n("reefdb.property.date.creation"),
141         Date.class);
142 
143     public static final ReefDbColumnIdentifier<PmfmTableRowModel> UPDATE_DATE = ReefDbColumnIdentifier.newReadOnlyId(
144         PmfmTableRowModel.PROPERTY_UPDATE_DATE,
145         n("reefdb.property.date.modification"),
146         n("reefdb.property.date.modification"),
147         Date.class);
148 
149 
150     /**
151      * <p>Constructor for PmfmTableModel.</p>
152      *
153      * @param columnModel a {@link org.jdesktop.swingx.table.TableColumnModelExt} object.
154      */
155     public PmfmTableModel(final TableColumnModelExt columnModel) {
156         super(columnModel, true, false);
157     }
158 
159     /** {@inheritDoc} */
160     @Override
161     public PmfmTableRowModel createNewRow() {
162         return new PmfmTableRowModel();
163     }
164 
165     /** {@inheritDoc} */
166     @Override
167     public ReefDbColumnIdentifier<PmfmTableRowModel> getFirstColumnEditing() {
168         return PARAMETER;
169     }
170 
171     /** {@inheritDoc} */
172     @Override
173     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<PmfmTableRowModel> propertyName) {
174         if (propertyName.equals(QUALITATIVE_VALUES)) {
175             PmfmTableRowModel row = getEntry(rowIndex);
176             return super.isCellEditable(rowIndex, columnIndex, propertyName) && row.getParameter() != null && row.getParameter().isQualitative();
177         } else {
178             return super.isCellEditable(rowIndex, columnIndex, propertyName);
179         }
180     }
181 
182 }