View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.national;
2   
3   /*
4    * #%L
5    * Reef DB :: 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.quadrige3.ui.swing.table.SwingTable;
27  import fr.ifremer.reefdb.dto.referential.UnitDTO;
28  import fr.ifremer.reefdb.service.StatusFilter;
29  import fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.menu.ReferentialUnitsMenuUIModel;
30  import fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.table.UnitTableModel;
31  import fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.table.UnitTableRowModel;
32  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableModel;
33  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableUIHandler;
34  import org.apache.commons.logging.Log;
35  import org.apache.commons.logging.LogFactory;
36  import org.jdesktop.swingx.table.TableColumnExt;
37  
38  import java.util.Collection;
39  
40  import static org.nuiton.i18n.I18n.t;
41  
42  /**
43   * Controlleur pour la gestion des Units au niveau national
44   */
45  public class ReferentialUnitsNationalUIHandler extends
46          AbstractReefDbTableUIHandler<UnitTableRowModel, ReferentialUnitsNationalUIModel, ReferentialUnitsNationalUI> {
47  
48      /**
49       * Logger.
50       */
51      private static final Log LOG = LogFactory.getLog(ReferentialUnitsNationalUIHandler.class);
52  
53      /** {@inheritDoc} */
54      @Override
55      public void beforeInit(ReferentialUnitsNationalUI ui) {
56          super.beforeInit(ui);
57  
58          // create model and register to the JAXX context
59          ReferentialUnitsNationalUIModel model = new ReferentialUnitsNationalUIModel();
60          ui.setContextValue(model);
61  
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public void afterInit(ReferentialUnitsNationalUI ui) {
67          initUI(ui);
68  
69          ReferentialUnitsMenuUIModel menuUIModel = getUI().getMenuUI().getModel();
70          menuUIModel.setLocal(false);
71  
72          menuUIModel.addPropertyChangeListener(ReferentialUnitsMenuUIModel.PROPERTY_RESULTS, evt -> getModel().setBeans((Collection<UnitDTO>) evt.getNewValue()));
73  
74          initTable();
75      }
76  
77      private void initTable() {
78  
79          // mnemonic
80          final TableColumnExt mnemonicCol = addColumn(
81                  UnitTableModel.NAME);
82          mnemonicCol.setSortable(true);
83  
84          // Symbol
85          final TableColumnExt symbolCol = addColumn(
86                  UnitTableModel.SYMBOL);
87          symbolCol.setSortable(true);
88  
89          // Comment, creation and update dates
90          addCommentColumn(UnitTableModel.COMMENT, false);
91          TableColumnExt creationDateCol = addDatePickerColumnToModel(UnitTableModel.CREATION_DATE, getConfig().getDateTimeFormat(), false);
92          fixColumnWidth(creationDateCol, 120);
93          TableColumnExt updateDateCol = addDatePickerColumnToModel(UnitTableModel.UPDATE_DATE, getConfig().getDateTimeFormat(), false);
94          fixColumnWidth(updateDateCol, 120);
95  
96          // status
97          final TableColumnExt statusCol = addFilterableComboDataColumnToModel(
98                  UnitTableModel.STATUS,
99                  getContext().getReferentialService().getStatus(StatusFilter.ACTIVE),
100                 false);
101         statusCol.setSortable(true);
102 
103         final UnitTableModel tableModel = new UnitTableModel(getTable().getColumnModel(), false);
104         getTable().setModel(tableModel);
105 
106         // Colonnes non editable
107         tableModel.setNoneEditableCols(
108                 UnitTableModel.NAME,
109                 UnitTableModel.SYMBOL,
110                 UnitTableModel.STATUS);
111 
112         // Add extraction action
113         addExportToCSVAction(t("reefdb.property.units.national"));
114 
115         // Initialisation du tableau
116         initTable(getTable(), true);
117 
118         creationDateCol.setVisible(false);
119         updateDateCol.setVisible(false);
120 
121         getTable().setVisibleRowCount(5);
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     public AbstractReefDbTableModel<UnitTableRowModel> getTableModel() {
127         return (UnitTableModel) getTable().getModel();
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     public SwingTable getTable() {
133         return ui.getReferentialUnitsNationalTable();
134     }
135 
136 }