1 package org.wcb.gui.dialog.del;
2
3 import org.wcb.gui.forms.AircraftEntryForm;
4 import org.wcb.gui.forms.AircraftTableDisplayForm;
5 import org.wcb.gui.component.VectorButton;
6 import org.wcb.resources.MessageResourceRegister;
7 import org.wcb.model.vo.hibernate.AircraftBO;
8 import org.wcb.model.bd.AircraftDelegate;
9 import org.wcb.model.util.SpringUtil;
10 import org.wcb.model.service.IServicesConstants;
11 import org.wcb.resources.MessageKey;
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 AircraftEntryDialog extends JDialog implements ActionListener {
46
47 private AircraftEntryForm form;
48 private AircraftBO oAircraft;
49 private AircraftDelegate delegate;
50 private JButton clearButton;
51 private JButton saveButton;
52 private JComponent parentFrame;
53
54 public AircraftEntryDialog(JComponent parent) {
55 setTitle("Enter New AircraftBO");
56 delegate = (AircraftDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.AIRCRAFT_DELEGATE);
57 setModal(true);
58 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
59 this.parentFrame = parent;
60 initComponents();
61 }
62
63 public void setAircraft(AircraftBO oValue) {
64 this.oAircraft = oValue;
65 form.setAircraft(this.oAircraft);
66 }
67
68 public AircraftBO getAircraft() {
69 this.oAircraft = form.getAircraft();
70 return this.oAircraft;
71 }
72
73
74
75
76 private void initComponents() {
77 form = new AircraftEntryForm();
78 saveButton = new VectorButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_SAVE));
79 saveButton.setBorderPainted(false);
80 saveButton.setForeground(new Color(50,255,0));
81 saveButton.addActionListener(this);
82 clearButton = new VectorButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_CANCEL));
83 clearButton.setBorderPainted(false);
84 clearButton.setForeground(new Color(50,50,255));
85 clearButton.addActionListener(this);
86 getContentPane().setLayout(new BorderLayout());
87
88 JPanel buttonPanel = new JPanel();
89 buttonPanel.setLayout(new GridBagLayout());
90 GridBagConstraints gridBagConstraints;
91 gridBagConstraints = new GridBagConstraints();
92 gridBagConstraints.gridx = 0;
93 gridBagConstraints.gridy = 1;
94 gridBagConstraints.anchor = GridBagConstraints.WEST;
95 buttonPanel.add(clearButton, gridBagConstraints);
96
97 gridBagConstraints = new GridBagConstraints();
98 gridBagConstraints.gridx = 1;
99 gridBagConstraints.gridy = 1;
100 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
101 gridBagConstraints.anchor = GridBagConstraints.WEST;
102 buttonPanel.add(saveButton, gridBagConstraints);
103
104 getContentPane().add(form, BorderLayout.CENTER);
105 getContentPane().add(buttonPanel, BorderLayout.SOUTH);
106 pack();
107 }
108
109 public void actionPerformed(ActionEvent event) {
110 Object source = event.getSource();
111 if (source.equals(saveButton))
112 {
113 this.save();
114 this.dispose();
115 }
116 if (source.equals(clearButton))
117 {
118 form.reset();
119 this.dispose();
120 }
121 }
122
123 private void save() {
124 boolean success = delegate.saveAircraft(this.getAircraft());
125 if (success)
126 {
127 if(this.parentFrame instanceof AircraftTableDisplayForm) {
128 ((AircraftTableDisplayForm) parentFrame).refresh();
129 }
130 JOptionPane.showMessageDialog(null, "Successfully saved!", "Save AircraftBO", JOptionPane.INFORMATION_MESSAGE);
131 }
132 else
133 {
134 JOptionPane.showMessageDialog(null, "Could not save data.", "Save AircraftBO", JOptionPane.ERROR_MESSAGE);
135 }
136 }
137
138 }
139