View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches.accidental.create;
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.ui.swing.content.operation.catches.EditCatchesUI;
27  import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler;
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.4
38   */
39  public class CreateAccidentalBatchUIHandler extends AbstractTuttiUIHandler<CreateAccidentalBatchUIModel, CreateAccidentalBatchUI> {
40  
41      private static final Log log =
42              LogFactory.getLog(CreateAccidentalBatchUIHandler.class);
43  
44      //------------------------------------------------------------------------//
45      //-- AbstractTuttiUIHandler methods                                     --//
46      //------------------------------------------------------------------------//
47  
48      @Override
49      public void beforeInit(CreateAccidentalBatchUI ui) {
50          super.beforeInit(ui);
51          CreateAccidentalBatchUIModel model = new CreateAccidentalBatchUIModel();
52          ui.setContextValue(model);
53          listModelIsModify(model);
54      }
55  
56      @Override
57      public void afterInit(CreateAccidentalBatchUI ui) {
58  
59          initUI(ui);
60  
61          initBeanFilterableComboBox(ui.getAccidentalSpeciesComboBox(),
62                                     Lists.newArrayList(getDataContext().getReferentSpecies()),
63                                     null);
64  
65          initBeanFilterableComboBox(ui.getAccidentalGenderComboBox(),
66                                     Lists.newArrayList(getDataContext().getGenderValues()),
67                                     null);
68  
69          initBeanFilterableComboBox(ui.getAccidentalLengthStepCaracteristicComboBox(),
70                                     Lists.newArrayList(getDataContext().getLengthStepCaracteristics()),
71                                     null);
72  
73          initBeanFilterableComboBox(ui.getAccidentalDeadOrAliveComboBox(),
74                                     Lists.newArrayList(getDataContext().getDeadOrAliveValues()),
75                                     null);
76  
77          listenValidatorValid(ui.getValidator(), getModel());
78      }
79  
80      @Override
81      protected JComponent getComponentToFocus() {
82          return getUI().getAccidentalSpeciesComboBox();
83      }
84  
85      @Override
86      public void onCloseUI() {
87  
88          if (log.isDebugEnabled()) {
89              log.debug("closing: " + ui);
90          }
91  
92          // evict model from validator
93          ui.getValidator().setBean(null);
94  
95          // when canceling always invalid model
96          getModel().setValid(false);
97  
98          EditCatchesUI parent = getParentContainer(EditCatchesUI.class);
99          parent.getHandler().setAccidentalSelectedCard(EditCatchesUIHandler.MAIN_CARD);
100     }
101 
102     @Override
103     public SwingValidator<CreateAccidentalBatchUIModel> getValidator() {
104         return ui.getValidator();
105     }
106 
107     //------------------------------------------------------------------------//
108     //-- Public methods                                                     --//
109     //------------------------------------------------------------------------//
110 
111     public void openUI() {
112 
113         CreateAccidentalBatchUIModel model = getModel();
114 
115         // connect model to validator
116         ui.getValidator().setBean(model);
117 
118         model.reset();
119 
120     }
121 
122 }