View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.location.national;
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.LocationDTO;
27  import fr.ifremer.dali.service.StatusFilter;
28  import fr.ifremer.dali.ui.swing.content.manage.filter.element.menu.ApplyFilterUIModel;
29  import fr.ifremer.dali.ui.swing.content.manage.referential.location.menu.LocationMenuUIModel;
30  import fr.ifremer.dali.ui.swing.content.manage.referential.location.table.LocationTableModel;
31  import fr.ifremer.dali.ui.swing.content.manage.referential.location.table.LocationTableRowModel;
32  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
33  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableUIHandler;
34  import fr.ifremer.quadrige3.ui.swing.component.coordinate.CoordinateEditor;
35  import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
36  import org.jdesktop.swingx.table.TableColumnExt;
37  
38  import java.util.List;
39  
40  import static org.nuiton.i18n.I18n.t;
41  
42  /**
43   * Controlleur pour la gestion des lieux au niveau national
44   */
45  public class LocationNationalUIHandler extends AbstractDaliTableUIHandler<LocationTableRowModel, LocationNationalUIModel, LocationNationalUI> {
46  
47      /** {@inheritDoc} */
48      @Override
49      public void beforeInit(LocationNationalUI ui) {
50          super.beforeInit(ui);
51  
52          // create model and register to the JAXX context
53          LocationNationalUIModel model = new LocationNationalUIModel();
54          ui.setContextValue(model);
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      @SuppressWarnings("unchecked")
60      public void afterInit(LocationNationalUI ui) {
61          initUI(ui);
62  
63          // listen to search results
64          ui.getLocationNationalMenuUI().getModel().addPropertyChangeListener(LocationMenuUIModel.PROPERTY_RESULTS,
65                  evt -> getModel().setBeans((List<LocationDTO>) evt.getNewValue()));
66  
67          // listen to 'apply filter' results
68          ui.getLocationNationalMenuUI().getApplyFilterUI().getModel().addPropertyChangeListener(ApplyFilterUIModel.PROPERTY_ELEMENTS,
69                  evt -> getModel().setBeans((List<LocationDTO>) evt.getNewValue()));
70  
71          initTable();
72  
73      }
74  
75      private void initTable() {
76  
77          // Le tableau
78          final SwingTable table = getTable();
79  
80          // id
81          TableColumnExt idCol = addColumn(LocationTableModel.ID);
82          idCol.setSortable(true);
83          idCol.setEditable(false);
84          fixColumnWidth(idCol, 80);
85  
86          // label
87          TableColumnExt identifiantCol = addColumn(LocationTableModel.LABEL);
88          identifiantCol.setSortable(true);
89          identifiantCol.setEditable(false);
90          fixColumnWidth(identifiantCol, 100);
91  
92          // Libelle
93          TableColumnExt libelleCol = addColumn(LocationTableModel.NAME);
94          libelleCol.setSortable(true);
95          libelleCol.setEditable(false);
96  
97          // Bathymetrie
98          TableColumnExt bathymetrieCol = addColumn(LocationTableModel.BATHYMETRIE);
99          bathymetrieCol.setSortable(true);
100         bathymetrieCol.setEditable(false);
101         fixColumnWidth(bathymetrieCol, 100);
102 
103         // Latitude Min
104         TableColumnExt latitudeMinCol = addCoordinateColumnToModel(
105                 CoordinateEditor.CoordinateType.LATITUDE_MIN,
106                 LocationTableModel.LATITUDE_MIN);
107         latitudeMinCol.setSortable(true);
108         latitudeMinCol.setEditable(false);
109         latitudeMinCol.setPreferredWidth(100);
110 
111         // Longitude Min
112         TableColumnExt longitudeMinCol = addCoordinateColumnToModel(
113                 CoordinateEditor.CoordinateType.LONGITUDE_MIN,
114                 LocationTableModel.LONGITUDE_MIN);
115         longitudeMinCol.setSortable(true);
116         longitudeMinCol.setEditable(false);
117         longitudeMinCol.setPreferredWidth(100);
118 
119         // Commentaire
120         addCommentColumn(LocationTableModel.COMMENT, false);
121         TableColumnExt creationDateCol = addDatePickerColumnToModel(LocationTableModel.CREATION_DATE, getConfig().getDateTimeFormat(), false);
122         fixColumnWidth(creationDateCol, 120);
123         TableColumnExt updateDateCol = addDatePickerColumnToModel(LocationTableModel.UPDATE_DATE, getConfig().getDateTimeFormat(), false);
124         fixColumnWidth(updateDateCol, 120);
125 
126         // Port de Rattachement
127         TableColumnExt portRattachementCol = addColumn(LocationTableModel.HARBOUR);
128         portRattachementCol.setSortable(true);
129         portRattachementCol.setEditable(false);
130 
131         // Delta UT Hivers
132         TableColumnExt deltaUTHiverCol = addColumn(LocationTableModel.DELTA_UT_HIVER);
133         deltaUTHiverCol.setSortable(true);
134         deltaUTHiverCol.setEditable(false);
135 
136         // Fiche du lieu
137 //		TableColumnExt ficheLieuCol = addColumnToModel(columnModel, LocationTableModel.FICHE_LIEU);
138 //		ficheLieuCol.setSortable(true);
139 
140         // Changement d heure
141         final TableColumnExt changementHeureCol = addBooleanColumnToModel(LocationTableModel.DAYLIGHT_SAVING_TIME, table);
142         changementHeureCol.setSortable(true);
143         changementHeureCol.setEditable(false);
144 
145         // Latitude Max
146         TableColumnExt latitudeMaxCol = addCoordinateColumnToModel(
147                 CoordinateEditor.CoordinateType.LATITUDE_MAX,
148                 LocationTableModel.LATITUDE_MAX);
149         latitudeMaxCol.setSortable(true);
150         latitudeMaxCol.setEditable(false);
151         latitudeMaxCol.setPreferredWidth(100);
152 
153         // Longitude Max
154         TableColumnExt longitudeMaxCol = addCoordinateColumnToModel(
155                 CoordinateEditor.CoordinateType.LONGITUDE_MAX,
156                 LocationTableModel.LONGITUDE_MAX);
157         longitudeMaxCol.setSortable(true);
158         longitudeMaxCol.setEditable(false);
159         longitudeMaxCol.setPreferredWidth(100);
160 
161         // Positionnement
162         TableColumnExt positioningCol = addFilterableComboDataColumnToModel(
163                 LocationTableModel.POSITIONING_NAME,
164                 getContext().getReferentialService().getPositioningSystems(), false);
165         positioningCol.setSortable(true);
166         positioningCol.setEditable(false);
167         positioningCol.setPreferredWidth(200);
168 
169         TableColumnExt positioningPrecisionCol = addColumn(
170                 LocationTableModel.POSITIONING_PRECISION);
171         positioningPrecisionCol.setEditable(false);
172         positioningPrecisionCol.setPreferredWidth(100);
173 
174         // status
175         TableColumnExt statusCol = addFilterableComboDataColumnToModel(
176             LocationTableModel.STATUS,
177             getContext().getReferentialService().getStatus(StatusFilter.ACTIVE),
178             false);
179         statusCol.setSortable(true);
180         statusCol.setEditable(false);
181 
182         LocationTableModel tableModel = new LocationTableModel(getTable().getColumnModel(), false);
183         table.setModel(tableModel);
184 
185         // Add extraction action
186         addExportToCSVAction(t("dali.property.location"));
187 
188         // Initialisation du tableau
189         initTable(table, true);
190 
191         // Les colonnes optionnelles sont invisibles
192         portRattachementCol.setVisible(false);
193         deltaUTHiverCol.setVisible(false);
194         changementHeureCol.setVisible(false);
195         latitudeMaxCol.setVisible(false);
196         longitudeMaxCol.setVisible(false);
197         positioningCol.setVisible(false);
198         positioningPrecisionCol.setVisible(false);
199 
200         creationDateCol.setVisible(false);
201         updateDateCol.setVisible(false);
202 
203         table.setVisibleRowCount(5);
204     }
205 
206     /** {@inheritDoc} */
207     @Override
208     public AbstractDaliTableModel<LocationTableRowModel> getTableModel() {
209         return (LocationTableModel) getTable().getModel();
210     }
211 
212     /** {@inheritDoc} */
213     @Override
214     public SwingTable getTable() {
215         return getUI().getLocationNationalTable();
216     }
217 
218 }