View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.taxongroup.table;
2   
3   /*
4    * #%L
5    * Dali :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.dali.decorator.DecoratorService;
27  import fr.ifremer.dali.dto.referential.TaxonDTO;
28  import fr.ifremer.dali.dto.referential.TaxonGroupDTO;
29  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
30  import fr.ifremer.dali.ui.swing.util.table.DaliColumnIdentifier;
31  import fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
32  import fr.ifremer.quadrige3.ui.swing.table.SwingTableColumnModel;
33  
34  import java.util.Date;
35  
36  import static org.nuiton.i18n.I18n.n;
37  
38  /**
39   * Model.
40   */
41  public class TaxonGroupTableModel extends AbstractDaliTableModel<TaxonGroupTableRowModel> {
42  
43      /** Constant <code>PARENT</code> */
44      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> PARENT = DaliColumnIdentifier.newId(
45              TaxonGroupTableRowModel.PROPERTY_PARENT_TAXON_GROUP,
46              n("dali.property.taxonGroup.parent"),
47              n("dali.property.taxonGroup.parent"),
48              TaxonGroupDTO.class);
49  
50      /** Constant <code>LABEL</code> */
51      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> LABEL = DaliColumnIdentifier.newId(
52              TaxonGroupTableRowModel.PROPERTY_LABEL,
53              n("dali.property.label"),
54              n("dali.property.label"),
55              String.class);
56  
57      /** Constant <code>NAME</code> */
58      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> NAME = DaliColumnIdentifier.newId(
59              TaxonGroupTableRowModel.PROPERTY_NAME,
60              n("dali.property.name"),
61              n("dali.property.name"),
62              String.class,
63              true);
64  
65      /** Constant <code>STATUS</code> */
66      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> STATUS = DaliColumnIdentifier.newId(
67              TaxonGroupTableRowModel.PROPERTY_STATUS,
68              n("dali.property.status"),
69              n("dali.property.status"),
70              StatusDTO.class,
71              true);
72  
73      /** Constant <code>COMMENT</code> */
74      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> COMMENT = DaliColumnIdentifier.newId(
75              TaxonGroupTableRowModel.PROPERTY_COMMENT,
76              n("dali.property.comment"),
77              n("dali.property.comment"),
78              String.class);
79  
80      /** Constant <code>TYPE</code> */
81      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> TYPE = DaliColumnIdentifier.newId(
82              TaxonGroupTableRowModel.PROPERTY_TYPE,
83              n("dali.property.taxonGroup.type"),
84              n("dali.property.taxonGroup.type.tip"),
85              String.class);
86  
87      /** Constant <code>TAXONS</code> */
88      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> TAXONS = DaliColumnIdentifier.newId(
89              TaxonGroupTableRowModel.PROPERTY_TAXONS,
90              n("dali.property.taxonGroup.taxons"),
91              n("dali.property.taxonGroup.taxons"),
92              TaxonDTO.class,
93              DecoratorService.COLLECTION_SIZE);
94  
95      public static final DaliColumnIdentifier<TaxonGroupTableRowModel> CREATION_DATE = DaliColumnIdentifier.newReadOnlyId(
96          TaxonGroupTableRowModel.PROPERTY_CREATION_DATE,
97          n("dali.property.date.creation"),
98          n("dali.property.date.creation"),
99          Date.class);
100 
101     public static final DaliColumnIdentifier<TaxonGroupTableRowModel> UPDATE_DATE = DaliColumnIdentifier.newReadOnlyId(
102         TaxonGroupTableRowModel.PROPERTY_UPDATE_DATE,
103         n("dali.property.date.modification"),
104         n("dali.property.date.modification"),
105         Date.class);
106 
107 
108     final boolean readOnly;
109 
110     /**
111      * <p>Constructor for TaxonGroupTableModel.</p>
112      *
113      * @param readOnly a boolean.
114      */
115     public TaxonGroupTableModel(final SwingTableColumnModel columnModel, boolean readOnly) {
116         super(columnModel, !readOnly, false);
117         this.readOnly = readOnly;
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     public TaxonGroupTableRowModel createNewRow() {
123         return new TaxonGroupTableRowModel(readOnly);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<TaxonGroupTableRowModel> propertyName) {
129 
130         if (propertyName == TAXONS && readOnly) {
131             TaxonGroupTableRowModel row = getEntry(rowIndex);
132             return row.sizeTaxons() > 0;
133         }
134 
135         return super.isCellEditable(rowIndex, columnIndex, propertyName);
136     }
137 
138     /** {@inheritDoc} */
139     @Override
140     public DaliColumnIdentifier<TaxonGroupTableRowModel> getFirstColumnEditing() {
141         return NAME;
142     }
143 }