1 package fr.ifremer.quadrige3.ui.swing.synchro.resolver;
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
27 import fr.ifremer.quadrige3.synchro.service.client.NotExportableRowStatus;
28 import fr.ifremer.quadrige3.synchro.service.client.NotExportableRowStrategy;
29 import fr.ifremer.quadrige3.synchro.service.client.SynchroNotExportableRowResolver;
30 import fr.ifremer.quadrige3.ui.swing.DialogHelper;
31
32 import javax.swing.JOptionPane;
33 import javax.swing.SwingUtilities;
34
35 import static org.nuiton.i18n.I18n.t;
36
37
38
39
40
41
42 public class SynchroNotExportableRowUIResolver implements SynchroNotExportableRowResolver {
43
44
45 private final DialogHelper dialogHelper;
46
47
48
49
50
51
52 public SynchroNotExportableRowUIResolver(DialogHelper dialogHelper) {
53 this.dialogHelper = dialogHelper;
54 }
55
56
57 @Override
58 public NotExportableRowStrategy getStrategy(final NotExportableRowStatus status, final String rejectMessage) {
59
60 NotExportableRowStrategy rejectedRowStrategy = NotExportableRowStrategy.CANCEL;
61 int dialogResult;
62
63
64 if (status == NotExportableRowStatus.RECORDED_BY_USER) {
65
66 dialogResult = dialogHelper.showConfirmDialog(
67 t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_USER.message"),
68 rejectMessage,
69 t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_USER.help"),
70 t("quadrige3.action.synchro.export.notExportable.title"),
71 JOptionPane.YES_NO_CANCEL_OPTION);
72 switch (dialogResult) {
73 case JOptionPane.YES_OPTION:
74 rejectedRowStrategy = NotExportableRowStrategy.KEEP_LOCAL;
75 break;
76 case JOptionPane.NO_OPTION:
77 rejectedRowStrategy = NotExportableRowStrategy.DELETE;
78 break;
79 case JOptionPane.CANCEL_OPTION:
80 rejectedRowStrategy = NotExportableRowStrategy.CANCEL;
81 break;
82 }
83 }
84
85
86 else if (status == NotExportableRowStatus.RECORDED_BY_OTHER) {
87
88
89 SwingUtilities.invokeLater(() -> dialogHelper.showWarningDialog(
90 t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_OTHER.message"),
91 rejectMessage,
92 t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_OTHER.help"),
93 t("quadrige3.action.synchro.export.notExportable.title")));
94
95 rejectedRowStrategy = NotExportableRowStrategy.KEEP_LOCAL;
96 }
97
98
99 else if (status == NotExportableRowStatus.DIRTY_AND_OLD) {
100
101
102 SwingUtilities.invokeLater(() -> dialogHelper.showWarningDialog(
103 t("quadrige3.action.synchro.export.notExportable.DIRTY_AND_OLD.message"),
104 rejectMessage,
105 t("quadrige3.action.synchro.export.notExportable.DIRTY_AND_OLD.help"),
106 t("quadrige3.action.synchro.export.notExportable.title")));
107
108 rejectedRowStrategy = NotExportableRowStrategy.KEEP_LOCAL;
109 }
110
111 return rejectedRowStrategy;
112 }
113
114 }