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 fr.ifremer.tutti.type.WeightUnit;
26  import org.jdesktop.swingx.table.TableColumnModelExt;
27  import org.nuiton.jaxx.application.swing.table.AbstractApplicationTableModel;
28  import org.nuiton.jaxx.application.swing.table.ColumnIdentifier;
29  
30  import static org.nuiton.i18n.I18n.n;
31  
32  /**
33   * @author Tony Chemit - chemit@codelutin.com
34   * @since 0.2
35   */
36  public class MarineLitterBatchTableModel extends AbstractApplicationTableModel<MarineLitterBatchRowModel> {
37  
38      private static final long serialVersionUID = 1L;
39  
40      public static final ColumnIdentifier<MarineLitterBatchRowModel> ID = ColumnIdentifier.newId(
41              MarineLitterBatchRowModel.PROPERTY_ID,
42              n("tutti.editMarineLitterBatch.table.header.id"),
43              n("tutti.editMarineLitterBatch.table.header.id.tip"));
44  
45      public static final ColumnIdentifier<MarineLitterBatchRowModel> MACRO_WASTE_CATEGORY = ColumnIdentifier.newId(
46              MarineLitterBatchRowModel.PROPERTY_MARINE_LITTER_CATEGORY,
47              n("tutti.editMarineLitterBatch.table.header.marineLitterCategory"),
48              n("tutti.editMarineLitterBatch.table.header.marineLitterCategory.tip"));
49  
50      public static final ColumnIdentifier<MarineLitterBatchRowModel> MACRO_WASTE_SIZE_CATEGORY = ColumnIdentifier.newId(
51              MarineLitterBatchRowModel.PROPERTY_MARINE_LITTER_SIZE_CATEGORY,
52              n("tutti.editMarineLitterBatch.table.header.marineLitterSizeCategory"),
53              n("tutti.editMarineLitterBatch.table.header.marineLitterSizeCategory.tip"));
54  
55      public static final ColumnIdentifier<MarineLitterBatchRowModel> NUMBER = ColumnIdentifier.newId(
56              MarineLitterBatchRowModel.PROPERTY_NUMBER,
57              n("tutti.editMarineLitterBatch.table.header.number"),
58              n("tutti.editMarineLitterBatch.table.header.number.tip"));
59  
60      public static final ColumnIdentifier<MarineLitterBatchRowModel> WEIGHT = ColumnIdentifier.newId(
61              MarineLitterBatchRowModel.PROPERTY_WEIGHT,
62              n("tutti.editMarineLitterBatch.table.header.weight"),
63              n("tutti.editMarineLitterBatch.table.header.weight.tip"));
64  
65      public static final ColumnIdentifier<MarineLitterBatchRowModel> COMMENT = ColumnIdentifier.newId(
66              MarineLitterBatchRowModel.PROPERTY_COMMENT,
67              n("tutti.editMarineLitterBatch.table.header.comment"),
68              n("tutti.editMarineLitterBatch.table.header.comment.tip"));
69  
70      public static final ColumnIdentifier<MarineLitterBatchRowModel> ATTACHMENT = ColumnIdentifier.newReadOnlyId(
71              MarineLitterBatchRowModel.PROPERTY_ATTACHMENT,
72              n("tutti.editMarineLitterBatch.table.header.file"),
73              n("tutti.editMarineLitterBatch.table.header.file.tip"));
74  
75      /**
76       * Weight unit.
77       *
78       * @since 2.5
79       */
80      protected final WeightUnit weightUnit;
81  
82      public MarineLitterBatchTableModel(WeightUnit weightUnit,
83                                         TableColumnModelExt columnModel) {
84          super(columnModel, false, false);
85          this.weightUnit = weightUnit;
86  
87          setNoneEditableCols(ID, MACRO_WASTE_CATEGORY, MACRO_WASTE_SIZE_CATEGORY);
88      }
89  
90      @Override
91      public MarineLitterBatchRowModel createNewRow() {
92          MarineLitterBatchRowModel result =
93                  new MarineLitterBatchRowModel(weightUnit);
94  
95          // by default empty row is not valid
96          result.setValid(false);
97          return result;
98      }
99  }