View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.parameter.local.replace;
2   
3   /*
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbUIHandler;
27  import jaxx.runtime.validator.swing.SwingValidator;
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.nuiton.jaxx.application.swing.util.Cancelable;
31  
32  import javax.swing.*;
33  
34  /**
35   * Created on 7/6/14.
36   *
37   * @since 3.6
38   */
39  public class ReplaceParameterUIHandler extends AbstractReefDbUIHandler<ReplaceParameterUIModel, ReplaceParameterUI> implements Cancelable {
40  
41      /**
42       * Logger.
43       */
44      private static final Log log =
45              LogFactory.getLog(ReplaceParameterUIHandler.class);
46  
47      /** {@inheritDoc} */
48      @Override
49      public void afterInit(ReplaceParameterUI ui) {
50  
51          initUI(ui);
52  
53          ReplaceParameterUIModel model = getModel();
54          initBeanFilterableComboBox(ui.getSourceListComboBox(), model.getSourceList(), model.getSelectedSource(), model.getDecoratorContext());
55          initBeanFilterableComboBox(ui.getTargetListComboBox(), model.getTargetList(), model.getSelectedTarget(), model.getDecoratorContext());
56  
57          SwingValidator validator = ui.getValidator();
58          listenValidatorValid(validator, model);
59  
60          registerValidators(validator);
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      protected JComponent getComponentToFocus() {
66          return getUI().getSourceListComboBox();
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      @SuppressWarnings("unchecked")
72      public SwingValidator getValidator() {
73          return ui.getValidator();
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public void cancel() {
79          getModel().setValid(false);
80          onCloseUI();
81      }
82  
83  }