View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.program.strategiesByLocation;
2   
3   /*
4    * #%L
5    * Dali :: 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.dali.dto.configuration.programStrategy.ProgramDTO;
27  import fr.ifremer.dali.ui.swing.action.QuitScreenAction;
28  import fr.ifremer.dali.ui.swing.util.AbstractDaliUIHandler;
29  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableUIModel;
30  import jaxx.runtime.SwingUtil;
31  import jaxx.runtime.validator.swing.SwingValidator;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  import org.nuiton.jaxx.application.swing.util.CloseableUI;
35  
36  /**
37   * Controlleur pour l'onglet prelevements mesures.
38   */
39  public class StrategiesLieuxUIHandler extends AbstractDaliUIHandler<StrategiesLieuxUIModel, StrategiesLieuxUI> implements CloseableUI {
40  
41      /**
42       * Logger.
43       */
44      private static final Log LOG = LogFactory.getLog(StrategiesLieuxUIHandler.class);
45  
46      /** {@inheritDoc} */
47      @Override
48      public void beforeInit(StrategiesLieuxUI ui) {
49          super.beforeInit(ui);
50          
51          // create model and register to the JAXX context
52          StrategiesLieuxUIModel model = new StrategiesLieuxUIModel();
53          ui.setContextValue(model);
54  
55          ui.setContextValue(SwingUtil.createActionIcon("program"));
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public void afterInit(StrategiesLieuxUI ui) {
61          initUI(ui);
62  
63          getModel().setTableUIModel(getUI().getStrategiesProgrammeTableUI().getModel());
64          listenModelModify(getModel().getTableUIModel());
65          getModel().getTableUIModel().addPropertyChangeListener(AbstractDaliTableUIModel.PROPERTY_VALID, evt -> getValidator().doValidate());
66  
67          listenValidatorValid(getValidator(), getModel());
68          registerValidators(getValidator());
69  
70          // Load les tableaux
71          load();
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public SwingValidator<StrategiesLieuxUIModel> getValidator() {
77          return getUI().getValidator();
78      }
79  
80      /**
81       * Load le tableau.
82       */
83      public void load() {
84      	
85      	// Le programme
86      	final ProgramDTO programme = getContext().getProgramStrategyService().getWritableProgramByCode(
87      			getContext().getSelectProgramCode());
88      	if (programme != null) {
89      		
90      		// Chargement des lieux
91      		getUI().getLieuxProgrammeTableUI().getHandler().load(programme);
92      	}
93      }
94  
95      @Override
96      @SuppressWarnings("unchecked")
97      public boolean quitUI() {
98          try {
99              QuitScreenAction action = new QuitScreenAction(this, false, SaveAction.class);
100             if (action.prepareAction()) {
101                 return true;
102             }
103         } catch (Exception e) {
104             LOG.error(e.getLocalizedMessage(), e);
105         }
106         return false;
107     }
108 
109 }