View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.program.pmfms.edit;
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.dto.configuration.programStrategy.PmfmStrategyDTO;
27  import fr.ifremer.reefdb.service.StatusFilter;
28  import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbUIHandler;
29  import org.nuiton.jaxx.application.swing.util.Cancelable;
30  
31  import static org.nuiton.i18n.I18n.t;
32  
33  /**
34   * <p>EditPmfmDialogUIHandler class.</p>
35   *
36   */
37  public class EditPmfmDialogUIHandler extends AbstractReefDbUIHandler<EditPmfmDialogUIModel, EditPmfmDialogUI> implements Cancelable {
38  
39      /** {@inheritDoc} */
40      @Override
41      public void beforeInit(EditPmfmDialogUI ui) {
42          super.beforeInit(ui);
43  
44          EditPmfmDialogUIModel model = new EditPmfmDialogUIModel();
45          ui.setContextValue(model);
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public void afterInit(EditPmfmDialogUI editPmfmDialogUI) {
51          initUI(ui);
52  
53          initBeanFilterableComboBox(
54                  getUI().getAnalysteCombo(),
55                  getContext().getReferentialService().getDepartments(),
56                  null);
57  
58          getModel().addPropertyChangeListener(EditPmfmDialogUIModel.PROPERTY_TABLE_MODEL, evt -> {
59  
60              // initialize ui with selected pmfm strategy
61              PmfmStrategyDTO pmfmStrategy = getModel().getTableModel().getSingleSelectedRow() != null ? getModel().getTableModel().getSingleSelectedRow().toBean() : null;
62              getModel().fromBean(pmfmStrategy);
63          });
64      }
65  
66  
67      /**
68       * <p>valid.</p>
69       */
70      public void valid() {
71  
72          // check analyst
73          if (getModel().getAnalysisDepartment() == null) {
74              getContext().getDialogHelper().showErrorDialog(
75                      getUI(),
76                      t("reefdb.program.pmfm.edit.error.analyst.message"),
77                      t("reefdb.program.pmfm.edit.error.titre"));
78  
79              return;
80          }
81  
82          // set properties to all selected pmfm strategies
83          for (final PmfmStrategyDTO psfmProgStra : getModel().getTableModel().getSelectedRows()) {
84              psfmProgStra.setAnalysisDepartment(getModel().getAnalysisDepartment());
85              psfmProgStra.setSurvey(getModel().isSurvey());
86              psfmProgStra.setSampling(getModel().isSampling());
87              psfmProgStra.setGrouping(getModel().isGrouping());
88              psfmProgStra.setUnique(getModel().isUnique());
89          }
90  
91          // Quitter la dialogue
92          closeDialog();
93      }
94  
95      /**
96       * <p>forceIsLocal.</p>
97       *
98       * @param local a {@link java.lang.Boolean} object.
99       */
100     public void forceIsLocal(Boolean local) {
101         StatusFilter statusFilter = StatusFilter.toActiveLocalOrNational(local);
102         getUI().getAnalysteCombo().setData(getContext().getReferentialService().getDepartments(statusFilter));
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public void cancel() {
108         closeDialog();
109     }
110 }