|
@@ -20,6 +20,8 @@ |
20 |
20 |
|
import domain.Offer; |
21 |
21 |
|
import domain.Owner; |
22 |
22 |
|
import domain.RuralHouse; |
|
23 |
+ |
import javax.swing.LayoutStyle.ComponentPlacement; |
|
24 |
+ |
import javax.swing.JTextField; |
23 |
25 |
|
|
24 |
26 |
|
public class DeleteOfferGUI extends JFrame { |
25 |
27 |
|
|
|
@@ -29,11 +31,11 @@ |
29 |
31 |
|
private static final long serialVersionUID = 1L; |
30 |
32 |
|
private JPanel contentPane; |
31 |
33 |
|
private Owner owner; |
|
34 |
+ |
private JLabel feedback; |
32 |
35 |
|
private JComboBox<RuralHouse> comboBox; |
33 |
36 |
|
private JComboBox<Offer> comboBox_1; |
34 |
37 |
|
private JButton btnDelete; |
35 |
38 |
|
|
36 |
|
- |
|
37 |
39 |
|
/** |
38 |
40 |
|
* Create the frame. |
39 |
41 |
|
*/ |
|
@@ -43,108 +45,94 @@ |
43 |
45 |
|
contentPane = new JPanel(); |
44 |
46 |
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
45 |
47 |
|
setContentPane(contentPane); |
46 |
|
- |
|
|
48 |
+ |
|
47 |
49 |
|
comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses()); |
48 |
|
- |
|
49 |
|
- |
|
50 |
|
- |
|
|
50 |
+ |
comboBox.setBounds(101, 38, 314, 20); |
|
51 |
+ |
|
51 |
52 |
|
comboBox_1 = new JComboBox<Offer>(); |
|
53 |
+ |
comboBox_1.setBounds(101, 76, 314, 20); |
|
54 |
+ |
Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem()).offers; |
|
55 |
+ |
comboBox_1.removeAllItems(); |
|
56 |
+ |
for (Offer of : vo) { |
|
57 |
+ |
comboBox_1.addItem(of); |
|
58 |
+ |
; |
|
59 |
+ |
} |
52 |
60 |
|
|
53 |
61 |
|
JRadioButton rdbtnIAmSure = new JRadioButton("I am sure"); |
54 |
|
- |
|
|
62 |
+ |
rdbtnIAmSure.setBounds(101, 134, 71, 23); |
|
63 |
+ |
|
55 |
64 |
|
btnDelete = new JButton("DELETE"); |
|
65 |
+ |
btnDelete.setBounds(92, 226, 69, 23); |
56 |
66 |
|
btnDelete.setEnabled(false); |
57 |
|
- |
|
|
67 |
+ |
|
58 |
68 |
|
comboBox.addItemListener(new ItemListener() { |
59 |
69 |
|
|
60 |
70 |
|
@Override |
61 |
71 |
|
public void itemStateChanged(ItemEvent arg0) { |
62 |
|
- |
Vector<Offer> vo = ((RuralHouse)comboBox.getSelectedItem()).offers; |
|
72 |
+ |
Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem()).offers; |
63 |
73 |
|
comboBox_1.removeAllItems(); |
64 |
|
- |
for (Offer of: vo){ |
65 |
|
- |
comboBox_1.addItem(of);; |
|
74 |
+ |
for (Offer of : vo) { |
|
75 |
+ |
comboBox_1.addItem(of); |
|
76 |
+ |
; |
66 |
77 |
|
} |
67 |
|
- |
|
|
78 |
+ |
|
68 |
79 |
|
} |
69 |
|
- |
|
|
80 |
+ |
|
70 |
81 |
|
}); |
71 |
|
- |
|
|
82 |
+ |
|
72 |
83 |
|
rdbtnIAmSure.addItemListener(new ItemListener() { |
73 |
84 |
|
|
74 |
85 |
|
@Override |
75 |
86 |
|
public void itemStateChanged(ItemEvent e) { |
76 |
87 |
|
int state = e.getStateChange(); |
77 |
|
- |
if (state == ItemEvent.SELECTED){ |
78 |
|
- |
btnDelete.setEnabled(true); |
79 |
|
- |
} |
80 |
|
- |
else if (state == ItemEvent.DESELECTED){ |
|
88 |
+ |
if (state == ItemEvent.SELECTED) { |
|
89 |
+ |
if (comboBox_1.getSelectedItem() != null) |
|
90 |
+ |
btnDelete.setEnabled(true); |
|
91 |
+ |
} else if (state == ItemEvent.DESELECTED) { |
81 |
92 |
|
btnDelete.setEnabled(false); |
82 |
93 |
|
} |
83 |
94 |
|
} |
84 |
95 |
|
}); |
85 |
|
- |
|
|
96 |
+ |
|
86 |
97 |
|
JLabel lblHouse = new JLabel("House:"); |
87 |
|
- |
|
|
98 |
+ |
lblHouse.setBounds(25, 41, 68, 14); |
|
99 |
+ |
|
88 |
100 |
|
JLabel lblOffer = new JLabel("Offer:"); |
89 |
|
- |
GroupLayout gl_contentPane = new GroupLayout(contentPane); |
90 |
|
- |
gl_contentPane.setHorizontalGroup( |
91 |
|
- |
gl_contentPane.createParallelGroup(Alignment.LEADING) |
92 |
|
- |
.addGroup(gl_contentPane.createSequentialGroup() |
93 |
|
- |
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) |
94 |
|
- |
.addGroup(gl_contentPane.createSequentialGroup() |
95 |
|
- |
.addGap(85) |
96 |
|
- |
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) |
97 |
|
- |
.addComponent(btnDelete) |
98 |
|
- |
.addComponent(rdbtnIAmSure))) |
99 |
|
- |
.addGroup(gl_contentPane.createSequentialGroup() |
100 |
|
- |
.addGap(20) |
101 |
|
- |
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false) |
102 |
|
- |
.addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
103 |
|
- |
.addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)) |
104 |
|
- |
.addGap(8) |
105 |
|
- |
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false) |
106 |
|
- |
.addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
107 |
|
- |
.addComponent(comboBox_1, 0, 314, Short.MAX_VALUE)))) |
108 |
|
- |
.addContainerGap(946, Short.MAX_VALUE)) |
109 |
|
- |
); |
110 |
|
- |
gl_contentPane.setVerticalGroup( |
111 |
|
- |
gl_contentPane.createParallelGroup(Alignment.LEADING) |
112 |
|
- |
.addGroup(gl_contentPane.createSequentialGroup() |
113 |
|
- |
.addGap(33) |
114 |
|
- |
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) |
115 |
|
- |
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
116 |
|
- |
.addComponent(lblHouse)) |
117 |
|
- |
.addGap(18) |
118 |
|
- |
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) |
119 |
|
- |
.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
120 |
|
- |
.addComponent(lblOffer)) |
121 |
|
- |
.addGap(43) |
122 |
|
- |
.addComponent(rdbtnIAmSure) |
123 |
|
- |
.addGap(47) |
124 |
|
- |
.addComponent(btnDelete) |
125 |
|
- |
.addContainerGap(493, Short.MAX_VALUE)) |
126 |
|
- |
); |
127 |
|
- |
contentPane.setLayout(gl_contentPane); |
128 |
|
- |
|
|
101 |
+ |
lblOffer.setBounds(25, 79, 68, 14); |
|
102 |
+ |
contentPane.setLayout(null); |
|
103 |
+ |
contentPane.add(btnDelete); |
|
104 |
+ |
contentPane.add(rdbtnIAmSure); |
|
105 |
+ |
contentPane.add(lblHouse); |
|
106 |
+ |
contentPane.add(lblOffer); |
|
107 |
+ |
contentPane.add(comboBox); |
|
108 |
+ |
contentPane.add(comboBox_1); |
|
109 |
+ |
|
|
110 |
+ |
feedback = new JLabel(""); |
|
111 |
+ |
feedback.setBounds(140, 178, 155, 23); |
|
112 |
+ |
contentPane.add(feedback); |
|
113 |
+ |
|
129 |
114 |
|
btnDelete.addActionListener(new ActionListener() { |
130 |
115 |
|
public void actionPerformed(ActionEvent arg0) { |
131 |
116 |
|
actionListenerButton(arg0); |
132 |
|
- |
|
|
117 |
+ |
|
133 |
118 |
|
} |
134 |
119 |
|
|
135 |
|
- |
|
136 |
120 |
|
}); |
137 |
121 |
|
} |
138 |
|
- |
|
139 |
|
- |
private void actionListenerButton(ActionEvent e){ |
140 |
122 |
|
|
141 |
|
- |
Offer toDel = (Offer)comboBox_1.getSelectedItem(); |
|
123 |
+ |
private void actionListenerButton(ActionEvent e) { |
|
124 |
+ |
|
|
125 |
+ |
Offer toDel = (Offer) comboBox_1.getSelectedItem(); |
142 |
126 |
|
OfferManager oM = new OfferManager(); |
143 |
127 |
|
try { |
144 |
|
- |
oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel); |
|
128 |
+ |
oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel); |
|
129 |
+ |
comboBox_1.removeItem(toDel); |
|
130 |
+ |
btnDelete.setEnabled(false); |
|
131 |
+ |
feedback.setText("Offer correctly deleted"); |
145 |
132 |
|
} catch (Exception e1) { |
|
133 |
+ |
feedback.setText("Imposible to delete the offer"); |
146 |
134 |
|
e1.printStackTrace(); |
147 |
135 |
|
} |
148 |
|
- |
comboBox.removeItem(toDel); |
|
136 |
+ |
|
149 |
137 |
|
} |
150 |
138 |
|
} |