1 package org.wcb.gui.forms.wizard;
2
3 import org.wcb.gui.component.JCloudPane;
4 import org.wcb.gui.util.PdfFormUtility8710;
5 import org.wcb.gui.util.UIHelper;
6 import org.wcb.model.vo.hibernate.FAA8710ApplicationBO;
7 import org.wcb.model.vo.ApplicationCertificate;
8 import org.wcb.model.util.SpringUtil;
9 import org.wcb.model.service.IServicesConstants;
10 import org.wcb.model.service.impl.LogbookService;
11 import org.wcb.exception.ServiceException;
12
13 import javax.swing.*;
14 import java.awt.*;
15 import java.awt.event.ActionListener;
16 import java.awt.event.ActionEvent;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class FAA8710Wizard extends JPanel implements ActionListener {
46
47 private JPanel centerPanel;
48 private Step1of8710Wizard step1Panel;
49 private Step2of8710Wizard step2Panel;
50 private Step3of8710Wizard step3Panel;
51 private Step4of8710Wizard step4Panel;
52 private Step5of8710Wizard step5Panel;
53 private Step6of8710Wizard step6Panel;
54 private CompletionofWizard completionPanel;
55 private JButton backButton;
56 private JButton nextButton;
57 private int stepCounter;
58 private int MAX_STEPS=6;
59
60 public FAA8710Wizard () {
61 initComponents();
62 stepCounter = 1;
63 }
64
65 private void initComponents() {
66 ImageIcon titleIcon = UIHelper.getIcon("org/wcb/resources/gui/wizard_icon.gif");
67 JLabel wizardLabel = new JLabel(titleIcon);
68 JCloudPane wizard = new JCloudPane();
69 wizard.add(wizardLabel);
70
71 backButton = new JButton("Back");
72 nextButton = new JButton("Next");
73 backButton.addActionListener(this);
74 nextButton.addActionListener(this);
75
76 step1Panel = new Step1of8710Wizard();
77 step2Panel = new Step2of8710Wizard();
78 step3Panel = new Step3of8710Wizard();
79 step4Panel = new Step4of8710Wizard();
80 step5Panel = new Step5of8710Wizard();
81 step6Panel = new Step6of8710Wizard();
82 completionPanel = new CompletionofWizard();
83 completionPanel.setTextToLabel("You have completed your FAA 8710 Form!");
84 centerPanel = new JPanel(new CardLayout());
85 centerPanel.add(step1Panel, "step1");
86 centerPanel.add(step2Panel, "step2");
87 centerPanel.add(step3Panel, "step3");
88 centerPanel.add(step4Panel, "step4");
89 centerPanel.add(step5Panel, "step5");
90 centerPanel.add(step6Panel, "step6");
91 centerPanel.add(completionPanel, "completion");
92
93 JPanel buttonPanel = new JPanel();
94 buttonPanel.add(backButton);
95 buttonPanel.add(nextButton);
96
97 setLayout(new BorderLayout());
98 add(wizardLabel, BorderLayout.WEST);
99 add(centerPanel, BorderLayout.CENTER);
100 add(buttonPanel, BorderLayout.SOUTH);
101 this.loadPanelData();
102 }
103
104 private void loadPanelData(){
105 LogbookService service = (LogbookService) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_SERVICE);
106 try {
107 FAA8710ApplicationBO applicant = service.getApplicant();
108 step2Panel.loadApplicant(applicant);
109 step3Panel.loadApplicant(applicant);
110 step4Panel.loadApplicant(applicant);
111 } catch (ServiceException se) {
112 System.err.println("Unable to load applicant information" + se);
113 }
114 }
115
116 public void actionPerformed(ActionEvent evt) {
117 Object src = evt.getSource();
118 if (src.equals(nextButton)) {
119 if(nextButton.getText().equals("Finish")) {
120 doSavePDF();
121 showNextPanel("completion");
122 nextButton.setEnabled(false);
123 backButton.setEnabled(false);
124 } else {
125 stepCounter = stepCounter + 1;
126 if(stepCounter >= MAX_STEPS) {
127 stepCounter = MAX_STEPS;
128 nextButton.setText("Finish");
129 }
130 showNextPanel("step" + stepCounter);
131 }
132 }
133 if (src.equals(backButton)) {
134 if(nextButton.getText().equals("Finish")) {
135 nextButton.setText("Next");
136 }
137 stepCounter = stepCounter - 1;
138 if (stepCounter < 1) {
139 stepCounter = 1;
140 }
141 showNextPanel("step" + stepCounter);
142 }
143 }
144
145
146
147
148
149 private void showNextPanel(String panelName) {
150 CardLayout cl = (CardLayout) centerPanel.getLayout();
151 cl.show(centerPanel, panelName);
152 }
153
154 private void doSavePDF() {
155 PdfFormUtility8710 pdfUtility = new PdfFormUtility8710();
156
157 FAA8710ApplicationBO applicant;
158 try {
159 LogbookService service = (LogbookService) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_SERVICE);
160 applicant = service.getApplicant();
161 } catch (ServiceException se) {
162 applicant = new FAA8710ApplicationBO();
163 }
164
165 ApplicationCertificate certificateApplying = new ApplicationCertificate();
166 certificateApplying.setAdditionalRatings(step1Panel.isAdditionalRating());
167 certificateApplying.setAirlineTransportRating(step1Panel.isAirlineTransport());
168 certificateApplying.setAirplaneMEL(step1Panel.isAirplaneMEL());
169 certificateApplying.setAirplaneSEL(step1Panel.isAirplaneSEL());
170 certificateApplying.setAirshipRating(step1Panel.isAirshipRating());
171 certificateApplying.setBalloonRating(step1Panel.isBalloonRating());
172 certificateApplying.setCommercialPilot(step1Panel.isCommercialPilot());
173 certificateApplying.setGliderPilot(step1Panel.isGliderPilot());
174 certificateApplying.setInstrumentRating(step1Panel.isInstrumentRating());
175 certificateApplying.setPoweredLift(step1Panel.isPoweredLift());
176 certificateApplying.setPrivatePilot(step1Panel.isPrivate());
177 certificateApplying.setRecreationalPilot(step1Panel.isRecreationalPilot());
178 certificateApplying.setRotocraftRating(step1Panel.isRotocraft());
179 certificateApplying.setStudent(step1Panel.isStudent());
180
181 applicant.setApplyForCertificate(certificateApplying);
182
183
184 applicant.setLastName(step2Panel.getLastName());
185 applicant.setFirstName(step2Panel.getFirstName());
186 applicant.setMiddleName(step2Panel.getMiddleName());
187 applicant.setSsn(step2Panel.getSSN());
188 applicant.setBirthDate(step2Panel.getBirthDate());
189 applicant.setPlaceOfBirth(step2Panel.getPlaceOfBirth());
190 applicant.setAddress(step2Panel.getAddress());
191 applicant.setCity(step2Panel.getCity());
192 applicant.setState(step2Panel.getState());
193 applicant.setZip(step2Panel.getZipcode());
194
195 applicant.setCitizen(step3Panel.isCitizen());
196 if (!step3Panel.isCitizen()) {
197 applicant.setSpecifiy(step3Panel.specifyCitizenship());
198 }
199 applicant.setUnderstandEnglish(step3Panel.isUnderstandEnglish());
200 applicant.setqHoldFaaCertificate(step3Panel.isCertifiedPilot());
201 if (step3Panel.isCertifiedPilot()) {
202 applicant.setGradePilotCertificate(step3Panel.getCertificateGrade());
203 applicant.setCertificateNumber(step3Panel.getCertificateNumber());
204 applicant.setCertificateIssued(step3Panel.getCertificateIssuedDate());
205 }
206
207 applicant.setqHoldMedicalCertificate(step4Panel.hasMedical());
208 if (step4Panel.hasMedical()) {
209 applicant.setClassMedicalCertificate(step4Panel.getMedicalClass());
210 applicant.setNameMedicalExaminer(step4Panel.getNameOfExaminer());
211 applicant.setMedicalIssued(step4Panel.getMedicalIssueDate());
212 }
213 applicant.setHeight(step4Panel.getApplicantHeight());
214 applicant.setWeight(step4Panel.getWeight());
215 applicant.setHair(step4Panel.getHair());
216 applicant.setEyes(step4Panel.getEyes());
217 applicant.setSex(step4Panel.getSex());
218 applicant.setConvicted(step4Panel.hasFelony());
219 if (step4Panel.hasFelony()) {
220 applicant.setDateOfFinalConviction(step4Panel.getDateFinalConviction());
221 }
222
223 applicant.setApplicationBasis(step5Panel.getApplyFor());
224 if (step5Panel.getApplyFor().equals("a")) {
225 applicant.setAircraftToUse(step5Panel.getAircraftToBeUsed());
226 applicant.setTimeInAircraft(step5Panel.getTotalTimeInAircraft());
227 applicant.setPicAircraft(step5Panel.getPICTime());
228 }
229 applicant.setFailedRatingBefore(step5Panel.hasFailedCertificate());
230
231 LogbookService service = (LogbookService) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_SERVICE);
232 try {
233 service.saveApplicant(applicant);
234 } catch (ServiceException se) {
235 System.err.println("Unable to save Applicant" + se);
236 }
237
238 pdfUtility.setFileSaveAs(step6Panel.getFilePathName());
239
240 pdfUtility.loadValues(applicant);
241 }
242
243 }