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 VesselUseFeatureTabUIHandler extends AbstractCaracteristicTabUIHandler<VesselUseFeatureRowModel, VesselUseFeatureTabUIModel, VesselUseFeatureTableModel, VesselUseFeatureTabUI> {
43  
44      public VesselUseFeatureTabUIHandler() {
45          super(VesselUseFeatureRowModel.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 VesselUseFeatureTabUIModel createModel() {
59          return new VesselUseFeatureTabUIModel();
60      }
61  
62      @Override
63      protected CaracteristicMap getCaracteristics(FishingOperation operation) {
64          return operation.getVesselUseFeatures();
65      }
66  
67      @Override
68      protected List<String> getProtocolPmfmIds() {
69          return TuttiProtocols.vesselUseFeaturePmfmIds(getDataContext().getProtocol());
70      }
71  
72      //------------------------------------------------------------------------//
73      //-- AbstractTuttiTableUIHandler methods                                --//
74      //------------------------------------------------------------------------//
75  
76      @Override
77      public JXTable getTable() {
78          return ui.getVesselUseFeatureTable();
79      }
80  
81      //------------------------------------------------------------------------//
82      //-- AbstractTuttiUIHandler methods                                     --//
83      //------------------------------------------------------------------------//
84  
85      @Override
86      public void afterInit(VesselUseFeatureTabUI ui) {
87          super.afterInit(ui);
88  
89          JXTable table = getTable();
90  
91          // create table column model
92          DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt();
93  
94          {
95  
96              addColumnToModel(columnModel,
97                               null,
98                               newTableCellRender(Caracteristic.class, DecoratorService.CARACTERISTIC_WITH_UNIT),
99                               VesselUseFeatureTableModel.KEY);
100         }
101 
102         {
103 
104             addColumnToModel(columnModel,
105                              new CaracteristicValueEditor(getContext()),
106                              new CaracteristicValueRenderer(getContext()),
107                              VesselUseFeatureTableModel.VALUE);
108         }
109 
110         // create table model
111         VesselUseFeatureTableModel tableModel =
112                 new VesselUseFeatureTableModel(columnModel);
113 
114         table.setModel(tableModel);
115         table.setColumnModel(columnModel);
116         initTable(table);
117     }
118 
119     @Override
120     protected void initTable(JXTable table) {
121         super.initTable(table);
122         installTableKeyListener(table.getColumnModel(), table);
123     }
124 
125 }