View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.matrix.associatedFractions;
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.FractionDTO;
28  import fr.ifremer.dali.service.StatusFilter;
29  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.fraction.table.FractionsTableModel;
30  import fr.ifremer.dali.ui.swing.content.manage.referential.pmfm.fraction.table.FractionsTableRowModel;
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   * Handler.
41   */
42  public class AssociatedFractionsUIHandler extends AbstractDaliTableUIHandler<FractionsTableRowModel, AssociatedFractionsUIModel, AssociatedFractionsUI> implements Cancelable {
43  
44      /** {@inheritDoc} */
45      @Override
46      public void beforeInit(AssociatedFractionsUI ui) {
47          super.beforeInit(ui);
48  
49          AssociatedFractionsUIModel model = new AssociatedFractionsUIModel();
50          ui.setContextValue(model);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public void afterInit(AssociatedFractionsUI associatedFractionsUI) {
56          initUI(associatedFractionsUI);
57  
58          // Init table columns and properties
59          initTable();
60  
61          getModel().addPropertyChangeListener(evt -> {
62  
63              if (AssociatedFractionsUIModel.PROPERTY_MATRIX.equals(evt.getPropertyName())) {
64  
65                  List<FractionDTO> fractions = getModel().getMatrix() != null ? Lists.newArrayList(getModel().getMatrix().getFractions()) : null;
66                  getModel().setBeans(fractions);
67  
68              }
69          });
70      }
71  
72      /**
73       * Init the table
74       */
75      private void initTable() {
76  
77          // La table des prelevements
78          final SwingTable table = getTable();
79  
80          // mnemonic
81          final TableColumnExt mnemonicCol = addColumn(FractionsTableModel.NAME);
82          mnemonicCol.setSortable(true);
83  
84          // Description
85          final TableColumnExt descriptionCol = addColumn(FractionsTableModel.DESCRIPTION);
86          descriptionCol.setSortable(true);
87  
88          // status
89          final TableColumnExt statusCol = addFilterableComboDataColumnToModel(
90                  FractionsTableModel.STATUS,
91                  getContext().getReferentialService().getStatus(StatusFilter.ALL),
92                  false);
93          statusCol.setSortable(true);
94  
95          // model for table
96          final FractionsTableModel tableModel = new FractionsTableModel(getTable().getColumnModel());
97          table.setModel(tableModel);
98  
99          initTable(table);
100 
101         table.setEditable(false);
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     public AbstractDaliTableModel<FractionsTableRowModel> getTableModel() {
107         return (FractionsTableModel) getTable().getModel();
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public SwingTable getTable() {
113         return ui.getAssociatedFractionsTable();
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     public void cancel() {
119         closeDialog();
120     }
121 }