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