View Javadoc
1   package fr.ifremer.dali.ui.swing.content.observation.survey.history;
2   
3   /*-
4    * #%L
5    * Dali :: UI
6    * %%
7    * Copyright (C) 2014 - 2017 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Affero General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU Affero General Public License
20   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
22   */
23  
24  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableUIHandler;
25  import fr.ifremer.quadrige3.ui.swing.table.AbstractTableModel;
26  import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
27  import fr.ifremer.quadrige3.ui.swing.table.renderer.MultiLineStringCellRenderer;
28  import org.jdesktop.swingx.table.TableColumnExt;
29  import org.jdesktop.swingx.table.TableRowHeightController;
30  
31  import javax.swing.SortOrder;
32  
33  /**
34   * @author peck7 on 26/09/2017.
35   */
36  public class QualificationHistoryUIHandler extends AbstractDaliTableUIHandler<QualificationHistoryRowModel, QualificationHistoryUIModel, QualificationHistoryUI> {
37  
38      @Override
39      public void beforeInit(QualificationHistoryUI ui) {
40          super.beforeInit(ui);
41  
42          ui.setContextValue(new QualificationHistoryUIModel());
43      }
44  
45      @Override
46      public void afterInit(QualificationHistoryUI qualificationHistoryUI) {
47  
48          initUI(qualificationHistoryUI);
49          initTable();
50      }
51  
52      private void initTable() {
53  
54          SwingTable table = getTable();
55  
56          TableColumnExt dateCol = addColumn(
57                  null,
58                  newDateCellRenderer(getConfig().getDateTimeFormat()),
59                  QualificationHistoryTableModel.DATE);
60          fixColumnWidth(dateCol, 125);
61  
62          addColumn(
63                  null,
64                  new MultiLineStringCellRenderer(),
65                  QualificationHistoryTableModel.COMMENT);
66  
67          addColumn(QualificationHistoryTableModel.QUALITY_LEVEL);
68  
69          addColumn(QualificationHistoryTableModel.RECORDER_PERSON);
70  
71          QualificationHistoryTableModel tableModel = new QualificationHistoryTableModel(getTable().getColumnModel());
72          table.setModel(tableModel);
73          initTable(table, true);
74  
75          table.setEditable(false);
76  
77          table.setSortOrder(QualificationHistoryTableModel.DATE, SortOrder.ASCENDING);
78  
79          // Auto adjust rows height
80          new TableRowHeightController(table);
81      }
82  
83      @Override
84      public AbstractTableModel<QualificationHistoryRowModel> getTableModel() {
85          return (QualificationHistoryTableModel) getTable().getModel();
86      }
87  
88      @Override
89      public SwingTable getTable() {
90          return getUI().getQualificationHistoryTable();
91      }
92  
93  }