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.security;
19:
20: import java.util.Collection;
21:
22: import javax.swing.JComboBox;
23: import javax.swing.JDialog;
24: import javax.swing.JOptionPane;
25: import javax.swing.JPasswordField;
26: import javax.swing.JTextField;
27:
28: import de.finix.contelligent.client.ContelligentClient;
29: import de.finix.contelligent.client.modules.preferences.PreferencesModule;
30: import de.finix.contelligent.client.util.RestrictedDocument;
31:
32: public class LoginOptionPane extends JOptionPane {
33:
34: private JTextField loginField = new JTextField(15);
35:
36: private JComboBox groupBox;
37:
38: private JPasswordField passwordField = new JPasswordField(15);
39:
40: public LoginOptionPane(Collection userGroups) {
41: RestrictedDocument document = new RestrictedDocument();
42: document.setAllowString(RestrictedDocument.PRINCIPALS);
43: loginField.setDocument(document);
44: document = new RestrictedDocument();
45: document.setAllowString(RestrictedDocument.PRINCIPALS);
46: passwordField.setDocument(document);
47: groupBox = new JComboBox(userGroups.toArray());
48: String defaultGroup = PreferencesModule.getPreferences().get(
49: PreferencesModule.GROUP,
50: PreferencesModule.DEFAULT_GROUP);
51: groupBox.setSelectedItem(defaultGroup);
52: if (!defaultGroup.equals(groupBox.getSelectedItem())) {
53: // Fallback if our desired default group no longer exists
54: groupBox.setSelectedItem("system-users");
55: }
56: }
57:
58: public int showLoginDialog(String title, String loginLabel,
59: String groupLabel, String passwordLabel, String contextLabel) {
60: Object[] array = { loginLabel, loginField, passwordLabel,
61: passwordField, groupLabel, groupBox };
62:
63: setMessage(array);
64: setMessageType(QUESTION_MESSAGE);
65: setOptionType(JOptionPane.OK_CANCEL_OPTION);
66:
67: JDialog dialog = createDialog(ContelligentClient.getFrame(),
68: title);
69:
70: dialog.setVisible(true);
71: if (getValue() instanceof Integer) {
72: PreferencesModule.getPreferences().put(
73: PreferencesModule.GROUP,
74: (String) groupBox.getSelectedItem());
75: return ((Integer) getValue()).intValue();
76: }
77: return CANCEL_OPTION;
78: }
79:
80: public String getLogin() {
81: return loginField.getText();
82: }
83:
84: public String getGroup() {
85: return (String) groupBox.getSelectedItem();
86: }
87:
88: public String getPassword() {
89: return new String(passwordField.getPassword());
90: }
91: }
|