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