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 ValidationHistoryUIHandler extends AbstractDaliTableUIHandler<ValidationHistoryRowModel, ValidationHistoryUIModel, ValidationHistoryUI> {
37  
38      @Override
39      public void beforeInit(ValidationHistoryUI ui) {
40          super.beforeInit(ui);
41  
42          ui.setContextValue(new ValidationHistoryUIModel());
43      }
44  
45      @Override
46      public void afterInit(ValidationHistoryUI validationHistoryUI) {
47  
48          initUI(validationHistoryUI);
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                  ValidationHistoryTableModel.DATE);
60          fixColumnWidth(dateCol, 110);
61  
62          addColumn(
63                  null,
64                  new MultiLineStringCellRenderer(),
65                  ValidationHistoryTableModel.COMMENT);
66  
67          addColumn(ValidationHistoryTableModel.RECORDER_PERSON);
68  
69          ValidationHistoryTableModel tableModel = new ValidationHistoryTableModel(getTable().getColumnModel());
70          table.setModel(tableModel);
71          initTable(table, true);
72  
73          table.setEditable(false);
74  
75          table.setSortOrder(ValidationHistoryTableModel.DATE, SortOrder.ASCENDING);
76  
77          // Auto adjust rows height
78          new TableRowHeightController(table);
79      }
80  
81      @Override
82      public AbstractTableModel<ValidationHistoryRowModel> getTableModel() {
83          return (ValidationHistoryTableModel) getTable().getModel();
84      }
85  
86      @Override
87      public SwingTable getTable() {
88          return getUI().getValidationHistoryTable();
89      }
90  
91  }