View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.rule.rulelist;
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.DaliBeans;
27  import fr.ifremer.dali.dto.configuration.control.RuleListDTO;
28  import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
29  
30  import static org.nuiton.i18n.I18n.t;
31  
32  /**
33   * Action permettant de supprimer une observation dans le tableau des observations de l ecran d accueil.
34   */
35  public class DeleteRuleListAction extends AbstractDaliAction<RuleListUIModel, RuleListUI, RuleListUIHandler> {
36      
37      /**
38       * Constructor.
39       *
40       * @param handler Le controleur
41       */
42      public DeleteRuleListAction(final RuleListUIHandler handler) {
43  		super(handler, false);
44  	}
45  
46  	/** {@inheritDoc} */
47  	@Override
48      public boolean prepareAction() throws Exception {
49          return super.prepareAction() && checkReadOnlyRuleLists() && askBeforeDelete(
50                  t("dali.action.delete.confirm.title"),
51                  t("dali.rule.ruleList.delete.message"));
52      }
53  
54      private boolean checkReadOnlyRuleLists() {
55          // return true if at least one rule list is read only
56          if (getModel().getSelectedRows().stream().anyMatch(RuleListDTO::isReadOnly)) {
57              getContext().getDialogHelper().showWarningDialog(
58                      t("dali.rule.ruleList.delete.readOnly.message"),
59                      t("quadrige3.error.business.warning")
60              );
61              return false;
62          }
63  	    return true;
64      }
65  
66      /** {@inheritDoc} */
67  	@Override
68  	public void doAction() throws Exception {
69          getContext().getRuleListService().deleteRuleLists(
70                  getContext().getAuthenticationInfo(),
71                  DaliBeans.collectProperties(getModel().getSelectedRows(), RuleListDTO.PROPERTY_CODE));
72          getModel().deleteSelectedRows();
73  	}
74  
75      /** {@inheritDoc} */
76      @Override
77      public void postSuccessAction() {
78          // reload combobox
79          getHandler().getRulesUI().getRulesMenuUI().getHandler().reloadComboBox();
80      }
81  }