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