View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.rule;
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 com.google.common.collect.Lists;
27  import fr.ifremer.dali.ui.swing.action.AbstractDaliRemoteSaveAction;
28  import fr.ifremer.dali.ui.swing.content.manage.rule.menu.SearchAction;
29  import fr.ifremer.quadrige3.core.exception.SaveForbiddenException;
30  import fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil;
31  import fr.ifremer.quadrige3.ui.swing.model.AbstractBeanUIModel;
32  import org.apache.commons.collections4.CollectionUtils;
33  
34  import java.util.List;
35  
36  import static org.nuiton.i18n.I18n.t;
37  
38  /**
39   * Save rule list action
40   */
41  public class SaveAction extends AbstractDaliRemoteSaveAction<RulesUIModel, RulesUI, RulesUIHandler> {
42  
43      /**
44       * Constructor.
45       *
46       * @param handler Controller
47       */
48      public SaveAction(final RulesUIHandler handler) {
49          super(handler, false);
50      }
51  
52      @Override
53      protected void doSave() {
54  
55          // service call
56          getContext().getRuleListService().saveRuleLists(getContext().getAuthenticationInfo(), getModel().getRuleListUIModel().getRows());
57      }
58  
59      @Override
60      protected void reload() {
61  
62          // If control rules in table, force newCode state to false (Mantis #46454)
63          if (getModel().getControlRuleUIModel().getRowCount() > 0) {
64              getModel().getControlRuleUIModel().getRows().forEach(controlRuleRowModel -> controlRuleRowModel.setNewCode(false));
65          }
66  
67          // reload ComboBox
68          getUI().getRulesMenuUI().getHandler().reloadComboBox();
69  
70          // reload rules
71          getActionEngine().runInternalAction(getUI().getRulesMenuUI().getHandler(), SearchAction.class);
72      }
73  
74      @Override
75      protected void onSaveForbiddenException(SaveForbiddenException exception) {
76  
77          if (CollectionUtils.isNotEmpty(exception.getObjectIds())) {
78              getContext().getDialogHelper().showErrorDialog(
79                      t("dali.action.save.rules.forbidden.topMessage"),
80                      ApplicationUIUtil.getHtmlString(exception.getObjectIds()),
81                      t("dali.action.save.rules.forbidden.bottomMessage"),
82                      t("dali.action.save.errors.title"));
83          } else {
84              getContext().getDialogHelper().showErrorDialog(
85                      t("dali.action.save.rules.forbidden.message"),
86                      t("dali.action.save.errors.title"));
87          }
88  
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      protected List<AbstractBeanUIModel> getModelsToModify() {
94          List<AbstractBeanUIModel> models = Lists.newArrayList();
95          models.add(getModel().getRuleListUIModel());
96          models.add(getModel().getProgramsUIModel());
97          models.add(getModel().getDepartmentsUIModel());
98          models.add(getModel().getControlRuleUIModel());
99          models.add(getModel().getPmfmUIModel());
100         return models;
101     }
102 
103 }