View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.department.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 ReplaceDepartmentUIHandler extends AbstractReefDbUIHandler<ReplaceDepartmentUIModel, ReplaceDepartmentUI> implements Cancelable {
40  
41      /** Logger. */
42      private static final Log log =
43              LogFactory.getLog(ReplaceDepartmentUIHandler.class);
44  
45      /** {@inheritDoc} */
46      @Override
47      public void afterInit(ReplaceDepartmentUI ui) {
48  
49          initUI(ui);
50  
51          ReplaceDepartmentUIModel model = getModel();
52          initBeanFilterableComboBox(ui.getSourceListComboBox(), model.getSourceList(), model.getSelectedSource());
53          initBeanFilterableComboBox(ui.getTargetListComboBox(), model.getTargetList(), model.getSelectedTarget());
54  
55          SwingValidator validator = ui.getValidator();
56          listenValidatorValid(validator, model);
57  
58          registerValidators(validator);
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      protected JComponent getComponentToFocus() {
64          return getUI().getSourceListComboBox();
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      @SuppressWarnings("unchecked")
70      public SwingValidator getValidator() {
71          return ui.getValidator();
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public void cancel() {
77          getModel().setValid(false);
78          onCloseUI();
79      }
80  
81  }