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