View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.samplingequipment.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.SamplingEquipmentDTO;
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.samplingequipment.menu.SamplingEquipmentsMenuUIModel;
30  import fr.ifremer.dali.ui.swing.content.manage.referential.samplingequipment.table.SamplingEquipmentsTableModel;
31  import fr.ifremer.dali.ui.swing.content.manage.referential.samplingequipment.table.SamplingEquipmentsTableRowModel;
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.table.SwingTable;
35  import org.jdesktop.swingx.table.TableColumnExt;
36  
37  import java.util.List;
38  
39  import static org.nuiton.i18n.I18n.t;
40  
41  /**
42   * Controlleur pour la gestion des enginsPrelevement au niveau national
43   */
44  public class SamplingEquipmentsNationalUIHandler extends
45          AbstractDaliTableUIHandler<SamplingEquipmentsTableRowModel, SamplingEquipmentsNationalUIModel, SamplingEquipmentsNationalUI> {
46  
47      /** {@inheritDoc} */
48      @Override
49      public void beforeInit(SamplingEquipmentsNationalUI ui) {
50          super.beforeInit(ui);
51  
52          // create model and register to the JAXX context
53          SamplingEquipmentsNationalUIModel model = new SamplingEquipmentsNationalUIModel();
54          ui.setContextValue(model);
55  
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      @SuppressWarnings("unchecked")
61      public void afterInit(SamplingEquipmentsNationalUI ui) {
62          initUI(ui);
63  
64          // init listener on found samplingEquipments
65          ui.getSamplingEquipmentsNationalMenuUI().getModel().addPropertyChangeListener(SamplingEquipmentsMenuUIModel.PROPERTY_RESULTS, evt -> {
66              if (evt.getNewValue() != null) {
67                  getModel().setBeans((List<SamplingEquipmentDTO>) evt.getNewValue());
68              }
69          });
70  
71          // listen to 'apply filter' results
72          ui.getSamplingEquipmentsNationalMenuUI().getApplyFilterUI().getModel().addPropertyChangeListener(ApplyFilterUIModel.PROPERTY_ELEMENTS,
73                  evt -> getModel().setBeans((List<SamplingEquipmentDTO>) evt.getNewValue()));
74  
75          initTable();
76  
77      }
78  
79      private void initTable() {
80  
81          // Le tableau
82          final SwingTable table = getTable();
83  
84          // mnemonic
85          TableColumnExt mnemonicCol = addColumn(SamplingEquipmentsTableModel.NAME);
86          mnemonicCol.setSortable(true);
87          mnemonicCol.setEditable(false);
88  
89          // description
90          TableColumnExt descriptionCol = addColumn(SamplingEquipmentsTableModel.DESCRIPTION);
91          descriptionCol.setSortable(true);
92          descriptionCol.setEditable(false);
93  
94          // size
95          TableColumnExt sizeCol = addColumn(SamplingEquipmentsTableModel.SIZE);
96          sizeCol.setSortable(true);
97          sizeCol.setEditable(false);
98  
99          // unit
100         TableColumnExt unitCol = addFilterableComboDataColumnToModel(
101                 SamplingEquipmentsTableModel.UNIT,
102                 getContext().getReferentialService().getUnits(StatusFilter.ACTIVE),
103                 false);
104         unitCol.setSortable(true);
105         unitCol.setEditable(false);
106 
107         // Comment, creation and update dates
108         addCommentColumn(SamplingEquipmentsTableModel.COMMENT, false);
109         TableColumnExt creationDateCol = addDatePickerColumnToModel(SamplingEquipmentsTableModel.CREATION_DATE, getConfig().getDateTimeFormat(), false);
110         fixColumnWidth(creationDateCol, 120);
111         TableColumnExt updateDateCol = addDatePickerColumnToModel(SamplingEquipmentsTableModel.UPDATE_DATE, getConfig().getDateTimeFormat(), false);
112         fixColumnWidth(updateDateCol, 120);
113 
114         // status
115         TableColumnExt statusCol = addFilterableComboDataColumnToModel(
116                 SamplingEquipmentsTableModel.STATUS,
117                 getContext().getReferentialService().getStatus(StatusFilter.ACTIVE),
118                 false);
119         statusCol.setSortable(true);
120         statusCol.setEditable(false);
121 
122         SamplingEquipmentsTableModel tableModel = new SamplingEquipmentsTableModel(getTable().getColumnModel(), false);
123         table.setModel(tableModel);
124 
125         addExportToCSVAction(t("dali.property.samplingEquipment"));
126 
127         // Initialisation du tableau
128         initTable(table, true);
129 
130         creationDateCol.setVisible(false);
131         updateDateCol.setVisible(false);
132 
133         table.setVisibleRowCount(5);
134     }
135 
136     /**
137      * <p>clearTable.</p>
138      */
139     public void clearTable() {
140         getModel().setBeans(null);
141     }
142 
143     /** {@inheritDoc} */
144     @Override
145     public AbstractDaliTableModel<SamplingEquipmentsTableRowModel> getTableModel() {
146         return (SamplingEquipmentsTableModel) getTable().getModel();
147     }
148 
149     /** {@inheritDoc} */
150     @Override
151     public SwingTable getTable() {
152         return getUI().getSamplingEquipmentsNationalTable();
153     }
154 }