1 package fr.ifremer.dali.ui.swing.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 import fr.ifremer.dali.ui.swing.content.DaliMainUIHandler;
27 import fr.ifremer.quadrige3.ui.swing.action.AbstractMainUIAction;
28 import fr.ifremer.quadrige3.ui.swing.action.GoToHomeAction;
29 import fr.ifremer.quadrige3.ui.swing.action.GoToManageDbAction;
30 import fr.ifremer.quadrige3.ui.swing.content.db.OpenDbAction;
31
32 import static org.nuiton.i18n.I18n.t;
33
34
35
36
37
38
39
40
41 public class StartAction extends AbstractDaliMainUIAction {
42
43 private AbstractMainUIAction delegateAction;
44
45
46
47
48
49
50 public StartAction(DaliMainUIHandler handler) {
51 super(handler, true);
52 setActionDescription(t("dali.main.action.startDali"));
53 }
54
55
56 @Override
57 public boolean prepareAction() throws Exception {
58 super.prepareAction();
59
60 if (getContext().isPersistenceLoaded()) {
61
62
63 GoToHomeAction action = getContext().getActionFactory().createLogicAction(handler, GoToHomeAction.class);
64 action.setSkipCheckCurrentScreen(true);
65 delegateAction = action;
66
67 } else {
68
69 if (getContext().isDbExist()) {
70
71 OpenDbAction action = getContext().getActionFactory().createLogicAction(handler, OpenDbAction.class);
72 action.setSkipCheckCurrentScreen(true);
73 delegateAction = action;
74
75 } else {
76
77
78 getContext().clearDbContext();
79
80
81 GoToManageDbAction action = getContext().getActionFactory().createLogicAction(handler, GoToManageDbAction.class);
82 action.setSkipCheckCurrentScreen(true);
83 delegateAction = action;
84 }
85 }
86
87 setActionDescription(delegateAction.getActionDescription());
88 return delegateAction.prepareAction();
89 }
90
91
92 @Override
93 public void doAction() throws Exception {
94 getActionEngine().runInternalAction(delegateAction);
95 }
96
97
98 @Override
99 protected void releaseAction() {
100 delegateAction = null;
101 super.releaseAction();
102 }
103
104 }