View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.rule.controlrule;
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.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   * Model.
38   */
39  public class ControlRuleTableModel extends AbstractDaliTableModel<ControlRuleRowModel> {
40  
41      /**
42       * Constant <code>CODE</code>
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       * Constant <code>FUNCTION</code>
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       * Constant <code>CONTROL_ELEMENT</code>
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       * Constant <code>CONTROL_FEATURE</code>
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       * Constant <code>ACTIVE</code>
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       * Constant <code>BLOCKING</code>
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       * Constant <code>MIN</code>
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      * Constant <code>MAX</code>
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      * Constant <code>ALLOWED_VALUES</code>
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      * <p>Constructor for ControlRuleTableModel.</p>
124      */
125     public ControlRuleTableModel(final SwingTableColumnModel columnModel) {
126         super(columnModel, true, false);
127     }
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public ControlRuleRowModel createNewRow() {
134         return new ControlRuleRowModel();
135     }
136 
137     /**
138      * {@inheritDoc}
139      */
140     @Override
141     public DaliColumnIdentifier<ControlRuleRowModel> getFirstColumnEditing() {
142         return FUNCTION;
143     }
144 
145     /**
146      * {@inheritDoc}
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 //            } else if (ALLOWED_VALUES.equals(propertyName)) {
158 //                ControlRuleRowModel rowModel = getEntry(rowIndex);
159 //                FunctionDTO function = rowModel.getFunction();
160 //                editable = ControlFunctionValues.IS_AMONG.equals(function) || (ControlFunctionValues.PRECONDITION.equals(function) && rowModel.isPmfmValid());
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 }