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