View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches.marinelitter;
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 com.google.common.collect.Multimap;
26  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
27  import fr.ifremer.tutti.type.WeightUnit;
28  import fr.ifremer.tutti.ui.swing.content.operation.catches.AbstractTuttiBatchUIModel;
29  import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
30  import fr.ifremer.tutti.ui.swing.util.computable.ComputableData;
31  import org.apache.commons.collections4.CollectionUtils;
32  import org.nuiton.jaxx.application.swing.tab.TabContentModel;
33  
34  import static org.nuiton.i18n.I18n.n;
35  
36  /**
37   * @author Tony Chemit - chemit@codelutin.com
38   * @since 0.2
39   */
40  public class MarineLitterBatchUIModel extends AbstractTuttiBatchUIModel<MarineLitterBatchRowModel, MarineLitterBatchUIModel>
41          implements TabContentModel {
42  
43      private static final long serialVersionUID = 1L;
44  
45      public static final String PROPERTY_REMOVE_BATCH_ENABLED = "removeBatchEnabled";
46  
47      /**
48       * Can user remove a selected marineLitter batch?
49       *
50       * @since 1.3
51       */
52      protected boolean removeBatchEnabled;
53  
54      private final WeightUnit weightUnit;
55  
56      public MarineLitterBatchUIModel(EditCatchesUIModel catchesUIModel, WeightUnit weightUnit) {
57          super(catchesUIModel, EditCatchesUIModel.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT);
58          this.weightUnit = weightUnit;
59      }
60  
61      public WeightUnit getWeightUnit() {
62          return weightUnit;
63      }
64  
65      public ComputableData<Float> getMarineLitterTotalComputedOrNotWeight() {
66          return catchesUIModel.getMarineLitterTotalComputedOrNotWeight();
67      }
68  
69      public Float getMarineLitterTotalWeight() {
70          return catchesUIModel.getMarineLitterTotalWeight();
71      }
72  
73      public void setMarineLitterTotalWeight(Float marineLitterTotalWeight) {
74          catchesUIModel.setMarineLitterTotalWeight(marineLitterTotalWeight);
75      }
76  
77      public Float getMarineLitterTotalComputedWeight() {
78          return catchesUIModel.getMarineLitterTotalComputedWeight();
79      }
80  
81      public void setMarineLitterTotalComputedWeight(Float marineLitterTotalWeight) {
82          catchesUIModel.setMarineLitterTotalComputedWeight(marineLitterTotalWeight);
83      }
84  
85      public boolean isRemoveBatchEnabled() {
86          return removeBatchEnabled;
87      }
88  
89      public void setRemoveBatchEnabled(boolean removeBatchEnabled) {
90          this.removeBatchEnabled = removeBatchEnabled;
91          firePropertyChange(PROPERTY_REMOVE_BATCH_ENABLED, null, removeBatchEnabled);
92      }
93  
94      public Multimap<CaracteristicQualitativeValue, CaracteristicQualitativeValue> getMarineLitterCategoriesUsed() {
95          return catchesUIModel.getMarineLitterCategoriesUsed();
96      }
97  
98      //------------------------------------------------------------------------//
99      //-- TabContentModel                                                    --//
100     //------------------------------------------------------------------------//
101 
102     @Override
103     public boolean isEmpty() {
104         boolean result = getMarineLitterTotalWeight() == null;
105         if (result && CollectionUtils.isNotEmpty(getRows())) {
106 
107             // check if every line is not valid
108             for (MarineLitterBatchRowModel row : rows) {
109                 if (row.isValid()) {
110 
111                     // found a valid row so not empty
112                     result = false;
113                     break;
114                 }
115             }
116         }
117         return result;
118     }
119 
120     @Override
121     public String getTitle() {
122         return n("tutti.label.tab.marineLitter");
123     }
124 
125     @Override
126     public String getIcon() {
127         return null;
128     }
129 
130     @Override
131     public boolean isCloseable() {
132         return false;
133     }
134 }