51de1b0543615a1cb86683820a9f8fde36053517
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
.dialogs
;
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
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
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
;
42 * <p>Constructor for LoginDialog.</p>
44 * @param parentShell a {@link org.eclipse.swt.widgets.Shell} object.
46 public LoginDialog(Shell parentShell
) {
53 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
57 protected Control
createDialogArea(Composite parent
) {
58 Composite composite
= (Composite
) super.createDialogArea(parent
);
59 //add controls to composite as necessary
62 // Label for the heading
63 final CLabel titleLabel
= new CLabel(composite
, SWT
.NONE
);
64 titleLabel
.setText("User Login");
66 // Label for the username
67 final CLabel userNameLabel
= new CLabel(composite
, SWT
.NONE
);
68 userNameLabel
.setText("Username");
70 // Textfield for the username
71 text_username
= new Text(composite
, SWT
.BORDER
);
72 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
74 // Label for the password
75 final CLabel passwordLabel
= new CLabel(composite
, SWT
.NONE
);
76 passwordLabel
.setText("Password");
78 // Textfield for the password
79 text_password
= new Text(composite
, SWT
.PASSWORD
| SWT
.BORDER
);
80 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
89 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
92 protected void configureShell(Shell shell
) {
93 super.configureShell(shell
);
100 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
104 protected void okPressed() {
105 String username
= text_username
.getText();
106 String password
= text_password
.getText();
108 boolean result
= CdmStore
.getLoginManager().authenticate(username
, password
);
117 protected void cancelPressed() {
118 if(CdmStore
.getLoginManager().getAuthenticatedUser() != null){
119 super.cancelPressed();
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.");
125 CdmStore
.close(StoreUtil
.getMonitor());
126 super.cancelPressed();