View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.parameter.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.pmfm.ParameterGroupDTO;
28  import fr.ifremer.dali.dto.referential.pmfm.QualitativeValueDTO;
29  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
30  import fr.ifremer.dali.ui.swing.util.table.DaliColumnIdentifier;
31  import fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
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   * <p>ParameterTableModel class.</p>
40   *
41   * @author Antoine
42   */
43  public class ParameterTableModel extends AbstractDaliTableModel<ParameterTableRowModel> {
44  
45  	
46  	/**
47  	 * <p>Constructor for ParameterTableModel.</p>
48  	 *
49  	 * @param createNewRowAllowed a boolean.
50  	 */
51  	public ParameterTableModel(final SwingTableColumnModel columnModel, boolean createNewRowAllowed) {
52  		super(columnModel, createNewRowAllowed, false);
53  	}
54  	
55  	/** Constant <code>CODE</code> */
56  	public static final DaliColumnIdentifier<ParameterTableRowModel> CODE = DaliColumnIdentifier.newId(
57  			ParameterTableRowModel.PROPERTY_TRANSCRIBED_CODE, // use transcribed code (Mantis #47330)
58  			n("dali.property.code"),
59  			n("dali.property.code"),
60  			String.class,
61  			true);
62  	
63  	/** Constant <code>NAME</code> */
64  	public static final DaliColumnIdentifier<ParameterTableRowModel> NAME = DaliColumnIdentifier.newId(
65  			ParameterTableRowModel.PROPERTY_NAME,
66  			n("dali.property.name"),
67  			n("dali.property.name"),
68  			String.class,
69  			true);    
70      
71  	/** Constant <code>DESCRIPTION</code> */
72  	public static final DaliColumnIdentifier<ParameterTableRowModel> DESCRIPTION = DaliColumnIdentifier.newId(
73  			ParameterTableRowModel.PROPERTY_DESCRIPTION,
74  			n("dali.property.description"),
75  			n("dali.property.description"),
76  			String.class);
77  	
78  	/** Constant <code>STATUS</code> */
79  	public static final DaliColumnIdentifier<ParameterTableRowModel> STATUS = DaliColumnIdentifier.newId(
80  			ParameterTableRowModel.PROPERTY_STATUS,
81  			n("dali.property.status"),
82  			n("dali.property.status"),
83  			StatusDTO.class,
84  			true);
85  	
86  	/** Constant <code>ASSOCIATED_QUALITATIVE_VALUE</code> */
87  	public static final DaliColumnIdentifier<ParameterTableRowModel> ASSOCIATED_QUALITATIVE_VALUE = DaliColumnIdentifier.newId(
88  			ParameterTableRowModel.PROPERTY_QUALITATIVE_VALUES,
89  			n("dali.property.pmfm.parameter.associatedQualitativeValue"),
90  			n("dali.property.pmfm.parameter.associatedQualitativeValue"),
91  			QualitativeValueDTO.class,
92  			DecoratorService.COLLECTION_SIZE);
93  	
94  	/** Constant <code>PARAMETER_GROUP</code> */
95  	public static final DaliColumnIdentifier<ParameterTableRowModel> PARAMETER_GROUP = DaliColumnIdentifier.newId(
96  			ParameterTableRowModel.PROPERTY_PARAMETER_GROUP,
97  			n("dali.property.pmfm.parameter.parameterGroup"),
98  			n("dali.property.pmfm.parameter.parameterGroup"),
99  			ParameterGroupDTO.class,
100 			true);
101 	
102 	/** Constant <code>IS_QUALITATIVE</code> */
103 	public static final DaliColumnIdentifier<ParameterTableRowModel> IS_QUALITATIVE = DaliColumnIdentifier.newId(
104 			ParameterTableRowModel.PROPERTY_QUALITATIVE,
105 			n("dali.property.pmfm.parameter.qualitative"),
106 			n("dali.property.pmfm.parameter.qualitative"),
107 			Boolean.class);
108 	
109 	/** Constant <code>IS_CALCULATED</code> */
110 	public static final DaliColumnIdentifier<ParameterTableRowModel> IS_CALCULATED = DaliColumnIdentifier.newId(
111 			ParameterTableRowModel.PROPERTY_CALCULATED,
112 			n("dali.property.pmfm.parameter.calculated"),
113 			n("dali.property.pmfm.parameter.calculated"),
114 			Boolean.class);
115 	
116 	/** Constant <code>IS_TAXONOMIC</code> */
117 	public static final DaliColumnIdentifier<ParameterTableRowModel> IS_TAXONOMIC = DaliColumnIdentifier.newId(
118 			ParameterTableRowModel.PROPERTY_TAXONOMIC,
119 			n("dali.property.pmfm.parameter.taxonomic"),
120 			n("dali.property.pmfm.parameter.taxonomic"),
121 			Boolean.class);
122 
123 	public static final DaliColumnIdentifier<ParameterTableRowModel> COMMENT = DaliColumnIdentifier.newId(
124 		ParameterTableRowModel.PROPERTY_COMMENT,
125 		n("dali.property.comment"),
126 		n("dali.property.comment"),
127 		String.class,
128 		false);
129 
130 	public static final DaliColumnIdentifier<ParameterTableRowModel> CREATION_DATE = DaliColumnIdentifier.newReadOnlyId(
131 		ParameterTableRowModel.PROPERTY_CREATION_DATE,
132 		n("dali.property.date.creation"),
133 		n("dali.property.date.creation"),
134 		Date.class);
135 
136 	public static final DaliColumnIdentifier<ParameterTableRowModel> UPDATE_DATE = DaliColumnIdentifier.newReadOnlyId(
137 		ParameterTableRowModel.PROPERTY_UPDATE_DATE,
138 		n("dali.property.date.modification"),
139 		n("dali.property.date.modification"),
140 		Date.class);
141 
142 
143 	/** {@inheritDoc} */
144 	@Override
145 	public ParameterTableRowModel createNewRow() {
146 		return new ParameterTableRowModel();
147 	}
148 
149 	/** {@inheritDoc} */
150 	@Override
151 	public DaliColumnIdentifier<ParameterTableRowModel> getFirstColumnEditing() {
152 		return CODE;
153 	}
154 
155 	/** {@inheritDoc} */
156 	@Override
157 	public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<ParameterTableRowModel> propertyName) {
158 		boolean editable = super.isCellEditable(rowIndex, columnIndex, propertyName);
159 
160 		if (editable && ASSOCIATED_QUALITATIVE_VALUE.equals(propertyName)) {
161 
162 			ParameterTableRowModel rowModel = getEntry(rowIndex);
163 			editable = rowModel.isQualitative();
164 		}
165 
166 		return editable;
167 	}
168 }