View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.fishing;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (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 General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
26  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
27  import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols;
28  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
29  import fr.ifremer.tutti.service.DecoratorService;
30  import fr.ifremer.tutti.ui.swing.util.caracteristics.CaracteristicValueEditor;
31  import fr.ifremer.tutti.ui.swing.util.caracteristics.CaracteristicValueRenderer;
32  import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
33  import org.jdesktop.swingx.JXTable;
34  import org.jdesktop.swingx.table.DefaultTableColumnModelExt;
35  
36  import java.util.List;
37  
38  /**
39   * @author kmorin
40   * @since 0.3
41   */
42  public class GearUseFeatureTabUIHandler extends AbstractCaracteristicTabUIHandler<GearUseFeatureRowModel, GearUseFeatureTabUIModel, GearUseFeatureTableModel, GearUseFeatureTabUI> {
43  
44      public GearUseFeatureTabUIHandler() {
45          super(GearUseFeatureRowModel.PROPERTY_VALUE);
46      }
47  
48      //------------------------------------------------------------------------//
49      //-- AbstractCaracteristicTabUIHandler methods                          --//
50      //------------------------------------------------------------------------//
51  
52      @Override
53      protected BeanFilterableComboBox<Caracteristic> getKeyCombo() {
54          return ui.getNewRowKey();
55      }
56  
57      @Override
58      protected GearUseFeatureTabUIModel createModel() {
59          return new GearUseFeatureTabUIModel();
60      }
61  
62      @Override
63      protected CaracteristicMap getCaracteristics(FishingOperation operation) {
64          return operation.getGearUseFeatures();
65      }
66  
67      @Override
68      protected List<String> getProtocolPmfmIds() {
69          return TuttiProtocols.gearUseFeaturePmfmIds(getDataContext().getProtocol());
70      }
71  
72      //------------------------------------------------------------------------//
73      //-- AbstractTuttiTableUIHandler methods                                --//
74      //------------------------------------------------------------------------//
75  
76      @Override
77      public JXTable getTable() {
78          return ui.getGearUseFeatureTable();
79      }
80  
81      //------------------------------------------------------------------------//
82      //-- AbstractTuttiUIHandler methods                                     --//
83      //------------------------------------------------------------------------//
84  
85      @Override
86      public void afterInit(GearUseFeatureTabUI ui) {
87          super.afterInit(ui);
88  
89          JXTable table = getTable();
90  
91          // create table column model
92          DefaultTableColumnModelExt columnModel =
93                  new DefaultTableColumnModelExt();
94  
95          {
96  
97              addColumnToModel(columnModel,
98                               null,
99                               newTableCellRender(Caracteristic.class, DecoratorService.CARACTERISTIC_WITH_UNIT),
100                              GearUseFeatureTableModel.KEY);
101         }
102 
103         {
104 
105             addColumnToModel(columnModel,
106                              new CaracteristicValueEditor(getContext()),
107                              new CaracteristicValueRenderer(getContext()),
108                              GearUseFeatureTableModel.VALUE);
109         }
110 
111         // create table model
112         GearUseFeatureTableModel tableModel =
113                 new GearUseFeatureTableModel(columnModel);
114 
115         table.setModel(tableModel);
116         table.setColumnModel(columnModel);
117 
118         initTable(table);
119     }
120 
121     @Override
122     protected void initTable(JXTable table) {
123         super.initTable(table);
124         installTableKeyListener(table.getColumnModel(), table);
125         table.putClientProperty("JTable.autoStartsEdit", true);
126     }
127 
128 }