View Javadoc
1   package fr.ifremer.quadrige3.ui.swing.content.db;
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.action.AbstractMainUIAction;
28  import fr.ifremer.quadrige3.ui.swing.content.AbstractMainUIHandler;
29  
30  import static org.nuiton.i18n.I18n.t;
31  
32  /**
33   * To close a db.
34   *
35   * @since 2.4
36   */
37  public class CloseDbAction extends AbstractMainUIAction {
38  
39      private String jdbcUrl;
40  
41      /**
42       * <p>Constructor for CloseDbAction.</p>
43       *
44       * @param handler a {@link AbstractMainUIHandler} object.
45       */
46      public CloseDbAction(AbstractMainUIHandler handler) {
47          super(handler, true);
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public boolean prepareAction() throws Exception {
53  
54          boolean canContinue = super.prepareAction();
55          if (canContinue) {
56              jdbcUrl = getConfig().getJdbcUrl();
57          }
58          return canContinue;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public void doAction() {
64  
65          // close services 
66          getContext().closePersistenceService();
67  
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public void postSuccessAction() {
73          super.postSuccessAction();
74  
75          sendMessage(t("quadrige3.flash.info.db.closed", jdbcUrl));
76  
77          // make sure title is reloaded
78          getHandler().reloadDbManagerText();
79          getHandler().changeTitle();
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public void postFailedAction(Throwable error) {
85          getHandler().reloadDbManagerText();
86          super.postFailedAction(error);
87      }
88  }