View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.taxongroup;
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 groupeTaxons
40   */
41  public class ManageTaxonGroupUIHandler extends AbstractReefDbUIHandler<ManageTaxonGroupUIModel, ManageTaxonGroupUI> implements CloseableUI {
42  
43      /**
44       * Logger.
45       */
46      private static final Log LOG = LogFactory.getLog(ManageTaxonGroupUIHandler.class);
47  
48      /** {@inheritDoc} */
49      @Override
50      public void beforeInit(final ManageTaxonGroupUI ui) {
51          super.beforeInit(ui);
52  
53          // create model and register to the JAXX context
54          ui.setContextValue(new ManageTaxonGroupUIModel());
55          ui.setContextValue(SwingUtil.createActionIcon("config"));
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public void afterInit(final ManageTaxonGroupUI ui) {
61          initUI(ui);
62  
63          // Save models
64          getModel().setLocalUIModel(getUI().getTaxonGroupLocalUI().getModel());
65  
66          // Initialiser les parametres des ecrans Observation et prelevemnts
67          getContext().clearObservationPrelevementsIds();
68  
69          // Listen modify & valid
70          listenModelModify(getModel().getLocalUIModel());
71          getModel().getLocalUIModel().addPropertyChangeListener(AbstractReefDbBeanUIModel.PROPERTY_VALID, evt -> getValidator().doValidate());
72  
73          // Register validator
74          registerValidators(getValidator());
75          listenValidatorValid(getValidator(), getModel());
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public SwingValidator<ManageTaxonGroupUIModel> getValidator() {
81          return getUI().getValidator();
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      @SuppressWarnings("unchecked")
87      public boolean quitUI() {
88          try {
89              QuitScreenAction action = new QuitScreenAction(this, false, SaveAction.class);
90              if (action.prepareAction()) {
91                  return true;
92              }
93          } catch (Exception e) {
94              LOG.error(e.getLocalizedMessage(), e);
95          }
96          return false;
97  
98      }
99  }