3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
13 import org
.eclipse
.jface
.dialogs
.Dialog
;
14 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
15 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
;
23 import eu
.etaxonomy
.taxeditor
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 * TODO wrap in a LoginModule
29 * see: http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/spi/LoginModule.html
35 public class LoginDialog
extends Dialog
{
37 private static Text text_password
;
38 private static Text text_username
;
40 private final String title
;
42 public LoginDialog(Shell parentShell
) {
44 title
= Messages
.LoginDialog_LOGIN
;
50 protected Control
createDialogArea(Composite parent
) {
51 Composite composite
= (Composite
) super.createDialogArea(parent
);
52 //add controls to composite as necessary
55 // Label for the heading
56 final CLabel titleLabel
= new CLabel(composite
, SWT
.NONE
);
57 titleLabel
.setText(Messages
.LoginDialog_USER_LOGIN
);
59 // Label for the username
60 final CLabel userNameLabel
= new CLabel(composite
, SWT
.NONE
);
61 userNameLabel
.setText(Messages
.LoginDialog_USER_NAME
);
63 // Textfield for the username
64 text_username
= new Text(composite
, SWT
.BORDER
);
65 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
67 // Label for the password
68 final CLabel passwordLabel
= new CLabel(composite
, SWT
.NONE
);
69 passwordLabel
.setText(Messages
.LoginDialog_PASSWORD
);
71 // Textfield for the password
72 text_password
= new Text(composite
, SWT
.PASSWORD
| SWT
.BORDER
);
73 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
81 protected void configureShell(Shell shell
) {
82 super.configureShell(shell
);
90 protected void okPressed() {
91 String username
= text_username
.getText();
92 String password
= text_password
.getText();
94 boolean result
= CdmStore
.getLoginManager().authenticate(username
, password
);
103 protected void cancelPressed() {
104 if(CdmStore
.getLoginManager().getAuthenticatedUser() != null){
105 super.cancelPressed();
107 // if there is no active user and the current user chooses to cancel, we close the connection
108 boolean result
= MessageDialog
.openConfirm(getShell(), Messages
.LoginDialog_REALLY_CANCEL
, Messages
.LoginDialog_CANCEL_MESSAGE
);
111 CdmStore
.close(AbstractUtility
.getMonitor());
112 super.cancelPressed();