View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.method.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.pmfm.MethodDTO;
27  import fr.ifremer.dali.service.StatusFilter;
28  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.method.menu.ManageMethodsMenuUIModel;
29  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.method.table.MethodsTableModel;
30  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.method.table.MethodsTableRowModel;
31  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
32  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableUIHandler;
33  import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
34  import org.jdesktop.swingx.table.TableColumnExt;
35  
36  import java.util.Collection;
37  
38  import static org.nuiton.i18n.I18n.t;
39  
40  /**
41   * Controlleur pour la gestion des Methods au niveau national
42   */
43  public class ManageMethodsNationalUIHandler extends AbstractDaliTableUIHandler<MethodsTableRowModel, ManageMethodsNationalUIModel, ManageMethodsNationalUI> {
44  
45      /** {@inheritDoc} */
46      @Override
47      public void beforeInit(ManageMethodsNationalUI ui) {
48          super.beforeInit(ui);
49  
50          // create model and register to the JAXX context
51          ManageMethodsNationalUIModel model = new ManageMethodsNationalUIModel();
52          ui.setContextValue(model);
53  
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      @SuppressWarnings("unchecked")
59      public void afterInit(ManageMethodsNationalUI ui) {
60          initUI(ui);
61  
62          ManageMethodsMenuUIModel menuUIModel = getUI().getMenuUI().getModel();
63  
64          menuUIModel.addPropertyChangeListener(ManageMethodsMenuUIModel.PROPERTY_RESULTS, evt -> getModel().setBeans((Collection<MethodDTO>) evt.getNewValue()));
65  
66          initTable();
67  
68      }
69  
70      private void initTable() {
71  
72          // Le tableau
73          final SwingTable table = getTable();
74  
75          // mnemonic
76          final TableColumnExt mnemonicCol = addColumn(MethodsTableModel.NAME);
77          mnemonicCol.setSortable(true);
78          mnemonicCol.setEditable(false);
79  
80          // description
81          final TableColumnExt descriptionCol = addColumn(MethodsTableModel.DESCRIPTION);
82          descriptionCol.setSortable(true);
83          descriptionCol.setEditable(false);
84  
85          // reference
86          final TableColumnExt referenceCol = addColumn(MethodsTableModel.REFERENCE);
87          referenceCol.setSortable(true);
88          referenceCol.setEditable(false);
89  
90          // number
91          final TableColumnExt numberCol = addColumn(MethodsTableModel.NUMBER);
92          numberCol.setSortable(true);
93          numberCol.setEditable(false);
94  
95          // Comment, creation and update dates
96          addCommentColumn(MethodsTableModel.COMMENT, false);
97          TableColumnExt creationDateCol = addDatePickerColumnToModel(MethodsTableModel.CREATION_DATE, getConfig().getDateTimeFormat(), false);
98          fixColumnWidth(creationDateCol, 120);
99          TableColumnExt updateDateCol = addDatePickerColumnToModel(MethodsTableModel.UPDATE_DATE, getConfig().getDateTimeFormat(), false);
100         fixColumnWidth(updateDateCol, 120);
101 
102         // status
103         final TableColumnExt statusCol = addFilterableComboDataColumnToModel(
104                 MethodsTableModel.STATUS,
105                 getContext().getReferentialService().getStatus(StatusFilter.ALL),
106                 false);
107         statusCol.setSortable(true);
108         statusCol.setEditable(false);
109         fixDefaultColumnWidth(statusCol);
110 
111         // description packaging
112         final TableColumnExt descriptionPackagingCol = addColumn(MethodsTableModel.DESCRIPTIONPACKAGING);
113         descriptionPackagingCol.setSortable(true);
114         descriptionPackagingCol.setEditable(false);
115 
116         // description preparation
117         final TableColumnExt descriptionPreparationCol = addColumn(MethodsTableModel.DESCRIPTIONPREPARATION);
118         descriptionPreparationCol.setSortable(true);
119         descriptionPreparationCol.setEditable(false);
120 
121         // description preservation
122         final TableColumnExt descriptionPreservationCol = addColumn(MethodsTableModel.DESCRIPTIONPRESERVATION);
123         descriptionPreservationCol.setSortable(true);
124         descriptionPreservationCol.setEditable(false);
125 
126         MethodsTableModel tableModel = new MethodsTableModel(getTable().getColumnModel(), false);
127         table.setModel(tableModel);
128 
129         addExportToCSVAction(t("dali.property.pmfm.method"));
130 
131         // Initialisation du tableau
132         initTable(table, true);
133 
134         // Les colonnes optionnelles sont invisibles
135         descriptionPackagingCol.setVisible(false);
136         descriptionPreparationCol.setVisible(false);
137         descriptionPreservationCol.setVisible(false);
138 
139         creationDateCol.setVisible(false);
140         updateDateCol.setVisible(false);
141 
142         table.setVisibleRowCount(5);
143     }
144 
145     /** {@inheritDoc} */
146     @Override
147     public AbstractDaliTableModel<MethodsTableRowModel> getTableModel() {
148         return (MethodsTableModel) getTable().getModel();
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public SwingTable getTable() {
154         return ui.getManageMethodsNationalTable();
155     }
156 }