1 package org.wcb.gui.forms.wizard;
2
3 import org.wcb.gui.util.UIHelper;
4 import org.wcb.gui.component.JCloudPane;
5 import org.wcb.model.service.IImportService;
6 import org.wcb.model.service.IServicesConstants;
7 import org.wcb.model.util.SpringUtil;
8 import org.wcb.exception.ServiceException;
9
10 import javax.swing.*;
11 import java.awt.event.ActionListener;
12 import java.awt.event.ActionEvent;
13 import java.awt.*;
14 import java.io.File;
15
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 public class ImportAirportWizard extends JPanel implements ActionListener {
44
45 private JPanel centerPanel;
46 private Step1ofImportWizard step1Panel;
47 private CompletionofWizard completionPanel;
48 private JButton backButton;
49 private JButton nextButton;
50 private int stepCounter;
51 private int MAX_STEPS=1;
52
53 public ImportAirportWizard() {
54 initComponents();
55 stepCounter = 1;
56 }
57
58 private void initComponents() {
59 ImageIcon titleIcon = UIHelper.getIcon("org/wcb/resources/gui/importpref_wiz.gif");
60 JLabel wizardLabel = new JLabel(titleIcon);
61 JCloudPane wizard = new JCloudPane();
62 wizard.add(wizardLabel);
63
64 backButton = new JButton("Back");
65 nextButton = new JButton("Next");
66 backButton.addActionListener(this);
67 nextButton.addActionListener(this);
68
69 step1Panel = new Step1ofImportWizard();
70
71 completionPanel = new CompletionofWizard();
72 completionPanel.setTextToLabel("You have successfully imported data into your Log book!");
73 centerPanel = new JPanel(new CardLayout());
74 centerPanel.add(step1Panel, "step1");
75 centerPanel.add(completionPanel,"completion");
76
77 JPanel buttonPanel = new JPanel();
78 buttonPanel.add(backButton);
79 buttonPanel.add(nextButton);
80
81 setLayout(new BorderLayout());
82 add(wizardLabel, BorderLayout.WEST);
83 add(centerPanel, BorderLayout.CENTER);
84 add(buttonPanel, BorderLayout.SOUTH);
85
86 }
87
88 public void actionPerformed(ActionEvent evt) {
89 Object src = evt.getSource();
90 if (src.equals(nextButton)) {
91 if(nextButton.getText().equals("Finish")) {
92 doImport();
93 showNextPanel("completion");
94 nextButton.setEnabled(false);
95 backButton.setEnabled(false);
96 } else {
97 stepCounter = stepCounter + 1;
98 if(stepCounter >= MAX_STEPS) {
99 stepCounter = MAX_STEPS;
100 nextButton.setText("Finish");
101 }
102 showNextPanel("step" + stepCounter);
103 }
104 }
105 if (src.equals(backButton)) {
106 if(nextButton.getText().equals("Finish")) {
107 nextButton.setText("Next");
108 }
109 stepCounter = stepCounter - 1;
110 if (stepCounter < 1) {
111 stepCounter = 1;
112 }
113 showNextPanel("step" + stepCounter);
114 }
115 }
116
117
118
119
120
121 private void showNextPanel(String panelName) {
122 CardLayout cl = (CardLayout) centerPanel.getLayout();
123 cl.show(centerPanel, panelName);
124 }
125
126 private void doImport() {
127 IImportService service = (IImportService) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_IMPORT_SERVICE);
128 try
129 {
130 service.processAirportFile(new File(step1Panel.getFilePathName()));
131 }
132 catch (ServiceException se)
133 {
134 JOptionPane.showMessageDialog(this, "Unable to import the entire file " + step1Panel.getFilePathName() + " \n The reason is: " + se.getMessage(), "Failure to Import" , JOptionPane.ERROR_MESSAGE);
135 }
136 }
137
138
139
140 }