1 package fr.ifremer.quadrige2.ui.swing.common.synchro.action;
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.synchro.SynchroDirection;
28 import fr.ifremer.quadrige2.ui.swing.common.synchro.SynchroUIHandler;
29
30 /**
31 * <p>SynchroStopAction class.</p>
32 *
33 * @author Ludovic Pecquot <ludovic.pecquot@e-is.pro>
34 */
35 public class SynchroStopAction extends AbstractSynchroAction {
36
37 private AbstractSynchroAction nextAction;
38
39 /**
40 * <p>Constructor for SynchroStopAction.</p>
41 *
42 * @param handler a {@link SynchroUIHandler} object.
43 */
44 public SynchroStopAction(SynchroUIHandler handler) {
45 super(handler);
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 public boolean initAction() {
51 super.initAction();
52
53 // try to stop only if a synchronisation is running
54 return getModel().isRunningStatus();
55
56 }
57
58 /** {@inheritDoc} */
59 @Override
60 public void doAction() throws Exception {
61
62 if (getModel().getDirection() == SynchroDirection.IMPORT) {
63 nextAction = getContext().getActionFactory().createNonBlockingUIAction(handler, ImportSynchroStopAction.class);
64 } else if (getModel().getDirection() == SynchroDirection.EXPORT) {
65 nextAction = getContext().getActionFactory().createNonBlockingUIAction(handler, ExportSynchroStopAction.class);
66 }
67
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 public void doneAction() {
73 if (nextAction != null) {
74 nextAction.execute();
75 }
76 }
77
78 }