1 package fr.ifremer.tutti.ui.swing.content.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import fr.ifremer.tutti.persistence.ProgressionModel;
26 import fr.ifremer.tutti.ui.swing.TuttiScreen;
27 import fr.ifremer.tutti.ui.swing.TuttiUIContext;
28 import fr.ifremer.tutti.ui.swing.content.MainUIHandler;
29 import jaxx.runtime.SwingUtil;
30 import jaxx.runtime.context.JAXXContextEntryDef;
31
32 import java.beans.PropertyVetoException;
33
34 import static org.nuiton.i18n.I18n.t;
35
36
37
38
39
40
41
42
43
44
45 public abstract class AbstractChangeScreenAction extends AbstractMainUITuttiAction {
46
47
48
49
50
51
52 protected static final JAXXContextEntryDef<TuttiScreen> PREVIOUS_SCREEN =
53 SwingUtil.newContextEntryDef("previousScreen", TuttiScreen.class);
54
55
56
57
58
59
60 protected TuttiScreen screen;
61
62
63
64
65
66
67 protected boolean skipCheckCurrentScreen;
68
69 protected AbstractChangeScreenAction(MainUIHandler handler, boolean hideBody, TuttiScreen screen) {
70 super(handler, hideBody);
71 this.screen = screen;
72 }
73
74 public void setSkipCheckCurrentScreen(boolean skipCheckCurrentScreen) {
75 this.skipCheckCurrentScreen = skipCheckCurrentScreen;
76 }
77
78 protected void setScreen(TuttiScreen screen) {
79 this.screen = screen;
80 }
81
82 @Override
83 public boolean prepareAction() throws Exception {
84 boolean result = super.prepareAction();
85 result &= skipCheckCurrentScreen || getHandler().quitCurrentScreen();
86 return result;
87 }
88
89 @Override
90 public void doAction() throws Exception {
91
92 TuttiUIContext context = getContext();
93
94 TuttiScreen previousScreen = context.getScreen();
95 if (getUI() != null) {
96 if (previousScreen == null) {
97 PREVIOUS_SCREEN.removeContextValue(getUI());
98 } else {
99 PREVIOUS_SCREEN.setContextValue(getUI(), previousScreen);
100 }
101 }
102
103
104 context.setScreen(null);
105
106
107 context.setScreen(screen);
108 }
109
110 @Override
111 public void postFailedAction(Throwable error) {
112 if (error != null && !(error instanceof PropertyVetoException)) {
113
114 getContext().setFallBackScreen();
115 }
116 }
117
118 protected void loadReferantials(boolean createProgressionModel) {
119
120
121 ProgressionModel progressionModel;
122
123 if (createProgressionModel) {
124
125 progressionModel = new ProgressionModel();
126 progressionModel.setTotal(5);
127 setProgressionModel(progressionModel);
128
129 } else {
130
131 progressionModel = getProgressionModel();
132
133 }
134
135 progressionModel.increments(t("tutti.openScreen.step.loading.allGear"));
136 getContext().getPersistenceService().getAllGear();
137
138 progressionModel.increments(t("tutti.openScreen.step.loading.allPerson"));
139 getContext().getPersistenceService().getAllPerson();
140
141 progressionModel.increments(t("tutti.openScreen.step.loading.allSpecies"));
142 getContext().getPersistenceService().getAllSpecies();
143
144 progressionModel.increments(t("tutti.openScreen.step.loading.allVessel"));
145 getContext().getPersistenceService().getAllVessel();
146
147 progressionModel.increments(t("tutti.openScreen.step.loading.ui"));
148
149 }
150
151 protected void loadReferantialsWithObsoletes(boolean createProgressionModel) {
152
153 ProgressionModel progressionModel;
154
155 if (createProgressionModel) {
156
157 progressionModel = new ProgressionModel();
158 progressionModel.setTotal(9);
159 setProgressionModel(progressionModel);
160
161 } else {
162
163 progressionModel = getProgressionModel();
164
165 }
166
167 progressionModel.increments(t("tutti.openScreen.step.loading.allGear"));
168 getContext().getPersistenceService().getAllGear();
169
170 progressionModel.increments(t("tutti.openScreen.step.loading.allGearWithObsoletes"));
171 getContext().getPersistenceService().getAllGearWithObsoletes();
172
173 progressionModel.increments(t("tutti.openScreen.step.loading.allPerson"));
174 getContext().getPersistenceService().getAllPerson();
175
176 progressionModel.increments(t("tutti.openScreen.step.loading.allPersonWithObsoletes"));
177 getContext().getPersistenceService().getAllPersonWithObsoletes();
178
179 progressionModel.increments(t("tutti.openScreen.step.loading.allSpecies"));
180 getContext().getPersistenceService().getAllSpecies();
181
182 progressionModel.increments(t("tutti.openScreen.step.loading.allSpeciesWithObsoletes"));
183 getContext().getPersistenceService().getAllReferentSpeciesWithObsoletes();
184
185 progressionModel.increments(t("tutti.openScreen.step.loading.allVessel"));
186 getContext().getPersistenceService().getAllVessel();
187
188 progressionModel.increments(t("tutti.openScreen.step.loading.allVesselWithObsoletes"));
189 getContext().getPersistenceService().getAllVesselWithObsoletes();
190
191 progressionModel.increments(t("tutti.openScreen.step.loading.ui"));
192
193 }
194
195 }