1 package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
37
38
39
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
58
59
60
61 protected SpeciesBatchRowModel batch;
62
63
64
65
66
67
68 protected List<SampleCategoryModelEntry> category;
69
70
71
72
73
74
75 protected SampleCategoryModelEntry selectedCategory;
76
77
78
79
80
81
82 protected Float sampleWeight;
83
84
85
86
87
88
89 protected SampleCategoryModel sampleCategoryModel;
90
91
92
93
94
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 }