1 package fr.ifremer.quadrige3.ui.swing.synchro.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import fr.ifremer.quadrige3.ui.swing.action.AbstractMainUIAction;
28 import fr.ifremer.quadrige3.ui.swing.content.AbstractMainUIHandler;
29 import fr.ifremer.quadrige3.ui.swing.model.ProgressionUIModel;
30 import fr.ifremer.quadrige3.ui.swing.synchro.SynchroDirection;
31 import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIContext;
32 import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIHandler;
33
34
35
36
37
38
39
40 public class ImportDataSynchroAtOnceAction extends AbstractMainUIAction {
41
42
43
44
45
46
47 public ImportDataSynchroAtOnceAction(AbstractMainUIHandler handler) {
48 super(handler, true);
49 }
50
51
52 @Override
53 public void doAction() throws Exception {
54
55
56 ImportSynchroCheckAction checkAction = getContext().getActionFactory().createNonBlockingUIAction(getSynchroHandler(), ImportSynchroCheckAction.class);
57 checkAction.executeAndWait();
58 boolean needDataImport = getSynchroUIContext().getSynchroImportContext().isWithData();
59
60
61
62 if (!needDataImport) {
63 return;
64 }
65
66
67 SynchroDirection previousDirection = getSynchroUIContext().getDirection();
68 getSynchroUIContext().setDirection(SynchroDirection.IMPORT);
69
70
71 if (getConfig().isSynchronizationUsingServer()) {
72
73 ProgressionUIModel previousProgressionModel = getProgressionUIModel();
74 setProgressionUIModel(getSynchroUIContext().getProgressionModel());
75 getProgressionUIModel().setTotal(50);
76
77
78 AbstractSynchroAction action = getContext().getActionFactory().createNonBlockingUIAction(getSynchroHandler(), ImportSynchroStartAction.class);
79 action.executeAndWait();
80
81
82 action = getContext().getActionFactory().createNonBlockingUIAction(getSynchroHandler(), ImportSynchroDownloadAction.class);
83 action.executeAndWait();
84
85
86 ImportSynchroApplyAction importAction = getActionFactory().createLogicAction(handler, ImportSynchroApplyAction.class);
87 importAction.setSilent(true);
88 importAction.setSkipScreenReload(true);
89 if (importAction.prepareAction()) {
90 getActionEngine().runInternalAction(importAction);
91 }
92
93 setProgressionUIModel(previousProgressionModel);
94 } else {
95
96 ImportSynchroDirectAction importAction = getActionFactory().createLogicAction(getSynchroHandler(), ImportSynchroDirectAction.class);
97 if (importAction.prepareAction()) {
98 getActionEngine().runInternalAction(importAction);
99 }
100 }
101
102
103 getSynchroUIContext().setDirection(previousDirection);
104 }
105
106 private SynchroUIContext getSynchroUIContext() {
107 return getContext().getSynchroContext();
108 }
109
110 private SynchroUIHandler getSynchroHandler() {
111 return getContext().getSynchroHandler();
112 }
113
114 }