2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
12 import org
.eclipse
.jface
.dialogs
.Dialog
;
13 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.custom
.CLabel
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.swt
.widgets
.Text
;
22 import eu
.etaxonomy
.taxeditor
.Messages
;
23 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 * TODO wrap in a LoginModule
28 * see: http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/spi/LoginModule.html
34 public class LoginDialog
extends Dialog
{
36 private static Text text_password
;
37 private static Text text_username
;
39 private final String title
;
41 public LoginDialog(Shell parentShell
) {
43 title
= Messages
.LoginDialog_LOGIN
;
49 protected Control
createDialogArea(Composite parent
) {
50 Composite composite
= (Composite
) super.createDialogArea(parent
);
51 //add controls to composite as necessary
54 // Label for the heading
55 final CLabel titleLabel
= new CLabel(composite
, SWT
.NONE
);
56 titleLabel
.setText(Messages
.LoginDialog_USER_LOGIN
);
58 // Label for the username
59 final CLabel userNameLabel
= new CLabel(composite
, SWT
.NONE
);
60 userNameLabel
.setText(Messages
.LoginDialog_USER_NAME
);
62 // Textfield for the username
63 text_username
= new Text(composite
, SWT
.BORDER
);
64 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
66 // Label for the password
67 final CLabel passwordLabel
= new CLabel(composite
, SWT
.NONE
);
68 passwordLabel
.setText(Messages
.LoginDialog_PASSWORD
);
70 // Textfield for the password
71 text_password
= new Text(composite
, SWT
.PASSWORD
| SWT
.BORDER
);
72 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
80 protected void configureShell(Shell shell
) {
81 super.configureShell(shell
);
89 protected void okPressed() {
90 String username
= text_username
.getText();
91 String password
= text_password
.getText();
93 boolean result
= CdmStore
.getLoginManager().authenticate(username
, password
);
102 protected void cancelPressed() {
103 if(CdmStore
.getLoginManager().getAuthenticatedUser() != null){
104 super.cancelPressed();
106 // if there is no active user and the current user chooses to cancel, we close the connection
107 boolean result
= MessageDialog
.openConfirm(getShell(), Messages
.LoginDialog_REALLY_CANCEL
, Messages
.LoginDialog_CANCEL_MESSAGE
);
110 CdmStore
.close(AbstractUtility
.getMonitor());
111 super.cancelPressed();