X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/blobdiff_plain/e3043c3b5cbff18b2388a9c95c411cc60367000d..b09f345318baa9ca734e11c87f52f8522d7cc1fb:/ruralHouses/src/gui/DeleteOwnerGUI.java diff --git a/ruralHouses/src/gui/DeleteOwnerGUI.java b/ruralHouses/src/gui/DeleteOwnerGUI.java new file mode 100644 index 0000000..982e022 --- /dev/null +++ b/ruralHouses/src/gui/DeleteOwnerGUI.java @@ -0,0 +1,139 @@ +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.AccountInterface; +import common.AdminInterface; + +import configuration.___IntNames; +import domain.Owner; + +public class DeleteOwnerGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + + private DefaultTableModel tableModel; + private AdminInterface AdM = null; + private Vector owners = new Vector(); + + /** + * Create the frame. + */ + public DeleteOwnerGUI() { + setTitle("Current owners:"); + try { + init(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void init() throws Exception { + setBounds(100, 100, 600, 500); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + try { + AdM = (AdminInterface) Naming + .lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out + .println("Error accessing remote authentication: " + + e1.toString()); + } + this.owners = AdM.getAllOwners(); + JLabel lblNewLabel = new JLabel(); + lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); + lblNewLabel.setBounds(23, 41, 536, 33); + contentPane.add(lblNewLabel); + if (this.owners.isEmpty()) + lblNewLabel + .setText("There are not owners in the system"); + else + lblNewLabel.setText("List of owners:"); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); + scrollPane.setBounds(23, 113, 536, 271); + contentPane.add(scrollPane); + final JLabel feedback = new JLabel(""); + feedback.setBounds(134, 447, 307, 14); + contentPane.add(feedback); + JButton btnNewButton = new JButton("Delete from the system"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + AccountInterface acm = null; + + try { + acm = (AccountInterface) Naming + .lookup(___IntNames.AccountManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + try { + if(acm.removeAccount(table.getSelectedRow())) + { + feedback.setText("Deleted from the system"); + } + } catch (RemoteException e1) { + e1.printStackTrace(); + } + + ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); + } + } + }); + btnNewButton.setBounds(88, 396, 428, 40); + contentPane.add(btnNewButton); + 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[] { + "Name", "E-mail", "Bank Account" }); + + table.setModel(tableModel); + + + Enumeration rhs = this.owners.elements(); + while (rhs.hasMoreElements()) { + Owner own = rhs.nextElement(); + Vector row = new Vector(); + row.add(own.getName()); + row.add(own.getMailAccount()); + row.add(own.getBankAccount()); + tableModel.addRow(row); + } + + + } +}