View Javadoc
1   package fr.ifremer.tutti.ui.swing.util.species;
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 com.google.common.collect.Lists;
26  import fr.ifremer.tutti.persistence.entities.referential.Species;
27  import fr.ifremer.tutti.service.DecoratorService;
28  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler;
29  import jaxx.runtime.validator.swing.SwingValidator;
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  
33  import javax.swing.JComponent;
34  
35  /**
36   * @author Kevin Morin - kmorin@codelutin.com
37   * @since 1.0
38   */
39  public class SelectSpeciesUIHandler extends AbstractTuttiUIHandler<SelectSpeciesUIModel, SelectSpeciesUI> {
40  
41      private static final Log log =
42              LogFactory.getLog(SelectSpeciesUIHandler.class);
43  
44      @Override
45      public void beforeInit(SelectSpeciesUI ui) {
46          super.beforeInit(ui);
47          SelectSpeciesUIModel model = new SelectSpeciesUIModel();
48          ui.setContextValue(model);
49      }
50  
51      @Override
52      public void afterInit(SelectSpeciesUI ui) {
53          initUI(ui);
54  
55          String context = ui.useSurveyCode ? DecoratorService.WITH_SURVEY_CODE : null;
56  
57          initBeanFilterableComboBox(ui.getSpeciesCombo(),
58                                     Lists.<Species>newArrayList(),
59                                     null,
60                                     context);
61  
62  //        initBeanFilterableComboBox(ui.getSpeciesCombo(),
63  //                                   Lists.<Species>newArrayList(),
64  //                                   null,
65  //                                   DecoratorService.WITH_SURVEY_CODE);
66  
67          getModel().addPropertyChangeListener(
68                  SelectSpeciesUIModel.PROPERTY_SPECIES,
69                  evt -> SelectSpeciesUIHandler.this.ui.getSpeciesCombo().getHandler().sortData());
70  
71      }
72  
73      @Override
74      protected JComponent getComponentToFocus() {
75          return getUI().getSpeciesCombo();
76      }
77  
78      @Override
79      public void onCloseUI() {
80          if (log.isDebugEnabled()) {
81              log.debug("closing: " + ui);
82          }
83      }
84  
85      @Override
86      public SwingValidator<SelectSpeciesUIModel> getValidator() {
87          return null;
88      }
89  
90  }