b4d8ee17524b9c138216e7344377a478d9eb754b
[RRRRHHHH_Code] / ruralHouses / src / gui / SetAvailabilityGUI.java
1 package gui;
2
3 import javax.swing.ComboBoxModel;
4 import javax.swing.JPanel;
5 import javax.swing.JFrame;
6 import javax.swing.JComboBox;
7
8 import java.awt.Rectangle;
9 import java.util.Set;
10 import java.util.Vector;
11
12 import javax.swing.JButton;
13
14 import businessLogic.OwnerManager;
15 import businessLogic.OwnerManagerInterface;
16 import domain.Owner;
17 import domain.RuralHouse;
18 import javax.swing.JLabel;
19
20
21 public class SetAvailabilityGUI extends JFrame {
22
23         private static final long serialVersionUID = 1L;
24         private JPanel jContentPane = null;
25         private JComboBox jComboBox = null;
26         private JButton jButton = null;
27         private JLabel lblNewLabel;
28
29         /**
30          * This is the default constructor
31          */
32         public SetAvailabilityGUI() {
33                 super();
34                 initialize();
35         }
36
37         /**
38          * This method initializes this
39          * 
40          * @return void
41          */
42         private void initialize() {
43                 this.setSize(449, 293);
44                 this.setContentPane(getJContentPane());
45                 this.setTitle("Choose Owner");
46                 
47         }
48
49         /**
50          * This method initializes jContentPane
51          * 
52          * @return javax.swing.JPanel
53          */
54         private JPanel getJContentPane() {
55                 if (jContentPane == null) {
56                         jContentPane = new JPanel();
57                         jContentPane.setLayout(null);
58                         jContentPane.add(getJComboBox(), null);
59                         jContentPane.add(getJButton(), null);
60                         
61                         lblNewLabel = new JLabel("");
62                         lblNewLabel.setBounds(77, 194, 300, 32);
63                         jContentPane.add(lblNewLabel);
64                 }
65                 return jContentPane;
66         }
67
68         /**
69          * This method initializes jComboBox    
70          *      
71          * @return javax.swing.JComboBox        
72          */
73         private JComboBox getJComboBox() {
74                 
75                 if (jComboBox == null) {
76                         try {
77                         OwnerManagerInterface ownerM = new OwnerManager();
78                                 Vector<Owner> owners=ownerM.getOwners();
79                         jComboBox = new JComboBox(owners);
80                         jComboBox.setBounds(new Rectangle(136, 39, 175, 44));
81                         } catch (Exception e) {
82                                 e.printStackTrace();
83                         }
84                         
85                         }
86                 
87                 return jComboBox;
88         }
89
90         /**
91          * This method initializes jButton      
92          *      
93          * @return javax.swing.JButton  
94          */
95         private JButton getJButton() {
96                 if (jButton == null) {
97                         jButton = new JButton();
98                         jButton.setBounds(new Rectangle(172, 115, 95, 59));
99                         jButton.setText("Aceptar");
100                         jButton.addActionListener(new java.awt.event.ActionListener() {
101                                 public void actionPerformed(java.awt.event.ActionEvent e) {
102                                         Owner owner=(Owner)jComboBox.getSelectedItem();
103                                         Vector<RuralHouse> houseList=null;
104                                         try {
105                                         
106 //                                              ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();                       
107 //                                              houseList=facade.getRuralHouses(owner); // Not needed to ask the business logic because
108                                                 houseList=owner.getRuralHouses();               // Owner has been serialized with its rural houses !!
109                                         
110                                         } catch (Exception e1) {
111                                                 e1.printStackTrace();
112                                         }
113                                         if (houseList.isEmpty()!=true) {
114                                                 JFrame a = new SetAvailability2GUI(houseList);
115                                                 a.setVisible(true);
116                                         } else if (houseList.isEmpty()==true){
117                                                 lblNewLabel.setText("Owner does not exist or without houses ");
118                                         }               
119                                         
120                                 }
121                         });
122                 }
123                 return jButton;
124         }
125 }  //  @jve:decl-index=0:visual-constraint="222,33"