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