1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.user.local.replace;
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.reefdb.dto.referential.PersonDTO;
27 import fr.ifremer.reefdb.service.referential.ReferentialService;
28 import fr.ifremer.reefdb.ui.swing.content.manage.referential.replace.AbstractReplaceAction;
29 import fr.ifremer.reefdb.ui.swing.content.manage.referential.user.ManageUsersUI;
30
31 import javax.swing.*;
32
33 import static org.nuiton.i18n.I18n.t;
34
35
36
37
38 public class ReplaceUserAction extends AbstractReplaceAction<PersonDTO, ReplaceUserUIModel, ReplaceUserUI, ReplaceUserUIHandler> {
39
40
41
42
43
44
45 public ReplaceUserAction(ReplaceUserUIHandler handler) {
46 super(handler);
47 }
48
49
50 @Override
51 protected String getReferentialLabel() {
52 return t("reefdb.property.user");
53 }
54
55
56 @Override
57 protected boolean prepareReplaceReferential(ReferentialService service, PersonDTO source, PersonDTO target) {
58
59 if (service.isUserUsedInProgram(source.getId())) {
60 String decoratedSource = decorate(source);
61 if (getContext().getDialogHelper().showConfirmDialog(getReplaceUI(), t("reefdb.replaceReferential.used.programStrategy.message", decoratedSource, decoratedSource),
62 getReplaceUI().getTitle(), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
63 return false;
64 }
65 setDelete(false);
66 }
67
68 if (service.isUserUsedInRules(source.getId())) {
69 String decoratedSource = decorate(source);
70 if (getContext().getDialogHelper().showConfirmDialog(getReplaceUI(), t("reefdb.replaceReferential.used.controlRules.message", decoratedSource, decoratedSource),
71 getReplaceUI().getTitle(), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
72 return false;
73 }
74 setDelete(false);
75 }
76
77 if (service.isUserUsedInValidatedData(source.getId())) {
78 String decoratedSource = decorate(source);
79 if (getContext().getDialogHelper().showConfirmDialog(getReplaceUI(), t("reefdb.replaceReferential.used.validatedData.message", decoratedSource, decoratedSource),
80 getReplaceUI().getTitle(), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
81 return false;
82 }
83 setDelete(false);
84 }
85
86 return true;
87 }
88
89
90 @Override
91 protected void replaceReferential(ReferentialService service, PersonDTO source, PersonDTO target, boolean delete) {
92
93 service.replaceUser(source, target, delete);
94 }
95
96
97 @Override
98 protected void resetCaches() {
99 }
100
101
102 @Override
103 public void postSuccessAction() {
104 super.postSuccessAction();
105
106 final ManageUsersUI usersLocalUI = (ManageUsersUI) getContext().getMainUI().getHandler().getCurrentBody();
107
108 if (usersLocalUI != null) {
109 SwingUtilities.invokeLater(() -> getActionEngine().runAction(usersLocalUI.getManageUsersLocalUI().getUserMenuUI().getSearchButton()));
110 }
111
112 }
113 }