01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.modules.session;
19:
20: import java.awt.BorderLayout;
21: import java.util.List;
22: import java.util.Vector;
23:
24: import javax.swing.JLabel;
25: import javax.swing.JPanel;
26: import javax.swing.JScrollPane;
27: import javax.swing.table.DefaultTableModel;
28:
29: import de.finix.contelligent.client.base.Session;
30: import de.finix.contelligent.client.base.SessionListener;
31: import de.finix.contelligent.client.i18n.Resources;
32: import de.finix.contelligent.client.modules.AbstractModule;
33: import de.finix.contelligent.client.util.TableLayout;
34:
35: /**
36: * This Panel shows general information about the current logged in user.
37: */
38: public class SessionModule extends AbstractModule implements
39: SessionListener {
40: private JLabel userName = new JLabel();
41:
42: private RoleTable roleTable;
43:
44: private DefaultTableModel roleTableModel;
45:
46: public void init() {
47: removeAll();
48: setLayout(new TableLayout(new double[][] {
49: { TableLayout.FILL, TableLayout.PREFERRED },
50: { TableLayout.MINIMUM, TableLayout.FILL } }));
51: userName.setIcon(Resources.userIcon);
52: add(userName, "0,0");
53:
54: JPanel roleinfo = new JPanel(new BorderLayout());
55: roleinfo.setOpaque(false);
56: String[] columnNames = { "Role", "Role identification" };
57: roleTableModel = new RoleTableModel(new Vector(), new Vector());
58: roleTable = new RoleTable(roleTableModel);
59:
60: JScrollPane roleScroller = new JScrollPane(roleTable);
61: roleScroller.getViewport().setOpaque(false);
62: roleScroller.setOpaque(false);
63: roleinfo.add(roleScroller, BorderLayout.CENTER);
64: add(roleinfo, "0,1,1,1");
65: }
66:
67: public void sessionChanged(Session session) {
68: if (session.getUser() != null) {
69: if (session.getUser().getName() != null) {
70: // update username
71: if (session.isRoot()) {
72: userName.setText(session.getUser().getName()
73: + " ["
74: + session.getUser().getPrincipal()
75: .getDisplayName()
76: + "] - "
77: + Resources
78: .getLocalString("root_principal"));
79: } else {
80: userName.setText(session.getUser().getName()
81: + " ["
82: + session.getUser().getPrincipal()
83: .getDisplayName() + "]");
84: }
85: } else {
86: userName.setText(session.getUser().getLogin());
87: }
88: } else {
89: userName.setText("Not logged in");
90: }
91:
92: List roles = session.getRoles();
93: List privileges = session.getPrivileges();
94: roleTableModel = new RoleTableModel(roles, privileges);
95: roleTable.setModel(roleTableModel);
96: roleTable.getColumnModel().getColumn(0).setPreferredWidth(10);
97: roleTable.getColumnModel().getColumn(1).setPreferredWidth(290);
98: }
99: }
|