View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.matrix.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.MatrixDTO;
27  import fr.ifremer.dali.service.StatusFilter;
28  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.matrix.menu.ManageMatricesMenuUIModel;
29  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.matrix.table.MatricesTableModel;
30  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.matrix.table.MatricesTableRowModel;
31  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
32  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableUIHandler;
33  import fr.ifremer.dali.ui.swing.util.table.editor.AssociatedFractionsCellEditor;
34  import fr.ifremer.dali.ui.swing.util.table.renderer.AssociatedFractionCellRenderer;
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 Matrices au niveau national
44   */
45  public class ManageMatricesNationalUIHandler extends
46          AbstractDaliTableUIHandler<MatricesTableRowModel, ManageMatricesNationalUIModel, ManageMatricesNationalUI> {
47  
48      /** {@inheritDoc} */
49      @Override
50      public void beforeInit(ManageMatricesNationalUI ui) {
51          super.beforeInit(ui);
52  
53          // create model and register to the JAXX context
54          ManageMatricesNationalUIModel model = new ManageMatricesNationalUIModel();
55          ui.setContextValue(model);
56  
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      @SuppressWarnings("unchecked")
62      public void afterInit(ManageMatricesNationalUI ui) {
63          initUI(ui);
64  
65          ManageMatricesMenuUIModel menuUIModel = getUI().getMenuUI().getModel();
66  
67          menuUIModel.addPropertyChangeListener(ManageMatricesMenuUIModel.PROPERTY_RESULTS, evt -> getModel().setBeans((List<MatrixDTO>) evt.getNewValue()));
68  
69          initTable();
70  
71      }
72  
73      private void initTable() {
74  
75          // Le tableau
76          final SwingTable table = getTable();
77  
78          // mnemonic
79          final TableColumnExt mnemonicCol = addColumn(MatricesTableModel.NAME);
80          mnemonicCol.setSortable(true);
81          mnemonicCol.setEditable(false);
82  
83          // description
84          final TableColumnExt descriptionCol = addColumn(MatricesTableModel.DESCRIPTION);
85          descriptionCol.setSortable(true);
86          descriptionCol.setEditable(false);
87  
88          // Comment, creation and update dates
89          addCommentColumn(MatricesTableModel.COMMENT, false);
90          TableColumnExt creationDateCol = addDatePickerColumnToModel(MatricesTableModel.CREATION_DATE, getConfig().getDateTimeFormat(), false);
91          fixColumnWidth(creationDateCol, 120);
92          TableColumnExt updateDateCol = addDatePickerColumnToModel(MatricesTableModel.UPDATE_DATE, getConfig().getDateTimeFormat(), false);
93          fixColumnWidth(updateDateCol, 120);
94  
95          // status
96          final TableColumnExt statusCol = addFilterableComboDataColumnToModel(
97                  MatricesTableModel.STATUS,
98                  getContext().getReferentialService().getStatus(StatusFilter.ALL),
99                  false);
100         statusCol.setSortable(true);
101         statusCol.setEditable(false);
102         fixDefaultColumnWidth(statusCol);
103 
104         // associated fractions
105         final TableColumnExt associatedFractionsCol = addColumn(
106                 new AssociatedFractionsCellEditor(getTable(), getUI()),
107                 new AssociatedFractionCellRenderer(),
108                 MatricesTableModel.ASSOCIATED_FRACTIONS);
109         associatedFractionsCol.setSortable(true);
110 
111         MatricesTableModel tableModel = new MatricesTableModel(getTable().getColumnModel(), false);
112         table.setModel(tableModel);
113 
114         addExportToCSVAction(t("dali.property.pmfm.matrix"), MatricesTableModel.ASSOCIATED_FRACTIONS);
115 
116         // Initialisation du tableau
117         initTable(table, true);
118 
119         // Les colonnes optionnelles sont invisibles
120         associatedFractionsCol.setVisible(false);
121 
122         creationDateCol.setVisible(false);
123         updateDateCol.setVisible(false);
124 
125         table.setVisibleRowCount(5);
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     public AbstractDaliTableModel<MatricesTableRowModel> getTableModel() {
131         return (MatricesTableModel) getTable().getModel();
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public SwingTable getTable() {
137         return ui.getManageMatricesNationalTable();
138     }
139 }