1 package fr.ifremer.quadrige3.ui.swing.table;
2
3 /*-
4 * #%L
5 * Quadrige3 Core :: Quadrige3 UI Common
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2017 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.quadrige3.ui.swing.model.AbstractBeanUIModel;
27 import org.nuiton.util.beans.Binder;
28
29 import java.util.HashSet;
30 import java.util.Set;
31
32 /**
33 * <p>Abstract AbstractRowUIModel class.</p>
34 *
35 * @author Ludovic Pecquot <ludovic.pecquot@e-is.pro>
36 * @param <B>
37 * @param <M>
38 */
39 public abstract class AbstractRowUIModel<B, M extends AbstractRowUIModel<B, M>> extends AbstractBeanUIModel<B, M> {
40
41 /** Constant <code>PROPERTY_SELECTED="selected"</code> */
42 public static final String PROPERTY_SELECTED = "selected";
43
44 /**
45 * selected state
46 */
47 protected boolean selected;
48
49 /**
50 * a row is editable by default (each cell can be editable or not).
51 * if editable is false, the row is read-only
52 */
53 protected boolean editable;
54
55 /**
56 * a calculated row is read-only row with specific decoration if needed
57 */
58 protected boolean calculated;
59
60 /**
61 * a complete row is a row with all mandatory identifiers valid
62 */
63 protected final Set<ColumnIdentifier> invalidMandatoryIdentifiers;
64
65 /**
66 * <p>Constructor for AbstractRowUIModel.</p>
67 *
68 * @param fromBeanBinder a {@link Binder} object.
69 * @param toBeanBinder a {@link Binder} object.
70 */
71 public AbstractRowUIModel(Binder<B, M> fromBeanBinder, Binder<M, B> toBeanBinder) {
72 super(fromBeanBinder, toBeanBinder);
73
74 // by default a row is editable
75 editable = true;
76 invalidMandatoryIdentifiers = new HashSet<>();
77 }
78
79 /**
80 * <p>isSelected.</p>
81 *
82 * @return a boolean.
83 */
84 public boolean isSelected() {
85 return selected;
86 }
87
88 /**
89 * <p>Setter for the field <code>selected</code>.</p>
90 *
91 * @param selected a boolean.
92 */
93 public void setSelected(boolean selected) {
94 boolean oldValue = isSelected();
95 this.selected = selected;
96 firePropertyChange(PROPERTY_SELECTED, oldValue, selected);
97 }
98
99 /**
100 * <p>isEditable.</p>
101 *
102 * @return a boolean.
103 */
104 public boolean isEditable() {
105 return editable;
106 }
107
108 /**
109 * <p>Setter for the field <code>editable</code>.</p>
110 *
111 * @param editable a boolean.
112 */
113 public void setEditable(boolean editable) {
114 this.editable = editable;
115 }
116
117 /**
118 * <p>isCalculated.</p>
119 *
120 * @return a boolean.
121 */
122 public boolean isCalculated() {
123 return calculated;
124 }
125
126 /**
127 * <p>Setter for the field <code>calculated</code>.</p>
128 *
129 * @param calculated a boolean.
130 */
131 public void setCalculated(boolean calculated) {
132 this.calculated = calculated;
133 // set also editable property
134 setEditable(!calculated);
135 }
136
137 /**
138 * <p>isMandatoryValid.</p>
139 *
140 * @return a boolean.
141 */
142 public boolean isMandatoryValid() {
143 return invalidMandatoryIdentifiers.isEmpty();
144 }
145
146 void addInvalidMandatoryProperty(ColumnIdentifier identifier) {
147 invalidMandatoryIdentifiers.add(identifier);
148 }
149
150 void removeInvalidMandatoryProperty(ColumnIdentifier identifier) {
151 invalidMandatoryIdentifiers.remove(identifier);
152 }
153
154 public Set<ColumnIdentifier> getInvalidMandatoryIdentifiers() {
155 return invalidMandatoryIdentifiers;
156 }
157 }