unification with the actual initial project. Some things are new now, but there has...
[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.ApplicationFacadeInterface;
15 import domain.Owner;
16 import domain.RuralHouse;
17 import javax.swing.JLabel;
18
19
20 public class SetAvailabilityGUI extends JFrame {
21
22         private static final long serialVersionUID = 1L;
23         private JPanel jContentPane = null;
24         private JComboBox jComboBox = null;
25         private JButton jButton = null;
26         private JLabel lblNewLabel;
27
28         /**
29          * This is the default constructor
30          */
31         public SetAvailabilityGUI() {
32                 super();
33                 initialize();
34         }
35
36         /**
37          * This method initializes this
38          * 
39          * @return void
40          */
41         private void initialize() {
42                 this.setSize(449, 293);
43                 this.setContentPane(getJContentPane());
44                 this.setTitle("Choose Owner");
45                 
46         }
47
48         /**
49          * This method initializes jContentPane
50          * 
51          * @return javax.swing.JPanel
52          */
53         private JPanel getJContentPane() {
54                 if (jContentPane == null) {
55                         jContentPane = new JPanel();
56                         jContentPane.setLayout(null);
57                         jContentPane.add(getJComboBox(), null);
58                         jContentPane.add(getJButton(), null);
59                         
60                         lblNewLabel = new JLabel("");
61                         lblNewLabel.setBounds(77, 194, 300, 32);
62                         jContentPane.add(lblNewLabel);
63                 }
64                 return jContentPane;
65         }
66
67         /**
68          * This method initializes jComboBox    
69          *      
70          * @return javax.swing.JComboBox        
71          */
72         private JComboBox getJComboBox() {
73                 
74                 if (jComboBox == null) {
75                         try {
76                         ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
77                                 Vector<Owner> owners=facade.getOwners();
78                         jComboBox = new JComboBox(owners);
79                         jComboBox.setBounds(new Rectangle(136, 39, 175, 44));
80                         } catch (Exception e) {
81                                 // TODO Auto-generated catch block
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"