View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.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.quadrige3.ui.core.dto.referential.BaseReferentialDTO;
27  import fr.ifremer.reefdb.decorator.DecoratorService;
28  import fr.ifremer.reefdb.dto.referential.TaxonDTO;
29  import fr.ifremer.reefdb.dto.referential.TaxonomicLevelDTO;
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 TaxonTableModel extends AbstractReefDbTableModel<TaxonTableRowModel> {
42  
43      private final boolean readOnly;
44  
45      /**
46       * <p>Constructor for TaxonTableModel.</p>
47       *
48       * @param columnModel a {@link org.jdesktop.swingx.table.TableColumnModelExt} object.
49       * @param createNewRowAllowed a boolean.
50       */
51      public TaxonTableModel(final TableColumnModelExt columnModel, boolean createNewRowAllowed) {
52          super(columnModel, createNewRowAllowed, false);
53          readOnly = !createNewRowAllowed;
54      }
55  
56      // name
57      /** Constant <code>NAME</code> */
58      public static final ReefDbColumnIdentifier<TaxonTableRowModel> NAME = ReefDbColumnIdentifier.newId(
59              TaxonTableRowModel.PROPERTY_NAME,
60              n("reefdb.property.name"),
61              n("reefdb.property.name"),
62              String.class,
63              true);
64  
65      // citation
66      /** Constant <code>CITATION</code> */
67      public static final ReefDbColumnIdentifier<TaxonTableRowModel> CITATION = ReefDbColumnIdentifier.newId(
68              TaxonTableRowModel.PROPERTY_CITATION,
69              n("reefdb.property.taxon.citation"),
70              n("reefdb.property.taxon.citation"),
71              BaseReferentialDTO.class);
72  
73      // reference taxon
74      /** Constant <code>REFERENCE_TAXON</code> */
75      public static final ReefDbColumnIdentifier<TaxonTableRowModel> REFERENCE_TAXON = ReefDbColumnIdentifier.newId(
76              TaxonTableRowModel.PROPERTY_REFERENCE_TAXON,
77              n("reefdb.property.taxon.reference"),
78              n("reefdb.property.taxon.reference"),
79              TaxonDTO.class,
80              DecoratorService.WITH_CITATION);
81  
82      // parent taxon
83      /** Constant <code>PARENT</code> */
84      public static final ReefDbColumnIdentifier<TaxonTableRowModel> PARENT = ReefDbColumnIdentifier.newId(
85              TaxonTableRowModel.PROPERTY_PARENT_TAXON,
86              n("reefdb.property.taxon.parent"),
87              n("reefdb.property.taxon.parent"),
88              TaxonDTO.class,
89              DecoratorService.WITH_CITATION,
90              true);
91  
92      // level
93      /** Constant <code>LEVEL</code> */
94      public static final ReefDbColumnIdentifier<TaxonTableRowModel> LEVEL = ReefDbColumnIdentifier.newId(
95              TaxonTableRowModel.PROPERTY_LEVEL,
96              n("reefdb.property.taxon.level"),
97              n("reefdb.property.taxon.level.tip"),
98              TaxonomicLevelDTO.class,
99              true);
100 
101     // comment
102     /** Constant <code>COMMENT</code> */
103     public static final ReefDbColumnIdentifier<TaxonTableRowModel> COMMENT = ReefDbColumnIdentifier.newId(
104             TaxonTableRowModel.PROPERTY_COMMENT,
105             n("reefdb.property.comment"),
106             n("reefdb.property.comment"),
107             String.class);
108 
109     // temporary
110     /** Constant <code>TEMPORARY</code> */
111     public static final ReefDbColumnIdentifier<TaxonTableRowModel> TEMPORARY = ReefDbColumnIdentifier.newId(
112             TaxonTableRowModel.PROPERTY_TEMPORARY,
113             n("reefdb.property.temporary"),
114             n("reefdb.property.temporary"),
115             Boolean.class);
116 
117     // obsolete
118     /** Constant <code>OBSOLETE</code> */
119     public static final ReefDbColumnIdentifier<TaxonTableRowModel> OBSOLETE = ReefDbColumnIdentifier.newId(
120             TaxonTableRowModel.PROPERTY_OBSOLETE,
121             n("reefdb.property.obsolete"),
122             n("reefdb.property.obsolete"),
123             Boolean.class/*,
124             true*/);
125 
126     // virtual
127     /** Constant <code>VIRTUAL</code> */
128     public static final ReefDbColumnIdentifier<TaxonTableRowModel> VIRTUAL = ReefDbColumnIdentifier.newId(
129             TaxonTableRowModel.PROPERTY_VIRTUAL,
130             n("reefdb.property.virtual"),
131             n("reefdb.property.virtual"),
132             Boolean.class);
133 
134     // composites
135     /** Constant <code>COMPOSITES</code> */
136     public static final ReefDbColumnIdentifier<TaxonTableRowModel> COMPOSITES = ReefDbColumnIdentifier.newId(
137             TaxonTableRowModel.PROPERTY_COMPOSITE_TAXONS,
138             n("reefdb.property.taxon.composites"),
139             n("reefdb.property.taxon.composites"),
140             TaxonDTO.class,
141             DecoratorService.COLLECTION_SIZE);
142 
143     // taxref
144     /** Constant <code>TAXREF</code> */
145     public static final ReefDbColumnIdentifier<TaxonTableRowModel> TAXREF = ReefDbColumnIdentifier.newId(
146             TaxonTableRowModel.PROPERTY_TAX_REF,
147             n("reefdb.property.taxon.taxRef"),
148             n("reefdb.property.taxon.taxRef"),
149             String.class);
150 
151     // worms
152     /** Constant <code>WORMS</code> */
153     public static final ReefDbColumnIdentifier<TaxonTableRowModel> WORMS = ReefDbColumnIdentifier.newId(
154             TaxonTableRowModel.PROPERTY_WORMS_REF,
155             n("reefdb.property.taxon.worms"),
156             n("reefdb.property.taxon.worms"),
157             String.class);
158 
159 
160     public static final ReefDbColumnIdentifier<TaxonTableRowModel> CREATION_DATE = ReefDbColumnIdentifier.newReadOnlyId(
161         TaxonTableRowModel.PROPERTY_CREATION_DATE,
162         n("reefdb.property.date.creation"),
163         n("reefdb.property.date.creation"),
164         Date.class);
165 
166     public static final ReefDbColumnIdentifier<TaxonTableRowModel> UPDATE_DATE = ReefDbColumnIdentifier.newReadOnlyId(
167         TaxonTableRowModel.PROPERTY_UPDATE_DATE,
168         n("reefdb.property.date.modification"),
169         n("reefdb.property.date.modification"),
170         Date.class);
171 
172 
173     /** {@inheritDoc} */
174     @Override
175     public TaxonTableRowModel createNewRow() {
176         return new TaxonTableRowModel(readOnly);
177     }
178 
179     /** {@inheritDoc} */
180     @Override
181     public ReefDbColumnIdentifier<TaxonTableRowModel> getFirstColumnEditing() {
182         return NAME;
183     }
184 
185     /** {@inheritDoc} */
186     @Override
187     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<TaxonTableRowModel> propertyName) {
188 
189         if (propertyName == COMPOSITES) {
190             TaxonTableRowModel row = getEntry(rowIndex);
191             return row.sizeCompositeTaxons() > 0;
192         }
193 
194         return super.isCellEditable(rowIndex, columnIndex, propertyName);
195     }
196 
197 }