1 package fr.ifremer.dali.ui.swing.content.manage.rule.controlrule;
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.dto.FunctionDTO;
27 import fr.ifremer.dali.dto.configuration.control.ControlElementDTO;
28 import fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO;
29 import fr.ifremer.dali.dto.enums.ControlFunctionValues;
30 import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
31 import fr.ifremer.dali.ui.swing.util.table.DaliColumnIdentifier;
32 import fr.ifremer.quadrige3.ui.swing.table.SwingTableColumnModel;
33
34 import static org.nuiton.i18n.I18n.n;
35
36
37
38
39 public class ControlRuleTableModel extends AbstractDaliTableModel<ControlRuleRowModel> {
40
41
42
43
44 public static final DaliColumnIdentifier<ControlRuleRowModel> CODE = DaliColumnIdentifier.newId(
45 ControlRuleRowModel.PROPERTY_CODE,
46 n("dali.property.code"),
47 n("dali.rule.controlRule.code.tip"),
48 String.class);
49
50
51
52
53 public static final DaliColumnIdentifier<ControlRuleRowModel> FUNCTION = DaliColumnIdentifier.newId(
54 ControlRuleRowModel.PROPERTY_FUNCTION,
55 n("dali.rule.controlRule.function.short"),
56 n("dali.rule.controlRule.function.tip"),
57 FunctionDTO.class, true);
58
59
60
61
62 public static final DaliColumnIdentifier<ControlRuleRowModel> CONTROL_ELEMENT = DaliColumnIdentifier.newId(
63 ControlRuleRowModel.PROPERTY_CONTROL_ELEMENT,
64 n("dali.rule.controlRule.controlElement.short"),
65 n("dali.rule.controlRule.controlElement.tip"),
66 ControlElementDTO.class, true);
67
68
69
70
71 public static final DaliColumnIdentifier<ControlRuleRowModel> CONTROL_FEATURE = DaliColumnIdentifier.newId(
72 ControlRuleRowModel.PROPERTY_CONTROL_FEATURE,
73 n("dali.rule.controlRule.controlFeature.short"),
74 n("dali.rule.controlRule.controlFeature.tip"),
75 ControlFeatureDTO.class, true);
76
77
78
79
80 public static final DaliColumnIdentifier<ControlRuleRowModel> ACTIVE = DaliColumnIdentifier.newId(
81 ControlRuleRowModel.PROPERTY_ACTIVE,
82 n("dali.rule.controlRule.active.short"),
83 n("dali.rule.controlRule.active.tip"),
84 Boolean.class);
85
86
87
88
89 public static final DaliColumnIdentifier<ControlRuleRowModel> BLOCKING = DaliColumnIdentifier.newId(
90 ControlRuleRowModel.PROPERTY_BLOCKING,
91 n("dali.rule.controlRule.blocking.short"),
92 n("dali.rule.controlRule.blocking.tip"),
93 Boolean.class);
94
95
96
97
98 public static final DaliColumnIdentifier<ControlRuleRowModel> MIN = DaliColumnIdentifier.newId(
99 ControlRuleRowModel.PROPERTY_MIN,
100 n("dali.rule.controlRule.min.short"),
101 n("dali.rule.controlRule.min.tip"),
102 Object.class);
103
104
105
106
107 public static final DaliColumnIdentifier<ControlRuleRowModel> MAX = DaliColumnIdentifier.newId(
108 ControlRuleRowModel.PROPERTY_MAX,
109 n("dali.rule.controlRule.max.short"),
110 n("dali.rule.controlRule.max.tip"),
111 Object.class);
112
113
114
115
116 public static final DaliColumnIdentifier<ControlRuleRowModel> ALLOWED_VALUES = DaliColumnIdentifier.newId(
117 ControlRuleRowModel.PROPERTY_ALLOWED_VALUES,
118 n("dali.rule.controlRule.allowedValues.short"),
119 n("dali.rule.controlRule.allowedValues.tip"),
120 String.class);
121
122
123
124
125 public ControlRuleTableModel(final SwingTableColumnModel columnModel) {
126 super(columnModel, true, false);
127 }
128
129
130
131
132 @Override
133 public ControlRuleRowModel createNewRow() {
134 return new ControlRuleRowModel();
135 }
136
137
138
139
140 @Override
141 public DaliColumnIdentifier<ControlRuleRowModel> getFirstColumnEditing() {
142 return FUNCTION;
143 }
144
145
146
147
148 @Override
149 public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<ControlRuleRowModel> propertyName) {
150 boolean editable = super.isCellEditable(rowIndex, columnIndex, propertyName);
151
152 if (editable) {
153 if (MIN.equals(propertyName) || MAX.equals(propertyName)) {
154 ControlRuleRowModel rowModel = getEntry(rowIndex);
155 FunctionDTO function = rowModel.getFunction();
156 editable = ControlFunctionValues.MIN_MAX.equals(function) || ControlFunctionValues.MIN_MAX_DATE.equals(function);
157
158
159
160
161 } else if (CONTROL_ELEMENT.equals(propertyName)
162 || CONTROL_FEATURE.equals(propertyName)
163 || BLOCKING.equals(propertyName)) {
164 ControlRuleRowModel rowModel = getEntry(rowIndex);
165 editable = !ControlFunctionValues.PRECONDITION.equals(rowModel.getFunction());
166 }
167 }
168
169 if (ALLOWED_VALUES.equals(propertyName)) {
170 ControlRuleRowModel rowModel = getEntry(rowIndex);
171 FunctionDTO function = rowModel.getFunction();
172 editable = ControlFunctionValues.IS_AMONG.equals(function) || (ControlFunctionValues.PRECONDITION.equals(function) && rowModel.isPmfmValid());
173 }
174
175 return editable;
176 }
177 }