1 |
5dd980ce
|
n.hoffmann
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
|
|
* European Distributed Institute of Taxonomy
|
5 |
|
|
* http://www.e-taxonomy.eu
|
6 |
|
|
*
|
7 |
|
|
* 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 |
|
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24 |
8754b7c4
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
25 |
5dd980ce
|
n.hoffmann
|
|
26 |
|
|
/**
|
27 |
3be6ef3e
|
n.hoffmann
|
* TODO wrap in a LoginModule
|
28 |
df60b579
|
n.hoffmann
|
* see: http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/spi/LoginModule.html
|
29 |
3be6ef3e
|
n.hoffmann
|
*
|
30 |
5dd980ce
|
n.hoffmann
|
* @author n.hoffmann
|
31 |
|
|
* @created 16.06.2009
|
32 |
|
|
* @version 1.0
|
33 |
|
|
*/
|
34 |
|
|
public class LoginDialog extends Dialog {
|
35 |
bcfe7309
|
n.hoffmann
|
|
36 |
df60b579
|
n.hoffmann
|
private static Text text_password;
|
37 |
|
|
private static Text text_username;
|
38 |
5dd980ce
|
n.hoffmann
|
|
39 |
c4b87786
|
n.hoffmann
|
private String title;
|
40 |
|
|
|
41 |
5dd980ce
|
n.hoffmann
|
/**
|
42 |
3be6ef3e
|
n.hoffmann
|
* <p>Constructor for LoginDialog.</p>
|
43 |
|
|
*
|
44 |
|
|
* @param parentShell a {@link org.eclipse.swt.widgets.Shell} object.
|
45 |
5dd980ce
|
n.hoffmann
|
*/
|
46 |
|
|
public LoginDialog(Shell parentShell) {
|
47 |
|
|
super(parentShell);
|
48 |
c4b87786
|
n.hoffmann
|
title = "Login";
|
49 |
5dd980ce
|
n.hoffmann
|
}
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/* (non-Javadoc)
|
53 |
|
|
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
54 |
|
|
*/
|
55 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
56 |
5dd980ce
|
n.hoffmann
|
@Override
|
57 |
|
|
protected Control createDialogArea(Composite parent) {
|
58 |
|
|
Composite composite = (Composite) super.createDialogArea(parent);
|
59 |
|
|
//add controls to composite as necessary
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
// Label for the heading
|
63 |
|
|
final CLabel titleLabel = new CLabel(composite, SWT.NONE);
|
64 |
|
|
titleLabel.setText("User Login");
|
65 |
|
|
|
66 |
|
|
// Label for the username
|
67 |
|
|
final CLabel userNameLabel = new CLabel(composite, SWT.NONE);
|
68 |
|
|
userNameLabel.setText("Username");
|
69 |
|
|
|
70 |
|
|
// Textfield for the username
|
71 |
df60b579
|
n.hoffmann
|
text_username = new Text(composite, SWT.BORDER);
|
72 |
|
|
text_username.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
73 |
5dd980ce
|
n.hoffmann
|
|
74 |
|
|
// Label for the password
|
75 |
|
|
final CLabel passwordLabel = new CLabel(composite, SWT.NONE);
|
76 |
|
|
passwordLabel.setText("Password");
|
77 |
|
|
|
78 |
|
|
// Textfield for the password
|
79 |
c4b87786
|
n.hoffmann
|
text_password = new Text(composite, SWT.PASSWORD | SWT.BORDER);
|
80 |
df60b579
|
n.hoffmann
|
text_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
81 |
5dd980ce
|
n.hoffmann
|
|
82 |
|
|
|
83 |
|
|
return composite;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
c4b87786
|
n.hoffmann
|
/*
|
87 |
|
|
* (non-Javadoc)
|
88 |
|
|
*
|
89 |
|
|
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
90 |
|
|
*/
|
91 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
92 |
c4b87786
|
n.hoffmann
|
protected void configureShell(Shell shell) {
|
93 |
|
|
super.configureShell(shell);
|
94 |
|
|
if (title != null) {
|
95 |
|
|
shell.setText(title);
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
5dd980ce
|
n.hoffmann
|
|
99 |
|
|
/* (non-Javadoc)
|
100 |
|
|
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
|
101 |
|
|
*/
|
102 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
103 |
5dd980ce
|
n.hoffmann
|
@Override
|
104 |
|
|
protected void okPressed() {
|
105 |
8754b7c4
|
n.hoffmann
|
String username = text_username.getText();
|
106 |
|
|
String password = text_password.getText();
|
107 |
|
|
|
108 |
|
|
boolean result = CdmStore.getLoginManager().authenticate(username, password);
|
109 |
|
|
|
110 |
|
|
if(result){
|
111 |
|
|
super.okPressed();
|
112 |
|
|
}
|
113 |
5dd980ce
|
n.hoffmann
|
|
114 |
|
|
}
|
115 |
|
|
|
116 |
8754b7c4
|
n.hoffmann
|
@Override
|
117 |
|
|
protected void cancelPressed() {
|
118 |
2cb6f654
|
n.hoffmann
|
if(CdmStore.getLoginManager().getAuthenticatedUser() != null){
|
119 |
8754b7c4
|
n.hoffmann
|
super.cancelPressed();
|
120 |
2cb6f654
|
n.hoffmann
|
}else{
|
121 |
|
|
// if there is no active user and the current user chooses to cancel, we close the connection
|
122 |
|
|
boolean result = MessageDialog.openConfirm(getShell(), "Do you really want to cancel", "Aborting the login procedure will close the database.");
|
123 |
|
|
|
124 |
|
|
if(result){
|
125 |
|
|
CdmStore.close(StoreUtil.getMonitor());
|
126 |
|
|
super.cancelPressed();
|
127 |
|
|
}
|
128 |
8754b7c4
|
n.hoffmann
|
}
|
129 |
|
|
}
|
130 |
5dd980ce
|
n.hoffmann
|
}
|