package gui; import java.awt.Font; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.rmi.Naming; import java.rmi.RemoteException; import java.util.Enumeration; import java.util.Vector; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; import common.AdminInterface; import common.HouseInterface; import configuration.___IntNames; import domain.RuralHouse; public class listOfRemovalRequestsGUI extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JPanel contentPane; private JTable table; private DefaultTableModel tableModel; private AdminInterface am = null; private Vector houses; /** * Create the frame. */ public listOfRemovalRequestsGUI() { try { am = (AdminInterface) Naming.lookup(___IntNames.AdminManager); } catch (Exception e1) { System.out.println("Error accessing remote authentication: " + e1.toString()); } setTitle("Deleting requests"); try { this.houses = am.getDeletionRequests(); init(); } catch (Exception e) { e.printStackTrace(); } } private void init() throws Exception { setBounds(100, 100, 600, 450); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblNewLabel = new JLabel(); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); lblNewLabel.setBounds(23, 41, 536, 33); contentPane.add(lblNewLabel); if (houses.isEmpty()) lblNewLabel.setText("There are not houses to be deleted"); else lblNewLabel.setText("List of houses to be deleted:"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); scrollPane.setBounds(23, 113, 536, 271); contentPane.add(scrollPane); table = new JTable() { private static final long serialVersionUID = 1L; public boolean isCellEditable(int row, int column) { return false; }; }; scrollPane.setViewportView(table); tableModel = new DefaultTableModel(null, new String[] { "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" }); table.setModel(tableModel); Enumeration en = houses.elements(); RuralHouse rh; JButton btnNewButton = new JButton("Confirm Deletion"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { HouseInterface hm = null; try { hm = (HouseInterface) Naming .lookup(___IntNames.HouseManager); } catch (Exception e1) { System.out .println("Error accessing remote authentication: " + e1.toString()); } RuralHouse rh = houses.get(table.getSelectedRow()); try { hm.removeHouse(rh, rh.getOwner()); am.removeHouseDeletionRequests(rh); am.saveInstance(); } catch (RemoteException e1) { e1.printStackTrace(); } ((DefaultTableModel) table.getModel()).removeRow(houses .indexOf(rh)); houses.remove(rh); } } }); btnNewButton.setBounds(90, 396, 169, 25); contentPane.add(btnNewButton); JButton btnNewButton_1 = new JButton("Deny Deletion"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { RuralHouse rh = houses.get(table.getSelectedRow()); ((DefaultTableModel) table.getModel()).removeRow(houses .indexOf(rh)); houses.remove(rh); try { am.removeHouseDeletionRequests(rh); am.saveInstance(); } catch (RemoteException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); btnNewButton_1.setBounds(291, 396, 169, 25); contentPane.add(btnNewButton_1); while (en.hasMoreElements()) { rh = en.nextElement(); Vector row = new Vector(); row.add(rh.getHouseName()); row.add(rh.getFeatures().getnRooms()); row.add(rh.getFeatures().getnKitchens()); row.add(rh.getFeatures().getnBaths()); row.add(rh.getFeatures().getnParkings()); row.add(rh.getFeatures().getnLivings()); tableModel.addRow(row); } } }