View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.program.locations;
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  
27  import fr.ifremer.reefdb.dto.referential.DepartmentDTO;
28  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableModel;
29  import fr.ifremer.reefdb.ui.swing.util.table.ReefDbColumnIdentifier;
30  import org.jdesktop.swingx.table.TableColumnModelExt;
31  
32  import java.time.LocalDate;
33  
34  import static org.nuiton.i18n.I18n.n;
35  
36  /**
37   * Le modele pour le tableau des programmes.
38   */
39  public class LocationsTableModel extends AbstractReefDbTableModel<LocationsTableRowModel> {
40  
41  	/**
42  	 * Identifiant pour la colonne code = location id
43  	 */
44      public static final ReefDbColumnIdentifier<LocationsTableRowModel> CODE = ReefDbColumnIdentifier.newId(
45      		LocationsTableRowModel.PROPERTY_ID,
46              n("reefdb.property.code"),
47              n("reefdb.program.location.code.tip"),
48              Integer.class);
49  
50  	/**
51  	 * Identifiant pour la colonne label.
52  	 */
53      public static final ReefDbColumnIdentifier<LocationsTableRowModel> LABEL = ReefDbColumnIdentifier.newId(
54      		LocationsTableRowModel.PROPERTY_LABEL,
55              n("reefdb.property.label"),
56              n("reefdb.program.location.label.tip"),
57              String.class);
58      
59      /**
60       * Identifiant pour la colonne name.
61       */
62      public static final ReefDbColumnIdentifier<LocationsTableRowModel> NAME = ReefDbColumnIdentifier.newId(
63      		LocationsTableRowModel.PROPERTY_NAME,
64              n("reefdb.program.location.name.short"),
65              n("reefdb.program.location.name.tip"),
66              String.class);
67  
68      /**
69       * Identifiant pour la colonne date debut.
70       */
71      public static final ReefDbColumnIdentifier<LocationsTableRowModel> START_DATE = ReefDbColumnIdentifier.newId(
72      		LocationsTableRowModel.PROPERTY_START_DATE,
73              n("reefdb.program.location.startDate.short"),
74              n("reefdb.program.location.startDate.tip"),
75  			LocalDate.class);
76  
77      /**
78       * Identifiant pour la colonne date fin.
79       */
80      public static final ReefDbColumnIdentifier<LocationsTableRowModel> END_DATE = ReefDbColumnIdentifier.newId(
81      		LocationsTableRowModel.PROPERTY_END_DATE,
82              n("reefdb.program.location.endDate.short"),
83              n("reefdb.program.location.endDate.tip"),
84  			LocalDate.class);
85  
86      /**
87       * Identifiant pour la colonne preleveur.
88       */
89      public static final ReefDbColumnIdentifier<LocationsTableRowModel> PRELEVEUR = ReefDbColumnIdentifier.newId(
90      		LocationsTableRowModel.PROPERTY_DEPARTMENT,
91              n("reefdb.program.location.department"),
92              n("reefdb.program.location.department.tip"),
93              DepartmentDTO.class);
94  
95  	/**
96  	 * Constructor.
97  	 *
98  	 * @param columnModel Le modele pour les colonnes
99  	 */
100 	public LocationsTableModel(final TableColumnModelExt columnModel) {
101 		super(columnModel, false, false);
102 	}
103 
104 	/** {@inheritDoc} */
105 	@Override
106 	public LocationsTableRowModel createNewRow() {
107 		return new LocationsTableRowModel();
108 	}
109 
110 	/** {@inheritDoc} */
111 	@Override
112 	public ReefDbColumnIdentifier<LocationsTableRowModel> getFirstColumnEditing() {
113 		return CODE;
114 	}
115 
116 	@Override
117 	public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<LocationsTableRowModel> propertyName) {
118 
119 		if (propertyName == PRELEVEUR) {
120 			LocationsTableRowModel rowModel = getEntry(rowIndex);
121 			return rowModel.getStartDate() != null && rowModel.getEndDate() != null;
122 		}
123 
124 		return super.isCellEditable(rowIndex, columnIndex, propertyName);
125 	}
126 }