View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.program.programs;
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.ui.swing.util.table.AbstractReefDbTableModel;
28  import fr.ifremer.reefdb.ui.swing.util.table.ReefDbColumnIdentifier;
29  import org.jdesktop.swingx.table.TableColumnModelExt;
30  
31  import java.util.Date;
32  
33  import static org.nuiton.i18n.I18n.n;
34  
35  /**
36   * Le modele pour le tableau des programmes.
37   */
38  public class ProgramsTableModel extends AbstractReefDbTableModel<ProgramsTableRowModel> {
39  
40  	/**
41  	 * Identifiant pour la colonne libelle.
42  	 */
43      public static final ReefDbColumnIdentifier<ProgramsTableRowModel> NAME = ReefDbColumnIdentifier.newId(
44      		ProgramsTableRowModel.PROPERTY_NAME,
45              n("reefdb.property.name"),
46              n("reefdb.program.program.name.tip"),
47              String.class,
48              true);
49      
50      /**
51       * Identifiant pour la colonne description.
52       */
53      public static final ReefDbColumnIdentifier<ProgramsTableRowModel> DESCRIPTION = ReefDbColumnIdentifier.newId(
54      		ProgramsTableRowModel.PROPERTY_DESCRIPTION,
55              n("reefdb.property.description"),
56              n("reefdb.program.program.description.tip"),
57              String.class,
58              true);
59  
60      /**
61       * Identifiant pour la colonne code.
62       */
63      public static final ReefDbColumnIdentifier<ProgramsTableRowModel> CODE = ReefDbColumnIdentifier.newId(
64      		ProgramsTableRowModel.PROPERTY_CODE,
65              n("reefdb.property.code"),
66              n("reefdb.program.program.code.tip"),
67              String.class,
68              true);
69  
70  	public static final ReefDbColumnIdentifier<ProgramsTableRowModel> DEPARTMENT_HERMETIC = ReefDbColumnIdentifier.newId(
71  			ProgramsTableRowModel.PROPERTY_DEPARTMENT_HERMETIC,
72  			n("reefdb.property.departmentHermetic"),
73  			n("reefdb.program.program.departmentHermetic.tip"),
74  			Boolean.class,
75  			true);
76  
77  	/**
78       * Identifiant pour la colonne local.
79       */
80      public static final ReefDbColumnIdentifier<ProgramsTableRowModel> STATUS = ReefDbColumnIdentifier.newId(
81      		ProgramsTableRowModel.PROPERTY_STATUS,
82              n("reefdb.property.referential.local"),
83              n("reefdb.program.program.local.tip"),
84              Boolean.class);
85  
86  	public static final ReefDbColumnIdentifier<ProgramsTableRowModel> COMMENT = ReefDbColumnIdentifier.newId(
87  		ProgramsTableRowModel.PROPERTY_COMMENT,
88  		n("reefdb.property.comment"),
89  		n("reefdb.property.comment"),
90  		String.class,
91  		false);
92  
93  	public static final ReefDbColumnIdentifier<ProgramsTableRowModel> CREATION_DATE = ReefDbColumnIdentifier.newReadOnlyId(
94  		ProgramsTableRowModel.PROPERTY_CREATION_DATE,
95  		n("reefdb.property.date.creation"),
96  		n("reefdb.property.date.creation"),
97  		Date.class);
98  
99  	public static final ReefDbColumnIdentifier<ProgramsTableRowModel> UPDATE_DATE = ReefDbColumnIdentifier.newReadOnlyId(
100 		ProgramsTableRowModel.PROPERTY_UPDATE_DATE,
101 		n("reefdb.property.date.modification"),
102 		n("reefdb.property.date.modification"),
103 		Date.class);
104 
105 
106 
107 	/**
108 	 * Constructor.
109 	 *
110 	 * @param columnModel Le modele pour les colonnes
111 	 */
112 	public ProgramsTableModel(final TableColumnModelExt columnModel) {
113 		super(columnModel, true, false);
114     }
115 
116 	/** {@inheritDoc} */
117 	@Override
118 	public ProgramsTableRowModel createNewRow() {
119 		return new ProgramsTableRowModel();
120 	}
121 
122 	/** {@inheritDoc} */
123 	@Override
124 	public ReefDbColumnIdentifier<ProgramsTableRowModel> getFirstColumnEditing() {
125 		return NAME;
126 	}
127 
128     @Override
129     public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<ProgramsTableRowModel> propertyName) {
130 
131         if (DEPARTMENT_HERMETIC == propertyName) {
132             ProgramsTableRowModel rowModel = getEntry(rowIndex);
133             return rowModel.isEditable() && !rowModel.isLocal();
134         } else if (DESCRIPTION == propertyName) {
135 			return true;
136 		}
137 
138         return super.isCellEditable(rowIndex, columnIndex, propertyName);
139     }
140 }