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.SampleCategoryModel;
26  import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry;
27  import fr.ifremer.tutti.type.WeightUnit;
28  import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SelectedCategoryAble;
29  import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport;
30  import fr.ifremer.tutti.ui.swing.content.operation.catches.species.edit.SpeciesBatchRowModel;
31  import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel;
32  
33  import java.util.List;
34  
35  /**
36   * Model of {@link SplitSpeciesBatchUI}.
37   *
38   * @author Tony Chemit - chemit@codelutin.com
39   * @since 0.3
40   */
41  public class SplitSpeciesBatchUIModel
42          extends AbstractTuttiTableUIModel<SpeciesBatchRowModel, SplitSpeciesBatchRowModel, SplitSpeciesBatchUIModel> implements SelectedCategoryAble {
43  
44      private static final long serialVersionUID = 1L;
45  
46      public static final String PROPERTY_CATEGORY = "category";
47  
48      public static final String PROPERTY_SELECTED_CATEGORY = "selectedCategory";
49  
50      public static final String PROPERTY_BATCH_WEIGHT = "batchWeight";
51  
52      public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight";
53  
54      public static final String PROPERTY_SPLIT_MODE = "splitMode";
55  
56      /**
57       * Batch which fires the editor.
58       *
59       * @since 0.3
60       */
61      protected SpeciesBatchRowModel batch;
62  
63      /**
64       * Sample categories.
65       *
66       * @since 0.3
67       */
68      protected List<SampleCategoryModelEntry> category;
69  
70      /**
71       * Selected Sample category.
72       *
73       * @since 0.3
74       */
75      protected SampleCategoryModelEntry selectedCategory;
76  
77      /**
78       * Sample weight of split batches.
79       *
80       * @since 0.3
81       */
82      protected Float sampleWeight;
83  
84      /**
85       * Model of sample categories.
86       *
87       * @since 2.4
88       */
89      protected SampleCategoryModel sampleCategoryModel;
90  
91      /**
92       * Is ui in split mode ?
93       *
94       * @since 2.6
95       */
96      protected boolean splitMode = true;
97  
98      private final SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport;
99  
100     public SplitSpeciesBatchUIModel(SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport,
101                                     SampleCategoryModel sampleCategoryModel) {
102         super(SpeciesBatchRowModel.class, null, null);
103         this.speciesOrBenthosBatchUISupport = speciesOrBenthosBatchUISupport;
104         this.sampleCategoryModel = sampleCategoryModel;
105     }
106 
107     @Override
108     protected SpeciesBatchRowModel newEntity() {
109         return new SpeciesBatchRowModel(getWeightUnit(), sampleCategoryModel);
110     }
111 
112     public SpeciesOrBenthosBatchUISupport getSpeciesOrBenthosBatchUISupport() {
113         return speciesOrBenthosBatchUISupport;
114     }
115 
116     public SpeciesBatchRowModel getBatch() {
117         return batch;
118     }
119 
120     public void setBatch(SpeciesBatchRowModel batch) {
121         Object oldWeight = getBatchWeight();
122 
123         this.batch = batch;
124         firePropertyChange(PROPERTY_BATCH_WEIGHT, oldWeight, getBatchWeight());
125     }
126 
127     public List<SampleCategoryModelEntry> getCategory() {
128         return category;
129     }
130 
131     public void setCategory(List<SampleCategoryModelEntry> category) {
132         Object oldValue = getCategory();
133         this.category = category;
134         firePropertyChange(PROPERTY_CATEGORY, oldValue, category);
135     }
136 
137     public SampleCategoryModelEntry getSelectedCategory() {
138         return selectedCategory;
139     }
140 
141     public void setSelectedCategory(SampleCategoryModelEntry selectedCategory) {
142         Object oldValue = getSelectedCategory();
143         this.selectedCategory = selectedCategory;
144         firePropertyChange(PROPERTY_SELECTED_CATEGORY, oldValue, selectedCategory);
145     }
146 
147     public Float getBatchWeight() {
148         return batch == null ? null : batch.getFinestCategory().getCategoryWeight();
149     }
150 
151     public Float getSampleWeight() {
152         return sampleWeight;
153     }
154 
155     public void setSampleWeight(Float sampleWeight) {
156         Object oldValue = getSampleWeight();
157         this.sampleWeight = sampleWeight;
158         firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight);
159     }
160 
161     public SampleCategoryModel getSampleCategoryModel() {
162         return sampleCategoryModel;
163     }
164 
165     public boolean isSplitMode() {
166         return splitMode;
167     }
168 
169     public void setSplitMode(boolean splitMode) {
170         Object oldValue = isSplitMode();
171         this.splitMode = splitMode;
172         firePropertyChange(PROPERTY_SPLIT_MODE, oldValue, splitMode);
173     }
174 
175     public WeightUnit getWeightUnit() {
176         return speciesOrBenthosBatchUISupport.getWeightUnit();
177     }
178 }