import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Vector;
-import javax.swing.GroupLayout;
-import javax.swing.GroupLayout.Alignment;
+import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
-import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
-import businessLogic.HouseManager;
+import common.HouseInterface;
+
+import configuration.___IntNames;
+import domain.Districs;
import domain.HouseFeatures;
import domain.Owner;
import domain.RuralHouse;
private JPanel contentPane;
private Owner owner;
private JLabel lblDistrict;
- private JTextField District_f;
private JLabel feedback;
private JLabel lblDescription;
private JTextField description_f;
private JLabel lblParkings;
private JTextField parkings_f;
private JLabel lblBaths;
+ private String[] distric;
private JTextField baths_f;
private JButton btnConfirm;
private JComboBox<RuralHouse> houseBox;
+ private JComboBox<String> comboBox;
private RuralHouse rh;
/**
* Create the frame.
*/
- public ModifyHouseGUI(Owner o) {
+ public ModifyHouseGUI(final Owner o) {
+ this.distric=Districs.longNames();
+ comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+
+ this.distric));
this.getContentPane().setLayout(null);
owner = o;
setBounds(100, 100, 500, 583);
lblDistrict.setBounds(39, 119, 70, 14);
lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
- District_f = new JTextField();
- District_f.setBounds(127, 116, 86, 20);
- District_f.setColumns(10);
-
lblDescription = new JLabel("Description:");
lblDescription.setBounds(231, 88, 90, 14);
lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
public void actionPerformed(ActionEvent arg0) {
RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner,
- description_f.getText(), District_f.getText(),
+ description_f.getText(), (String)comboBox.getSelectedItem(),
new HouseFeatures(new Integer(rooms_f.getText()),
new Integer(kitchens_f.getText()), new Integer(
baths_f.getText()), new Integer(
lRooms_f.getText()), new Integer(
parkings_f.getText())));
- HouseManager hm = new HouseManager();
- if (hm.registerNewHouse(newRh)) {
- feedback.setText("House properly modified");
- } else
- feedback.setText("Imposible to modify the house");
+ HouseInterface hm= null;
+ try {
+ hm = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
+ try {
+ if (hm.registerNewHouse(newRh)) {
+ owner.getRuralHouses().add(newRh);
+ houseBox.removeItem(rh);
+ feedback.setText("House properly modified");
+ } else
+ feedback.setText("Imposible to modify the house");
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
});
-
- houseBox = new JComboBox<RuralHouse>(o.getRuralHouses());
+ HouseInterface hm= null;
+ try {
+ hm = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+ Vector<RuralHouse> list = null;
+ try {
+ list = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
+ } catch (RemoteException e1) {
+ e1.printStackTrace();
+ }
+
+ houseBox = new JComboBox<RuralHouse>(list);
if (!o.getRuralHouses().isEmpty()) {
- rh = (RuralHouse) houseBox.getSelectedItem();
- District_f.setText(rh.getDistrict());
+ rh = (RuralHouse) houseBox.getSelectedItem();
+ comboBox.setSelectedItem(rh.getDistrict());
description_f.setText(rh.getDescription());
kitchens_f.setText(Integer
.toString(rh.getFeatures().getnKitchens()));
houseBox.setBounds(89, 85, 124, 20);
}else{
feedback.setText("Not available houses");
+ btnConfirm.setEnabled(false);
}
houseBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
rh = (RuralHouse) houseBox.getSelectedItem();
- District_f.setText(rh.getDistrict());
+ comboBox.setSelectedItem(rh.getDistrict());
description_f.setText(rh.getDescription());
kitchens_f.setText(Integer.toString(rh.getFeatures()
.getnKitchens()));
contentPane.add(lblBaths);
contentPane.add(baths_f);
contentPane.add(lblDistrict);
- contentPane.add(District_f);
contentPane.add(lblLivings);
contentPane.add(lRooms_f);
contentPane.add(lblKitchen);
feedback = new JLabel("");
feedback.setBounds(189, 510, 195, 23);
contentPane.add(feedback);
+
+ comboBox.setBounds(127, 116, 86, 20);
+ contentPane.add(comboBox);
}
}