1 package fr.ifremer.quadrige3.ui.swing.action;
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.ui.swing.Application;
28 import fr.ifremer.quadrige3.ui.swing.content.AbstractMainUIHandler;
29
30 import java.util.Locale;
31
32 import static org.nuiton.i18n.I18n.t;
33
34
35
36
37 public abstract class AbstractChangeLocaleAction extends AbstractChangeScreenAction {
38
39
40
41
42
43
44 protected AbstractChangeLocaleAction(AbstractMainUIHandler handler) {
45 super(handler, true, null);
46 }
47
48
49
50
51
52
53 protected abstract Locale getLocale();
54
55 @Override
56 public boolean prepareAction() throws Exception {
57 if (!super.prepareAction()) return false;
58
59 if (getLocale() == null || getLocale().equals(getModel().getLocale())) {
60 return false;
61 }
62
63 createProgressionUIModel();
64
65
66 getModel().setLocale(getLocale());
67
68
69 setActionDescription(t("quadrige3.action.changeLocale.title"));
70
71 return true;
72 }
73
74
75 @Override
76 public void doAction() throws InterruptedException {
77
78 getProgressionUIModel().setMessage(t("quadrige3.action.changeLocale.apply", getLocale()));
79
80
81 getContext().clearCaches();
82
83
84 Thread.sleep(2000);
85
86 }
87
88 @Override
89 public void postSuccessAction() {
90
91
92 CloseApplicationAction action = getContext().getActionFactory().createLogicAction(
93 getHandler(), CloseApplicationAction.class);
94 action.setExitCode(Application.UPDATE_EXIT_CODE);
95 getActionEngine().runAction(action);
96
97 }
98 }