1 package fr.ifremer.quadrige3.ui.swing.action;
2
3 /*-
4 * #%L
5 * Quadrige3 Core :: Quadrige3 UI Common
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2017 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * #L%
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 * <p>Abstract AbstractChangeLocaleAction class.</p>
36 */
37 public abstract class AbstractChangeLocaleAction extends AbstractChangeScreenAction {
38
39 /**
40 * <p>Constructor for AbstractChangeLocaleAction.</p>
41 *
42 * @param handler a {@link AbstractMainUIHandler} object.
43 */
44 protected AbstractChangeLocaleAction(AbstractMainUIHandler handler) {
45 super(handler, true, null);
46 }
47
48 /**
49 * <p>getLocale.</p>
50 *
51 * @return a {@link Locale} object.
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 // change locale (and save configuration)
66 getModel().setLocale(getLocale());
67
68 // update action description with new locale (Mantis #47394)
69 setActionDescription(t("quadrige3.action.changeLocale.title"));
70
71 return true;
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public void doAction() throws InterruptedException {
77
78 getProgressionUIModel().setMessage(t("quadrige3.action.changeLocale.apply", getLocale()));
79
80 // clear caches
81 getContext().clearCaches();
82
83 // wait a while to see message
84 Thread.sleep(2000);
85
86 }
87
88 @Override
89 public void postSuccessAction() {
90
91 // Restart application (Mantis #49004)
92 CloseApplicationAction action = getContext().getActionFactory().createLogicAction(
93 getHandler(), CloseApplicationAction.class);
94 action.setExitCode(Application.UPDATE_EXIT_CODE);
95 getActionEngine().runAction(action);
96
97 }
98 }