1 package fr.ifremer.dali.ui.swing.content.manage.program.pmfms;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
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
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
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
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
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
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
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
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
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
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
147
148
149
150 public PmfmsTableModel(final SwingTableColumnModel columnModel) {
151 super(columnModel, false, false);
152 }
153
154
155 @Override
156 public PmfmsTableRowModel createNewRow() {
157 return new PmfmsTableRowModel();
158 }
159
160
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 }