View Javadoc
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  import fr.ifremer.quadrige3.ui.swing.Application;
27  import fr.ifremer.quadrige3.ui.swing.content.AbstractMainUIHandler;
28  
29  import static org.nuiton.i18n.I18n.t;
30  
31  /**
32   * To close Application.
33   *
34   * @since 1.1
35   */
36  public class CloseApplicationAction extends AbstractChangeScreenAction {
37  
38      private int exitCode = Application.NORMAL_EXIT_CODE;
39  
40      /**
41       * <p>Constructor for CloseApplicationAction.</p>
42       *
43       * @param handler a {@link AbstractMainUIHandler} object.
44       */
45      public CloseApplicationAction(AbstractMainUIHandler handler) {
46          super(handler, false, null);
47          setSkipCheckCurrentScreen(false);
48          setActionDescription(t("quadrige3.main.action.exit.tip"));
49      }
50  
51      /**
52       * <p>Setter for the field <code>exitCode</code>.</p>
53       *
54       * @param exitCode a int.
55       */
56      public void setExitCode(int exitCode) {
57          this.exitCode = exitCode;
58          switch (exitCode) {
59              case Application.NORMAL_EXIT_CODE:
60                  forceActionDescription(t("quadrige3.main.action.exit.tip"));
61                  break;
62              case Application.UPDATE_EXIT_CODE:
63                  forceActionDescription(t("quadrige3.main.action.restart.tip"));
64                  break;
65          }
66      }
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      public void doAction() throws Exception {
73          super.doAction();
74  
75          createProgressionUIModel();
76          switch (exitCode) {
77              case Application.NORMAL_EXIT_CODE:
78                  getProgressionUIModel().setMessage(t("quadrige3.main.action.exit.message"));
79                  break;
80              case Application.UPDATE_EXIT_CODE:
81                  getProgressionUIModel().setMessage(t("quadrige3.main.action.restart.message"));
82                  break;
83          }
84  
85          // Close synchro widget
86          if (getContext().getSynchroHandler() != null)
87              getContext().getSynchroHandler().hidePopup();
88  
89          // Close main UI
90          getHandler().closeUI();
91  
92          // Exit
93          Application.exit(exitCode);
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public void releaseAction() {
101         exitCode = Application.NORMAL_EXIT_CODE;
102         super.releaseAction();
103     }
104 }