1 package org.wcb.gui.forms.wizard;
2
3 import org.wcb.gui.component.JXTitlePanel;
4 import org.wcb.gui.renderer.AircraftTypeListCellRender;
5 import org.wcb.model.vo.hibernate.AircraftTypeBO;
6 import org.wcb.model.vo.hibernate.Logbook;
7 import org.wcb.model.vo.hibernate.AircraftBO;
8 import org.wcb.model.bd.AircraftDelegate;
9 import org.wcb.model.bd.LogbookDelegate;
10 import org.wcb.model.util.SpringUtil;
11 import org.wcb.model.service.IServicesConstants;
12 import org.jdesktop.swingx.border.DropShadowBorder;
13 import org.jdesktop.swingx.VerticalLayout;
14 import org.apache.commons.lang.StringUtils;
15
16 import javax.swing.border.Border;
17 import javax.swing.border.CompoundBorder;
18 import javax.swing.*;
19 import java.awt.event.ItemEvent;
20 import java.awt.event.ItemListener;
21 import java.awt.*;
22 import java.util.Date;
23 import java.text.DecimalFormat;
24
25 import com.toedter.calendar.JDateChooser;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class Step5of8710Wizard extends JXTitlePanel implements ItemListener {
54
55 private JPanel displayPanel;
56 private final DecimalFormat formatter = new DecimalFormat("###,##0.0");
57
58 public Step5of8710Wizard() {
59 super("Step 5 of 6 - Basis for Application", new Color(0x3779ff));
60 Border shadow = new DropShadowBorder(Color.BLACK, 1, 5, .3f, 15, true, true, true, true);
61 setBorder(new CompoundBorder(shadow, getBorder()));
62 initComponents();
63 }
64
65
66
67
68
69
70 private void initComponents() {
71 completionOfTestRb = new JRadioButton("Completion of Required Test", true);
72 militaryComplianceRb = new JRadioButton("Military Competence Obtained in", false);
73 graduationOfCourseRb = new JRadioButton("Graduate of Approved Course", false);
74 holderForeignLicenseRb = new JRadioButton("Holder of Foreign License Issued By", false);
75 yesRb = new JRadioButton("Yes", false);
76 noRb = new JRadioButton("No", true);
77 completionOfTestRb.addItemListener(this);
78 militaryComplianceRb.addItemListener(this);
79 graduationOfCourseRb.addItemListener(this);
80 holderForeignLicenseRb.addItemListener(this);
81
82 picTimeTf = new JTextField(5);
83 totalTimeInAircraftTf = new JTextField(5);
84 aircraftToBeUsedCB = new JComboBox(this.getAircraftTypes().toArray());
85 aircraftToBeUsedCB.setRenderer(new AircraftTypeListCellRender());
86 aircraftToBeUsedCB.addItemListener(this);
87
88 serviceTf = new JTextField(10);
89 dateRated = new JDateChooser();
90 rankTf = new JTextField(10);
91 serviceNumberTf = new JTextField(10);
92 militaryAircraftTf = new JTextField(10);
93 militaryAircraftCheckTf = new JTextField(10);
94
95
96 setLayout(new java.awt.BorderLayout());
97 displayPanel = new JPanel(new CardLayout());
98 displayPanel.add(this.getCompletionTestPanel(), "a");
99 displayPanel.add(this.getMilitaryPanel(), "b");
100 displayPanel.add(this.getGraduateCoursePanel(), "c");
101 displayPanel.add(this.getForeignLicensePanel(), "d");
102
103
104 add(displayPanel, java.awt.BorderLayout.CENTER);
105 add(getBasisApplicationPanel(), java.awt.BorderLayout.NORTH);
106
107 }
108
109 private JPanel getCompletionTestPanel() {
110 JPanel certificatePanel = new JPanel();
111 certificatePanel.setBorder(BorderFactory.createTitledBorder("Completion of required test"));
112
113 certificatePanel.setLayout(new java.awt.GridBagLayout());
114
115 GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
116 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117 certificatePanel.add(new JLabel("1. AircraftBO to be used(if flight test required)"), gridBagConstraints);
118
119 gridBagConstraints = new java.awt.GridBagConstraints();
120 gridBagConstraints.ipadx = 3;
121 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122 certificatePanel.add(aircraftToBeUsedCB, gridBagConstraints);
123
124 gridBagConstraints = new java.awt.GridBagConstraints();
125 gridBagConstraints.gridx = 0;
126 gridBagConstraints.gridy = 1;
127 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
128 certificatePanel.add(new JLabel("2a. Total time in this aircraft/SIM/FTD"), gridBagConstraints);
129
130 gridBagConstraints = new java.awt.GridBagConstraints();
131 gridBagConstraints.gridx = 1;
132 gridBagConstraints.gridy = 1;
133 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
134 certificatePanel.add(totalTimeInAircraftTf, gridBagConstraints);
135
136 gridBagConstraints = new java.awt.GridBagConstraints();
137 gridBagConstraints.gridx = 0;
138 gridBagConstraints.gridy = 2;
139 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140 certificatePanel.add(new JLabel("2b. Pilot In command"), gridBagConstraints);
141
142 gridBagConstraints = new java.awt.GridBagConstraints();
143 gridBagConstraints.gridx = 1;
144 gridBagConstraints.gridy = 2;
145 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146 certificatePanel.add(picTimeTf, gridBagConstraints);
147 return certificatePanel;
148 }
149
150 private JPanel getBasisApplicationPanel() {
151 JPanel physicalInfoPanel = new JPanel();
152 physicalInfoPanel.setBorder(BorderFactory.createTitledBorder("Certificate or Rating Applied For on Basis of:"));
153
154 physicalInfoPanel.setLayout(new VerticalLayout());
155 ButtonGroup group = new ButtonGroup();
156 group.add(completionOfTestRb);
157 group.add(militaryComplianceRb);
158 group.add(graduationOfCourseRb);
159 group.add(holderForeignLicenseRb);
160 physicalInfoPanel.add(completionOfTestRb);
161 physicalInfoPanel.add(militaryComplianceRb);
162 physicalInfoPanel.add(graduationOfCourseRb);
163 physicalInfoPanel.add(holderForeignLicenseRb);
164
165 JPanel failedTestPanel = new JPanel(new GridLayout());
166 ButtonGroup yesNoGroup = new ButtonGroup();
167 yesNoGroup.add(yesRb);
168 yesNoGroup.add(noRb);
169 GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
170 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
171 failedTestPanel.add(new JLabel("Have you failed a test for this certificate or rating?"), gridBagConstraints);
172
173 gridBagConstraints = new java.awt.GridBagConstraints();
174 gridBagConstraints.ipadx = 3;
175 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
176 failedTestPanel.add(yesRb, gridBagConstraints);
177
178 gridBagConstraints = new java.awt.GridBagConstraints();
179 gridBagConstraints.ipadx = 3;
180 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
181 failedTestPanel.add(noRb, gridBagConstraints);
182
183 physicalInfoPanel.add(failedTestPanel);
184
185 return physicalInfoPanel;
186 }
187
188
189
190
191
192 private JPanel getMilitaryPanel() {
193 JPanel certificatePanel = new JPanel();
194 certificatePanel.setBorder(BorderFactory.createTitledBorder("Military Competence"));
195 certificatePanel.add(new JLabel("Not implemented yet!"));
196 return certificatePanel;
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270 }
271
272
273
274
275
276 private JPanel getGraduateCoursePanel() {
277 JPanel certificatePanel = new JPanel();
278 certificatePanel.setBorder(BorderFactory.createTitledBorder("Graduate of Approved Course"));
279 certificatePanel.add(new JLabel("Not implemented yet!"));
280 return certificatePanel;
281
282 }
283
284
285
286
287
288 private JPanel getForeignLicensePanel() {
289 JPanel certificatePanel = new JPanel();
290 certificatePanel.setBorder(BorderFactory.createTitledBorder("Holder of Foreign License Issued By"));
291 certificatePanel.add(new JLabel("Not implemented yet!"));
292 return certificatePanel;
293
294 }
295
296 public void itemStateChanged(ItemEvent evt) {
297 Object src = evt.getSource();
298 if (completionOfTestRb.isSelected()) {
299 showNextPanel("a");
300 }
301 if (militaryComplianceRb.isSelected()) {
302 showNextPanel("b");
303 }
304 if (graduationOfCourseRb.isSelected()) {
305 showNextPanel("c");
306 }
307 if (holderForeignLicenseRb.isSelected()) {
308 showNextPanel("d");
309 }
310 if(src.equals(aircraftToBeUsedCB)) {
311 this.populateTimeFields();
312 }
313 }
314
315
316
317
318
319
320 private void populateTimeFields() {
321 AircraftTypeBO type = (AircraftTypeBO) aircraftToBeUsedCB.getSelectedItem();
322 String matchAbreviation = trimModelVersion(type.getAbbreviation());
323 LogbookDelegate delegate = (LogbookDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_DELEGATE);
324 java.util.List<Logbook> entries = delegate.getAllLogbookEntries();
325 Double totalTime = 0.0;
326 Double picTime = 0.0;
327 if(type.getModel() != null) {
328 for(Logbook item: entries) {
329 AircraftBO aircraft = delegate.getAircraftForLogEntry(item);
330 AircraftTypeBO aircraftType = delegate.getAircraftType(aircraft);
331 String abname = trimModelVersion(aircraftType.getAbbreviation());
332
333 if (aircraft.getTypeId() == type.getId() || abname.equalsIgnoreCase(matchAbreviation)) {
334 totalTime = totalTime + item.getFlightDuration();
335 picTime = picTime + item.getPic();
336 }
337 }
338 totalTimeInAircraftTf.setText(formatter.format(totalTime));
339 picTimeTf.setText(formatter.format(picTime));
340 }
341 }
342
343
344
345
346
347
348
349 private String trimModelVersion(String aircraftAbrev) {
350 if(StringUtils.trimToNull(aircraftAbrev) != null) {
351 String val = aircraftAbrev.substring(aircraftAbrev.length());
352 if (StringUtils.isAlpha(val)) {
353 return aircraftAbrev.substring(0,aircraftAbrev.length()-1);
354 }
355 }
356 return aircraftAbrev;
357 }
358
359
360
361
362
363 private void showNextPanel(String panelName) {
364 CardLayout cl = (CardLayout) displayPanel.getLayout();
365 cl.show(displayPanel, panelName);
366 }
367
368 public String getTotalTimeInAircraft() {
369 return totalTimeInAircraftTf.getText();
370 }
371
372
373
374
375
376
377
378 public String getAircraftToBeUsed() {
379 AircraftTypeBO type = (AircraftTypeBO) aircraftToBeUsedCB.getSelectedItem();
380 if(type.getAbbreviation() == null) {
381 return "";
382 }
383 return type.getManufacturer() + "/" + trimModelVersion(type.getModel());
384 }
385
386 public String getPICTime() {
387 return picTimeTf.getText();
388 }
389
390
391
392
393
394 public boolean hasFailedCertificate() {
395 return yesRb.isSelected();
396 }
397
398 public String getApplyFor() {
399 if (completionOfTestRb.isSelected()) {
400 return "a";
401 }
402 if (militaryComplianceRb.isSelected()) {
403 return "b";
404 }
405 if (graduationOfCourseRb.isSelected()) {
406 return "c";
407 }
408 if (holderForeignLicenseRb.isSelected()) {
409 return "d";
410 }
411 return "a";
412 }
413
414 public Date getDateRatedMilitary() {
415 return dateRated.getDate();
416 }
417
418 private java.util.List<AircraftTypeBO> getAircraftTypes() {
419 AircraftDelegate delegate = (AircraftDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.AIRCRAFT_DELEGATE);
420 java.util.List<AircraftTypeBO> types = delegate.getAircraftTypes();
421 AircraftTypeBO newType = new AircraftTypeBO("Select One", null, null, -1);
422 types.add(0, newType);
423 return types;
424 }
425
426
427 private JComboBox aircraftToBeUsedCB;
428 private JTextField totalTimeInAircraftTf;
429 private JTextField picTimeTf;
430 private JRadioButton completionOfTestRb;
431 private JRadioButton militaryComplianceRb;
432 private JRadioButton graduationOfCourseRb;
433 private JRadioButton holderForeignLicenseRb;
434
435 private JRadioButton yesRb;
436 private JRadioButton noRb;
437
438 private JTextField serviceTf;
439 private JDateChooser dateRated;
440 private JTextField rankTf;
441 private JTextField serviceNumberTf;
442 private JTextField militaryAircraftTf;
443 private JTextField militaryAircraftCheckTf;
444
445 private JTextField trainingCenterTf;
446 private JTextField certificationNumberTf;
447 private JTextField curriculumTf;
448 private JDateChooser courseDate;
449
450 }