View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.persistence.entities.data.SampleCategory;
26  import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry;
27  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
28  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
29  
30  import java.io.Serializable;
31  
32  /**
33   * A row in the {@link SplitSpeciesBatchUIModel}.
34   *
35   * @author Tony Chemit - chemit@codelutin.com
36   * @since 0.3
37   */
38  public class SplitSpeciesBatchRowModel
39          extends AbstractTuttiBeanUIModel<SplitSpeciesBatchRowModel, SplitSpeciesBatchRowModel> {
40  
41      private static final long serialVersionUID = 1L;
42  
43      public static final String PROPERTY_CATEGORY_VALUE = "categoryValue";
44  
45      public static final String PROPERTY_WEIGHT = "weight";
46  
47      public static final String PROPERTY_SELECTED = "selected";
48  
49      public static final String PROPERTY_EDITABLE = "editable";
50  
51      /**
52       * Delegate sample category which contains category value + weight.
53       *
54       * @since 0.3
55       */
56      protected final SampleCategory<Serializable> category = SampleCategory.newSample(null);
57  
58      /**
59       * Is row selected?
60       *
61       * @since 2.5
62       */
63      protected boolean selected;
64  
65      /**
66       * Is row editable ? (in add mode incoming rows are all selected and not editable).
67       *
68       * @since 2.6
69       */
70      protected boolean editable;
71  
72      public SplitSpeciesBatchRowModel() {
73          super(null, null);
74      }
75  
76  //    public SampleCategoryModelEntry getCategorytype() {
77  //        return category.getCategoryDef();
78  //    }
79  
80      public void setCategoryType(SampleCategoryModelEntry categoryType) {
81          category.setCategoryDef(categoryType);
82      }
83  
84      public Serializable getCategoryValue() {
85          return category.getCategoryValue();
86      }
87  
88      public void setCategoryValue(Serializable categoryValue) {
89          Object oldValue = getCategoryValue();
90          category.setCategoryValue(categoryValue);
91          firePropertyChange(PROPERTY_CATEGORY_VALUE, oldValue, categoryValue);
92      }
93  
94      public void setCategoryValue(CaracteristicQualitativeValue categoryValue) {
95          Object oldValue = getCategoryValue();
96          category.setCategoryValue(categoryValue);
97          firePropertyChange(PROPERTY_CATEGORY_VALUE, oldValue, categoryValue);
98      }
99  
100     public void setCategoryValue(Float categoryValue) {
101         Object oldValue = getCategoryValue();
102         category.setCategoryValue(categoryValue);
103         firePropertyChange(PROPERTY_CATEGORY_VALUE, oldValue, categoryValue);
104     }
105 
106     public Float getWeight() {
107         return category.getCategoryWeight();
108     }
109 
110     public void setWeight(Float weight) {
111         Object oldValue = getWeight();
112         category.setCategoryWeight(weight);
113         firePropertyChange(PROPERTY_WEIGHT, oldValue, weight);
114     }
115 
116     public boolean isSelected() {
117         return selected;
118     }
119 
120     public void setSelected(boolean selected) {
121         Object oldValue = isSelected();
122         this.selected = selected;
123         firePropertyChange(PROPERTY_SELECTED, oldValue, selected);
124     }
125 
126     public boolean isEditable() {
127         return editable;
128     }
129 
130     public void setEditable(boolean editable) {
131         Object oldValue = isEditable();
132         this.editable = editable;
133         firePropertyChange(PROPERTY_EDITABLE, oldValue, editable);
134     }
135 
136     @Override
137     protected SplitSpeciesBatchRowModel newEntity() {
138         return new SplitSpeciesBatchRowModel();
139     }
140 }