View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon;
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.action.QuitScreenAction;
27  import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbBeanUIModel;
28  import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbUIHandler;
29  import jaxx.runtime.SwingUtil;
30  import jaxx.runtime.validator.swing.SwingValidator;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.nuiton.jaxx.application.swing.util.CloseableUI;
34  
35  import java.beans.PropertyChangeEvent;
36  import java.beans.PropertyChangeListener;
37  
38  /**
39   * Controlleur pour la gestion des taxons
40   */
41  public class ManageTaxonsUIHandler extends AbstractReefDbUIHandler<ManageTaxonsUIModel, ManageTaxonsUI> implements CloseableUI {
42  
43      /**
44       * Logger.
45       */
46      private static final Log LOG = LogFactory.getLog(ManageTaxonsUIHandler.class);
47  
48      /** {@inheritDoc} */
49      @Override
50      public void beforeInit(final ManageTaxonsUI ui) {
51          super.beforeInit(ui);
52  
53          // create model and register to the JAXX context
54          ui.setContextValue(new ManageTaxonsUIModel());
55          ui.setContextValue(SwingUtil.createActionIcon("config"));
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public void afterInit(final ManageTaxonsUI ui) {
61          initUI(ui);
62  
63          // Initialiser les parametres des ecrans Observation et prelevemnts
64          getContext().clearObservationPrelevementsIds();
65  
66          getModel().setLocalUIModel(getUI().getTaxonsLocalUI().getModel());
67  
68          // Listen modify & valid
69          listenModelModify(getModel().getLocalUIModel());
70          getModel().getLocalUIModel().addPropertyChangeListener(AbstractReefDbBeanUIModel.PROPERTY_VALID, evt -> getValidator().doValidate());
71  
72          // Register validator
73          registerValidators(getValidator());
74          listenValidatorValid(getValidator(), getModel());
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public SwingValidator<ManageTaxonsUIModel> getValidator() {
80          return getUI().getValidator();
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      @SuppressWarnings("unchecked")
86      public boolean quitUI() {
87          try {
88              QuitScreenAction action = new QuitScreenAction(this, false, SaveAction.class);
89              if (action.prepareAction()) {
90                  return true;
91              }
92          } catch (Exception e) {
93              LOG.error(e.getLocalizedMessage(), e);
94          }
95          return false;
96  
97      }
98  }