Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard
 
7bf57b2f0f2b3cf0ae9489a8204918762e64648e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package gui;

import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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 businessLogic.AccountManager;
import businessLogic.AdminManager;
import domain.Account;
import domain.Administrator;

public class ownerAddittionRequests extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTable table;
	private DefaultTableModel tableModel;
	private AdminManager am = new AdminManager();
	private Vector<Account> accounts;
 	/**
	 * Create the frame.
	 */
	public  ownerAddittionRequests()  {
 		setTitle("Adding requests");
		try {
			this.accounts= am.getOwnerAdditionReuests();
			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 (accounts.isEmpty())
			lblNewLabel.setText("There are not owners to be added");
		else
			lblNewLabel.setText("List of owners to be added:");
		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[] {
				"Name", "E-mail", "Bank Account" });
		
		//Maybe there is a better way to avoid interaction.
		//table.setEnabled(false);
		table.setModel(tableModel);
		
		JButton btnNewButton = new JButton("Confirm Addition");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
					AccountManager ama = new AccountManager();
					Account accou = accounts.get(table.getSelectedRow());
					//TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
					ama.addAccount(accou);
					am.removeOwnerAdditionRequests(accou);;
					Administrator.saveInstance();
					((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(accou));
					accounts.remove(accou);
				}
			}
		});
		btnNewButton.setBounds(88, 396, 169, 25);
		contentPane.add(btnNewButton);
		
		JButton btnDenyAddition = new JButton("Deny Addition");
		btnDenyAddition.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
					Account acc = accounts.get(table.getSelectedRow());
					am.removeOwnerAdditionRequests(acc);
					Administrator.saveInstance();
					((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(acc));
					accounts.remove(acc);
				}
			}
		});
		btnDenyAddition.setBounds(300, 396, 169, 25);
		contentPane.add(btnDenyAddition);
		Enumeration<Account> en = accounts.elements();
		Account acc;
		
		while (en.hasMoreElements()) {
			acc = en.nextElement();
			Vector<Object> row = new Vector<Object>();
			row.add(acc.getOwner().getName());
			row.add(acc.getOwner().getMailAccount());
			row.add(acc.getOwner().getBankAccount());			
			tableModel.addRow(row);
		}

	}
}

Commits for RRRRHHHH_Code/ruralHouses/src/gui/ownerAddittionRequests.java

Diff revisions: vs.
Revision Author Commited Message
7bf57b ... camjan Sun 17 May, 2015 11:59:22 +0000

Possibility of registering new owners added