1 package fr.ifremer.dali.ui.swing.content.manage.rule.rulelist;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
34
35 public class DeleteRuleListAction extends AbstractDaliAction<RuleListUIModel, RuleListUI, RuleListUIHandler> {
36
37
38
39
40
41
42 public DeleteRuleListAction(final RuleListUIHandler handler) {
43 super(handler, false);
44 }
45
46
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
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
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
76 @Override
77 public void postSuccessAction() {
78
79 getHandler().getRulesUI().getRulesMenuUI().getHandler().reloadComboBox();
80 }
81 }