1 package fr.ifremer.quadrige2.ui.swing.common.content.db;
2
3 /*-
4 * #%L
5 * Quadrige2 Core :: Quadrige2 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.quadrige2.ui.swing.common.action.AbstractMainUIAction;
28 import fr.ifremer.quadrige2.ui.swing.common.content.AbstractMainUIHandler;
29
30 /**
31 * To install or reinstall a db (will delegate to correct action).
32 *
33 * @since 2.4
34 */
35 public class InstallOrReinstallDbAction extends AbstractMainUIAction {
36
37 protected AbstractMainUIAction delegateAction;
38
39 /**
40 * <p>Constructor for InstallOrReinstallDbAction.</p>
41 *
42 * @param handler a {@link AbstractMainUIHandler} object.
43 */
44 public InstallOrReinstallDbAction(AbstractMainUIHandler handler) {
45 super(handler, true);
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 public boolean prepareAction() throws Exception {
51
52 if (getContext().isDbExist()) {
53
54 // reinstall action
55 delegateAction = getContext().getActionFactory().createLogicAction(getHandler(), ReinstallDbAction.class);
56 } else {
57
58 // install action
59 delegateAction = getContext().getActionFactory().createLogicAction(getHandler(), InstallDbAction.class);
60 }
61
62 setActionDescription(delegateAction.getActionDescription());
63
64 return delegateAction.prepareAction();
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 public void doAction() throws Exception {
70
71 getActionEngine().runInternalAction(delegateAction);
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 protected void releaseAction() {
77 delegateAction = null;
78 super.releaseAction();
79 }
80
81 }