1 |
5dd980ce
|
n.hoffmann
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
8aac42d2
|
Patrick Plitzner
|
* European Distributed Institute of Taxonomy
|
5 |
5dd980ce
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
6 |
8aac42d2
|
Patrick Plitzner
|
*
|
7 |
5dd980ce
|
n.hoffmann
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.dialog;
|
12 |
5dd980ce
|
n.hoffmann
|
|
13 |
|
|
import org.eclipse.jface.dialogs.Dialog;
|
14 |
8754b7c4
|
n.hoffmann
|
import org.eclipse.jface.dialogs.MessageDialog;
|
15 |
5dd980ce
|
n.hoffmann
|
import org.eclipse.swt.SWT;
|
16 |
|
|
import org.eclipse.swt.custom.CLabel;
|
17 |
|
|
import org.eclipse.swt.layout.GridData;
|
18 |
|
|
import org.eclipse.swt.widgets.Composite;
|
19 |
|
|
import org.eclipse.swt.widgets.Control;
|
20 |
|
|
import org.eclipse.swt.widgets.Shell;
|
21 |
|
|
import org.eclipse.swt.widgets.Text;
|
22 |
|
|
|
23 |
8aac42d2
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.Messages;
|
24 |
|
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25 |
5dd980ce
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
3be6ef3e
|
n.hoffmann
|
* TODO wrap in a LoginModule
|
29 |
df60b579
|
n.hoffmann
|
* see: http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/spi/LoginModule.html
|
30 |
3be6ef3e
|
n.hoffmann
|
*
|
31 |
5dd980ce
|
n.hoffmann
|
* @author n.hoffmann
|
32 |
|
|
* @created 16.06.2009
|
33 |
|
|
* @version 1.0
|
34 |
|
|
*/
|
35 |
|
|
public class LoginDialog extends Dialog {
|
36 |
8aac42d2
|
Patrick Plitzner
|
|
37 |
df60b579
|
n.hoffmann
|
private static Text text_password;
|
38 |
|
|
private static Text text_username;
|
39 |
5dd980ce
|
n.hoffmann
|
|
40 |
8aac42d2
|
Patrick Plitzner
|
private final String title;
|
41 |
c4b87786
|
n.hoffmann
|
|
42 |
5dd980ce
|
n.hoffmann
|
public LoginDialog(Shell parentShell) {
|
43 |
|
|
super(parentShell);
|
44 |
8aac42d2
|
Patrick Plitzner
|
title = Messages.LoginDialog_LOGIN;
|
45 |
5dd980ce
|
n.hoffmann
|
}
|
46 |
|
|
|
47 |
8aac42d2
|
Patrick Plitzner
|
|
48 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
49 |
5dd980ce
|
n.hoffmann
|
@Override
|
50 |
|
|
protected Control createDialogArea(Composite parent) {
|
51 |
|
|
Composite composite = (Composite) super.createDialogArea(parent);
|
52 |
|
|
//add controls to composite as necessary
|
53 |
8aac42d2
|
Patrick Plitzner
|
|
54 |
5dd980ce
|
n.hoffmann
|
|
55 |
|
|
// Label for the heading
|
56 |
|
|
final CLabel titleLabel = new CLabel(composite, SWT.NONE);
|
57 |
8aac42d2
|
Patrick Plitzner
|
titleLabel.setText(Messages.LoginDialog_USER_LOGIN);
|
58 |
5dd980ce
|
n.hoffmann
|
|
59 |
|
|
// Label for the username
|
60 |
|
|
final CLabel userNameLabel = new CLabel(composite, SWT.NONE);
|
61 |
8aac42d2
|
Patrick Plitzner
|
userNameLabel.setText(Messages.LoginDialog_USER_NAME);
|
62 |
5dd980ce
|
n.hoffmann
|
|
63 |
|
|
// Textfield for the username
|
64 |
df60b579
|
n.hoffmann
|
text_username = new Text(composite, SWT.BORDER);
|
65 |
|
|
text_username.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
66 |
5dd980ce
|
n.hoffmann
|
|
67 |
|
|
// Label for the password
|
68 |
|
|
final CLabel passwordLabel = new CLabel(composite, SWT.NONE);
|
69 |
8aac42d2
|
Patrick Plitzner
|
passwordLabel.setText(Messages.LoginDialog_PASSWORD);
|
70 |
5dd980ce
|
n.hoffmann
|
|
71 |
|
|
// Textfield for the password
|
72 |
c4b87786
|
n.hoffmann
|
text_password = new Text(composite, SWT.PASSWORD | SWT.BORDER);
|
73 |
df60b579
|
n.hoffmann
|
text_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
74 |
8aac42d2
|
Patrick Plitzner
|
|
75 |
|
|
|
76 |
5dd980ce
|
n.hoffmann
|
return composite;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
80 |
8aac42d2
|
Patrick Plitzner
|
@Override
|
81 |
c4b87786
|
n.hoffmann
|
protected void configureShell(Shell shell) {
|
82 |
|
|
super.configureShell(shell);
|
83 |
|
|
if (title != null) {
|
84 |
|
|
shell.setText(title);
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
5dd980ce
|
n.hoffmann
|
|
88 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
89 |
5dd980ce
|
n.hoffmann
|
@Override
|
90 |
|
|
protected void okPressed() {
|
91 |
8754b7c4
|
n.hoffmann
|
String username = text_username.getText();
|
92 |
|
|
String password = text_password.getText();
|
93 |
8aac42d2
|
Patrick Plitzner
|
|
94 |
8754b7c4
|
n.hoffmann
|
boolean result = CdmStore.getLoginManager().authenticate(username, password);
|
95 |
8aac42d2
|
Patrick Plitzner
|
|
96 |
8754b7c4
|
n.hoffmann
|
if(result){
|
97 |
|
|
super.okPressed();
|
98 |
|
|
}
|
99 |
8aac42d2
|
Patrick Plitzner
|
|
100 |
|
|
}
|
101 |
|
|
|
102 |
8754b7c4
|
n.hoffmann
|
@Override
|
103 |
8aac42d2
|
Patrick Plitzner
|
protected void cancelPressed() {
|
104 |
2cb6f654
|
n.hoffmann
|
if(CdmStore.getLoginManager().getAuthenticatedUser() != null){
|
105 |
8754b7c4
|
n.hoffmann
|
super.cancelPressed();
|
106 |
2cb6f654
|
n.hoffmann
|
}else{
|
107 |
|
|
// if there is no active user and the current user chooses to cancel, we close the connection
|
108 |
8aac42d2
|
Patrick Plitzner
|
boolean result = MessageDialog.openConfirm(getShell(), Messages.LoginDialog_REALLY_CANCEL, Messages.LoginDialog_CANCEL_MESSAGE);
|
109 |
|
|
|
110 |
2cb6f654
|
n.hoffmann
|
if(result){
|
111 |
8aac42d2
|
Patrick Plitzner
|
CdmStore.close(AbstractUtility.getMonitor());
|
112 |
2cb6f654
|
n.hoffmann
|
super.cancelPressed();
|
113 |
|
|
}
|
114 |
8754b7c4
|
n.hoffmann
|
}
|
115 |
|
|
}
|
116 |
5dd980ce
|
n.hoffmann
|
}
|