View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.fraction.associatedMatrices;
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 com.google.common.collect.Lists;
27  import fr.ifremer.dali.dto.referential.pmfm.MatrixDTO;
28  import fr.ifremer.dali.service.StatusFilter;
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.quadrige3.ui.swing.table.SwingTable;
34  import org.jdesktop.swingx.table.TableColumnExt;
35  import org.nuiton.jaxx.application.swing.util.Cancelable;
36  
37  import java.util.List;
38  
39  /**
40   * Controlleur pour la gestion des lieux au niveau national
41   */
42  public class AssociatedMatricesUIHandler extends AbstractDaliTableUIHandler<MatricesTableRowModel, AssociatedMatricesUIModel, AssociatedMatricesUI> implements Cancelable {
43  
44      /** {@inheritDoc} */
45      @Override
46      public void beforeInit(AssociatedMatricesUI ui) {
47          super.beforeInit(ui);
48  
49          AssociatedMatricesUIModel matricesUIModel = new AssociatedMatricesUIModel();
50          ui.setContextValue(matricesUIModel);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public void afterInit(AssociatedMatricesUI associatedMatricesUI) {
56          initUI(associatedMatricesUI);
57  
58          // Initialisation du tableau
59          initTable();
60  
61  
62          getModel().addPropertyChangeListener(evt -> {
63  
64              if (AssociatedMatricesUIModel.PROPERTY_FRACTION.equals(evt.getPropertyName())) {
65  
66                  List<MatrixDTO> matrices = getModel().getFraction() != null ? Lists.newArrayList(getModel().getFraction().getMatrixes()) : null;
67                  getModel().setBeans(matrices);
68  
69              }
70          });
71      }
72  
73      /**
74       * Initialisation du tableau.
75       */
76      private void initTable() {
77  
78          // Le tableau
79          final SwingTable table = getTable();
80  
81          // mnemonic
82          final TableColumnExt mnemonicCol = addColumn(MatricesTableModel.NAME);
83          mnemonicCol.setSortable(true);
84  
85          // description
86          final TableColumnExt descriptionCol = addColumn(MatricesTableModel.DESCRIPTION);
87          descriptionCol.setSortable(true);
88  
89          // status
90          final TableColumnExt statusCol = addFilterableComboDataColumnToModel(
91                  MatricesTableModel.STATUS,
92                  getContext().getReferentialService().getStatus(StatusFilter.ALL),
93                  false);
94          statusCol.setSortable(true);
95          fixDefaultColumnWidth(statusCol);
96  
97          MatricesTableModel tableModel = new MatricesTableModel(getTable().getColumnModel(), false);
98          table.setModel(tableModel);
99  
100         // Initialisation du tableau
101         initTable(table, true);
102 
103         table.setEditable(false);
104 
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     public AbstractDaliTableModel<MatricesTableRowModel> getTableModel() {
110         return (MatricesTableModel) getTable().getModel();
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public SwingTable getTable() {
116         return ui.getAssociatedMatricesTable();
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     public void cancel() {
122         closeDialog();
123     }
124 }