DeleteOffers and Modify Offers completed, both logic and GUI
[RRRRHHHH_Code] / ruralHouses / src / gui / DeleteOfferGUI.java
1 package gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.ItemEvent;
8 import java.awt.event.ItemListener;
9 import java.rmi.RemoteException;
10 import java.util.Vector;
11
12 import javax.swing.JFrame;
13 import javax.swing.JPanel;
14 import javax.swing.border.EmptyBorder;
15 import javax.swing.GroupLayout;
16 import javax.swing.GroupLayout.Alignment;
17 import javax.swing.JComboBox;
18 import javax.swing.JRadioButton;
19 import javax.swing.JButton;
20
21 import businessLogic.HouseManager;
22 import businessLogic.HouseManagerInterface;
23 import businessLogic.OfferManager;
24 import domain.Offer;
25 import domain.Owner;
26 import domain.RuralHouse;
27
28 import javax.swing.JLabel;
29 import javax.swing.LayoutStyle.ComponentPlacement;
30
31 public class DeleteOfferGUI extends JFrame {
32
33         /**
34          * 
35          */
36         private static final long serialVersionUID = 1L;
37         private JPanel contentPane;
38         private Owner owner;
39         private JComboBox<RuralHouse> comboBox;
40         private JComboBox<Offer> comboBox_1;
41         private JButton btnDelete;
42
43
44         /**
45          * Create the frame.
46          */
47         public DeleteOfferGUI(Owner o) {
48                 this.owner = o;
49                 setBounds(100, 100, 450, 300);
50                 contentPane = new JPanel();
51                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
52                 setContentPane(contentPane);
53         
54                 comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
55                 
56                 
57                 
58                 comboBox_1 = new JComboBox<Offer>();
59
60                 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
61                 
62                 btnDelete = new JButton("DELETE");
63                 btnDelete.setEnabled(false);
64                 
65                 comboBox.addItemListener(new ItemListener() {
66
67                         @Override
68                         public void itemStateChanged(ItemEvent arg0) {
69                                 Vector<Offer> vo = ((RuralHouse)comboBox.getSelectedItem()).offers;
70                                 comboBox_1.removeAllItems();
71                                 for (Offer of: vo){
72                                         comboBox_1.addItem(of);;
73                                 }
74                 
75                         }
76                         
77                 });
78                 
79                 rdbtnIAmSure.addItemListener(new ItemListener() {
80
81                         @Override
82                         public void itemStateChanged(ItemEvent e) {
83                                 int state = e.getStateChange();
84                                 if (state == ItemEvent.SELECTED){
85                                         btnDelete.setEnabled(true);
86                                 }
87                                 else if (state == ItemEvent.DESELECTED){
88                                         btnDelete.setEnabled(false);
89                                 }
90                         }
91                 });
92                 
93                 JLabel lblHouse = new JLabel("House:");
94                 
95                 JLabel lblOffer = new JLabel("Offer:");
96                 GroupLayout gl_contentPane = new GroupLayout(contentPane);
97                 gl_contentPane.setHorizontalGroup(
98                         gl_contentPane.createParallelGroup(Alignment.LEADING)
99                                 .addGroup(gl_contentPane.createSequentialGroup()
100                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
101                                                 .addGroup(gl_contentPane.createSequentialGroup()
102                                                         .addGap(85)
103                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
104                                                                 .addComponent(btnDelete)
105                                                                 .addComponent(rdbtnIAmSure)))
106                                                 .addGroup(gl_contentPane.createSequentialGroup()
107                                                         .addGap(20)
108                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
109                                                                 .addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
110                                                                 .addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE))
111                                                         .addGap(8)
112                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
113                                                                 .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
114                                                                 .addComponent(comboBox_1, 0, 314, Short.MAX_VALUE))))
115                                         .addContainerGap(946, Short.MAX_VALUE))
116                 );
117                 gl_contentPane.setVerticalGroup(
118                         gl_contentPane.createParallelGroup(Alignment.LEADING)
119                                 .addGroup(gl_contentPane.createSequentialGroup()
120                                         .addGap(33)
121                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
122                                                 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
123                                                 .addComponent(lblHouse))
124                                         .addGap(18)
125                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
126                                                 .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
127                                                 .addComponent(lblOffer))
128                                         .addGap(43)
129                                         .addComponent(rdbtnIAmSure)
130                                         .addGap(47)
131                                         .addComponent(btnDelete)
132                                         .addContainerGap(493, Short.MAX_VALUE))
133                 );
134                 contentPane.setLayout(gl_contentPane);
135                 
136                 btnDelete.addActionListener(new ActionListener() {
137                         public void actionPerformed(ActionEvent arg0) {
138                                 actionListenerButton(arg0);
139                                 
140                         }
141
142                         
143                 });
144         }
145         
146         private void actionListenerButton(ActionEvent e){
147
148                 Offer toDel = (Offer)comboBox_1.getSelectedItem();
149                 OfferManager oM = new OfferManager();
150                 try {
151                         oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel);
152                 } catch (Exception e1) {
153                         e1.printStackTrace();
154                 }
155                 comboBox.removeItem(toDel);
156         }
157 }