|
@@ -1,5 +1,144 @@ |
1 |
1 |
|
package gui; |
2 |
2 |
|
|
3 |
|
- |
public class DeleteOwnerGUI { |
|
3 |
+ |
import java.awt.Color; |
|
4 |
+ |
import java.awt.Component; |
|
5 |
+ |
import java.awt.Font; |
|
6 |
+ |
import java.awt.Rectangle; |
|
7 |
+ |
import java.awt.event.ActionEvent; |
|
8 |
+ |
import java.awt.event.ActionListener; |
|
9 |
+ |
import java.awt.event.MouseAdapter; |
|
10 |
+ |
import java.awt.event.MouseEvent; |
|
11 |
+ |
import java.rmi.Naming; |
|
12 |
+ |
import java.rmi.RemoteException; |
|
13 |
+ |
import java.util.Enumeration; |
|
14 |
+ |
import java.util.Vector; |
4 |
15 |
|
|
|
16 |
+ |
import javax.swing.JButton; |
|
17 |
+ |
import javax.swing.JFrame; |
|
18 |
+ |
import javax.swing.JLabel; |
|
19 |
+ |
import javax.swing.JPanel; |
|
20 |
+ |
import javax.swing.JScrollPane; |
|
21 |
+ |
import javax.swing.JTable; |
|
22 |
+ |
import javax.swing.border.EmptyBorder; |
|
23 |
+ |
import javax.swing.table.DefaultTableModel; |
|
24 |
+ |
|
|
25 |
+ |
|
|
26 |
+ |
|
|
27 |
+ |
import common.AccountInterface; |
|
28 |
+ |
import common.OwnerInterface; |
|
29 |
+ |
import configuration.___IntNames; |
|
30 |
+ |
import domain.Owner; |
|
31 |
+ |
|
|
32 |
+ |
public class DeleteOwnerGUI extends JFrame { |
|
33 |
+ |
|
|
34 |
+ |
/** |
|
35 |
+ |
* |
|
36 |
+ |
*/ |
|
37 |
+ |
private static final long serialVersionUID = 1L; |
|
38 |
+ |
private JPanel contentPane; |
|
39 |
+ |
private JTable table; |
|
40 |
+ |
|
|
41 |
+ |
private DefaultTableModel tableModel; |
|
42 |
+ |
private OwnerInterface Own = null; |
|
43 |
+ |
private Vector<Owner> owners = new Vector<Owner>(); |
|
44 |
+ |
|
|
45 |
+ |
/** |
|
46 |
+ |
* Create the frame. |
|
47 |
+ |
*/ |
|
48 |
+ |
public DeleteOwnerGUI() { |
|
49 |
+ |
setTitle("Current owners:"); |
|
50 |
+ |
try { |
|
51 |
+ |
init(); |
|
52 |
+ |
} catch (Exception e) { |
|
53 |
+ |
e.printStackTrace(); |
|
54 |
+ |
} |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
private void init() throws Exception { |
|
58 |
+ |
setBounds(100, 100, 600, 500); |
|
59 |
+ |
contentPane = new JPanel(); |
|
60 |
+ |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
61 |
+ |
setContentPane(contentPane); |
|
62 |
+ |
contentPane.setLayout(null); |
|
63 |
+ |
try { |
|
64 |
+ |
Own = (OwnerInterface) Naming |
|
65 |
+ |
.lookup(___IntNames.OwnerManager); |
|
66 |
+ |
} catch (Exception e1) { |
|
67 |
+ |
System.out |
|
68 |
+ |
.println("Error accessing remote authentication: " |
|
69 |
+ |
+ e1.toString()); |
|
70 |
+ |
} |
|
71 |
+ |
this.owners = Own.getOwners(); |
|
72 |
+ |
JLabel lblNewLabel = new JLabel(); |
|
73 |
+ |
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); |
|
74 |
+ |
lblNewLabel.setBounds(23, 41, 536, 33); |
|
75 |
+ |
contentPane.add(lblNewLabel); |
|
76 |
+ |
if (this.owners.isEmpty()) |
|
77 |
+ |
lblNewLabel |
|
78 |
+ |
.setText("There are not owners in the system"); |
|
79 |
+ |
else |
|
80 |
+ |
lblNewLabel.setText("List of owners:"); |
|
81 |
+ |
JScrollPane scrollPane = new JScrollPane(); |
|
82 |
+ |
scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); |
|
83 |
+ |
scrollPane.setBounds(23, 113, 536, 271); |
|
84 |
+ |
contentPane.add(scrollPane); |
|
85 |
+ |
JLabel feedback = new JLabel(""); |
|
86 |
+ |
feedback.setBounds(134, 447, 307, 14); |
|
87 |
+ |
contentPane.add(feedback); |
|
88 |
+ |
JButton btnNewButton = new JButton("Delete from the system"); |
|
89 |
+ |
btnNewButton.addActionListener(new ActionListener() { |
|
90 |
+ |
public void actionPerformed(ActionEvent e) { |
|
91 |
+ |
if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { |
|
92 |
+ |
AccountInterface acm = null; |
|
93 |
+ |
|
|
94 |
+ |
try { |
|
95 |
+ |
acm = (AccountInterface) Naming |
|
96 |
+ |
.lookup(___IntNames.AccountManager); |
|
97 |
+ |
} catch (Exception e1) { |
|
98 |
+ |
System.out.println("Error accessing remote authentication: " |
|
99 |
+ |
+ e1.toString()); |
|
100 |
+ |
} |
|
101 |
+ |
|
|
102 |
+ |
try { |
|
103 |
+ |
if(acm.removeAccount(table.getSelectedRow())) |
|
104 |
+ |
{ |
|
105 |
+ |
feedback.setText("Deleted from the system"); |
|
106 |
+ |
} |
|
107 |
+ |
} catch (RemoteException e1) { |
|
108 |
+ |
e1.printStackTrace(); |
|
109 |
+ |
} |
|
110 |
+ |
|
|
111 |
+ |
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); |
|
112 |
+ |
} |
|
113 |
+ |
} |
|
114 |
+ |
}); |
|
115 |
+ |
btnNewButton.setBounds(88, 396, 428, 40); |
|
116 |
+ |
contentPane.add(btnNewButton); |
|
117 |
+ |
table = new JTable() { |
|
118 |
+ |
private static final long serialVersionUID = 1L; |
|
119 |
+ |
|
|
120 |
+ |
public boolean isCellEditable(int row, int column) { |
|
121 |
+ |
return false; |
|
122 |
+ |
}; |
|
123 |
+ |
}; |
|
124 |
+ |
|
|
125 |
+ |
scrollPane.setViewportView(table); |
|
126 |
+ |
tableModel = new DefaultTableModel(null, new String[] { |
|
127 |
+ |
"Name", "E-mail", "Bank Account" }); |
|
128 |
+ |
|
|
129 |
+ |
table.setModel(tableModel); |
|
130 |
+ |
|
|
131 |
+ |
|
|
132 |
+ |
Enumeration<Owner> rhs = this.owners.elements(); |
|
133 |
+ |
while (rhs.hasMoreElements()) { |
|
134 |
+ |
Owner own = rhs.nextElement(); |
|
135 |
+ |
Vector<Object> row = new Vector<Object>(); |
|
136 |
+ |
row.add(own.getName()); |
|
137 |
+ |
row.add(own.getMailAccount()); |
|
138 |
+ |
row.add(own.getBankAccount()); |
|
139 |
+ |
tableModel.addRow(row); |
|
140 |
+ |
} |
|
141 |
+ |
|
|
142 |
+ |
|
|
143 |
+ |
} |
5 |
144 |
|
} |