1 package org.wcb.gui.forms.wizard;
2
3 import org.wcb.gui.component.JCloudPane;
4 import org.wcb.gui.util.UIHelper;
5 import org.wcb.model.vo.LogExportVO;
6 import org.wcb.model.service.IExportService;
7 import org.wcb.model.service.IServicesConstants;
8 import org.wcb.model.util.SpringUtil;
9 import org.wcb.exception.ServiceException;
10
11 import javax.swing.*;
12 import java.awt.event.ActionListener;
13 import java.awt.event.ActionEvent;
14 import java.awt.*;
15 import java.io.File;
16
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 public class ExportWizard extends JPanel implements ActionListener {
45
46 private JPanel centerPanel;
47 private Step1ofExportWizard step1Panel;
48 private Step2ofExportWizard step2Panel;
49 private CompletionofWizard completionPanel;
50 private JButton backButton;
51 private JButton nextButton;
52 private int stepCounter;
53 private int MAX_STEPS=2;
54
55 public ExportWizard () {
56 initComponents();
57 stepCounter = 1;
58 }
59
60 private void initComponents() {
61 ImageIcon titleIcon = UIHelper.getIcon("org/wcb/resources/gui/exportpref_wiz.gif");
62 JLabel wizardLabel = new JLabel(titleIcon);
63 JCloudPane wizard = new JCloudPane();
64 wizard.add(wizardLabel);
65
66 backButton = new JButton("Back");
67 nextButton = new JButton("Next");
68 backButton.addActionListener(this);
69 nextButton.addActionListener(this);
70
71 step1Panel = new Step1ofExportWizard();
72 step2Panel = new Step2ofExportWizard();
73
74 completionPanel = new CompletionofWizard();
75 completionPanel.setTextToLabel("You have successfully exported your Log book!");
76 centerPanel = new JPanel(new CardLayout());
77 centerPanel.add(step1Panel, "step1");
78 centerPanel.add(step2Panel, "step2");
79
80 centerPanel.add(completionPanel, "completion");
81
82 JPanel buttonPanel = new JPanel();
83 buttonPanel.add(backButton);
84 buttonPanel.add(nextButton);
85
86 setLayout(new BorderLayout());
87 add(wizardLabel, BorderLayout.WEST);
88 add(centerPanel, BorderLayout.CENTER);
89 add(buttonPanel, BorderLayout.SOUTH);
90
91 }
92
93 public void actionPerformed(ActionEvent evt) {
94 Object src = evt.getSource();
95 if (src.equals(nextButton)) {
96 if(nextButton.getText().equals("Finish")) {
97 doExport();
98 showNextPanel("completion");
99 nextButton.setEnabled(false);
100 backButton.setEnabled(false);
101 } else {
102 stepCounter = stepCounter + 1;
103 if(stepCounter >= MAX_STEPS) {
104 stepCounter = MAX_STEPS;
105 nextButton.setText("Finish");
106 }
107 showNextPanel("step" + stepCounter);
108 }
109 }
110 if (src.equals(backButton)) {
111 if(nextButton.getText().equals("Finish")) {
112 nextButton.setText("Next");
113 }
114 stepCounter = stepCounter - 1;
115 if (stepCounter < 1) {
116 stepCounter = 1;
117 }
118 showNextPanel("step" + stepCounter);
119 }
120 }
121
122
123
124
125
126 private void showNextPanel(String panelName) {
127 CardLayout cl = (CardLayout) centerPanel.getLayout();
128 cl.show(centerPanel, panelName);
129 }
130
131 private void doExport() {
132 IExportService service = (IExportService) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_EXPORT_SERVICE);
133 try
134 {
135 service.processFile(new File(step2Panel.getFilePathName()), this.getValueObject(), step2Panel.getFieldDelimiter());
136 }
137 catch (ServiceException se)
138 {
139 JOptionPane.showMessageDialog(this, "Unable to export the entire file " + step2Panel.getFilePathName() + " \n The reason is: " + se.getMessage(), "Failure to Export" , JOptionPane.ERROR_MESSAGE);
140 }
141 }
142
143 private LogExportVO getValueObject() {
144 LogExportVO returnValue = new LogExportVO();
145 returnValue.setEntryDate(step1Panel.getForm().getjCheckBoxEntryDate());
146 returnValue.setRegistration(step1Panel.getForm().getjCheckBoxRegistration());
147 returnValue.setFAAFrom(step1Panel.getForm().getjCheckBoxFAAFrom());
148 returnValue.setVia(step1Panel.getForm().getjCheckBoxVIA());
149 returnValue.setFAATo(step1Panel.getForm().getjCheckBoxFAATo());
150 returnValue.setFlightDuration(step1Panel.getForm().getjCheckBoxFlightDuration());
151 returnValue.setPIC(step1Panel.getForm().getjCheckBoxPIC());
152 returnValue.setSIC(step1Panel.getForm().getjCheckBoxSIC());
153 returnValue.setCrossCountry(step1Panel.getForm().getjCheckBoxCrossCountry());
154 returnValue.setFlightInstructing(step1Panel.getForm().getjCheckBoxFlightInstructing());
155 returnValue.setSafetyPilot(step1Panel.getForm().getjCheckBoxSafetyPilot());
156 returnValue.setDualReceived(step1Panel.getForm().getjCheckBoxDualReceived());
157 returnValue.setSolo(step1Panel.getForm().getjCheckBoxSolo());
158 returnValue.setDayLanding(step1Panel.getForm().getjCheckBoxDayLanding());
159 returnValue.setDayTakeoff(step1Panel.getForm().getjCheckBoxDayTakeoff());
160 returnValue.setNightLanding(step1Panel.getForm().getjCheckBoxNightLanding());
161 returnValue.setNightTakeoff(step1Panel.getForm().getjCheckBoxNightTakeoff());
162 returnValue.setConditionNight(step1Panel.getForm().getjCheckBoxConditionNight());
163 returnValue.setActualIMC(step1Panel.getForm().getjCheckBoxActualIMC());
164 returnValue.setSimulatedIMC(step1Panel.getForm().getjCheckBoxSimulatedIMC());
165 returnValue.setFlightSim(step1Panel.getForm().getjCheckBoxFlightSim());
166 returnValue.setInstrumentApproaches(step1Panel.getForm().getjCheckBoxInstrumentApproaches());
167 return returnValue;
168 }
169
170 }