View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.taxongroup.table;
2   
3   /*
4    * #%L
5    * Reef DB :: 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.reefdb.decorator.DecoratorService;
27  import fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
28  import fr.ifremer.reefdb.dto.referential.TaxonDTO;
29  import fr.ifremer.reefdb.dto.referential.TaxonGroupDTO;
30  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableModel;
31  import fr.ifremer.reefdb.ui.swing.util.table.ReefDbColumnIdentifier;
32  import org.jdesktop.swingx.table.TableColumnModelExt;
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 AbstractReefDbTableModel<TaxonGroupTableRowModel> {
42  
43      /** Constant <code>PARENT</code> */
44      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> PARENT = ReefDbColumnIdentifier.newId(
45              TaxonGroupTableRowModel.PROPERTY_PARENT_TAXON_GROUP,
46              n("reefdb.property.taxonGroup.parent"),
47              n("reefdb.property.taxonGroup.parent"),
48              TaxonGroupDTO.class);
49  
50      /** Constant <code>LABEL</code> */
51      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> LABEL = ReefDbColumnIdentifier.newId(
52              TaxonGroupTableRowModel.PROPERTY_LABEL,
53              n("reefdb.property.label"),
54              n("reefdb.property.label"),
55              String.class);
56  
57      /** Constant <code>NAME</code> */
58      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> NAME = ReefDbColumnIdentifier.newId(
59              TaxonGroupTableRowModel.PROPERTY_NAME,
60              n("reefdb.property.name"),
61              n("reefdb.property.name"),
62              String.class,
63              true);
64  
65      /** Constant <code>STATUS</code> */
66      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> STATUS = ReefDbColumnIdentifier.newId(
67              TaxonGroupTableRowModel.PROPERTY_STATUS,
68              n("reefdb.property.status"),
69              n("reefdb.property.status"),
70              StatusDTO.class,
71              true);
72  
73      /** Constant <code>COMMENT</code> */
74      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> COMMENT = ReefDbColumnIdentifier.newId(
75              TaxonGroupTableRowModel.PROPERTY_COMMENT,
76              n("reefdb.property.comment"),
77              n("reefdb.property.comment"),
78              String.class);
79  
80      /** Constant <code>TYPE</code> */
81      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> TYPE = ReefDbColumnIdentifier.newId(
82              TaxonGroupTableRowModel.PROPERTY_TYPE,
83              n("reefdb.property.taxonGroup.type"),
84              n("reefdb.property.taxonGroup.type.tip"),
85              String.class);
86  
87      /** Constant <code>TAXONS</code> */
88      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> TAXONS = ReefDbColumnIdentifier.newId(
89              TaxonGroupTableRowModel.PROPERTY_TAXONS,
90              n("reefdb.property.taxonGroup.taxons"),
91              n("reefdb.property.taxonGroup.taxons"),
92              TaxonDTO.class,
93              DecoratorService.COLLECTION_SIZE);
94  
95  
96      public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> CREATION_DATE = ReefDbColumnIdentifier.newReadOnlyId(
97          TaxonGroupTableRowModel.PROPERTY_CREATION_DATE,
98          n("reefdb.property.date.creation"),
99          n("reefdb.property.date.creation"),
100         Date.class);
101 
102     public static final ReefDbColumnIdentifier<TaxonGroupTableRowModel> UPDATE_DATE = ReefDbColumnIdentifier.newReadOnlyId(
103         TaxonGroupTableRowModel.PROPERTY_UPDATE_DATE,
104         n("reefdb.property.date.modification"),
105         n("reefdb.property.date.modification"),
106         Date.class);
107 
108 
109 
110     final boolean readOnly;
111 
112     /**
113      * <p>Constructor for TaxonGroupTableModel.</p>
114      *
115      * @param columnModel a {@link org.jdesktop.swingx.table.TableColumnModelExt} object.
116      * @param readOnly a boolean.
117      */
118     public TaxonGroupTableModel(final TableColumnModelExt columnModel, boolean readOnly) {
119         super(columnModel, !readOnly, false);
120         this.readOnly = readOnly;
121     }
122 
123     /** {@inheritDoc} */
124     @Override
125     public TaxonGroupTableRowModel createNewRow() {
126         return new TaxonGroupTableRowModel(readOnly);
127     }
128 
129     /** {@inheritDoc} */
130     @Override
131     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<TaxonGroupTableRowModel> propertyName) {
132 
133         if (propertyName == TAXONS && readOnly) {
134             TaxonGroupTableRowModel row = getEntry(rowIndex);
135             return row.sizeTaxons() > 0;
136         }
137 
138         return super.isCellEditable(rowIndex, columnIndex, propertyName);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public ReefDbColumnIdentifier<TaxonGroupTableRowModel> getFirstColumnEditing() {
144         return NAME;
145     }
146 }