Project

General

Profile

Download (3.48 KB) Statistics
| Branch: | Tag: | Revision:
1
// $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
package eu.etaxonomy.taxeditor.ui.dialog;
12

    
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;
22

    
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24
import eu.etaxonomy.taxeditor.store.StoreUtil;
25

    
26
/**
27
 * TODO wrap in a LoginModule
28
 * see: http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/spi/LoginModule.html
29
 *
30
 * @author n.hoffmann
31
 * @created 16.06.2009
32
 * @version 1.0
33
 */
34
public class LoginDialog extends Dialog {
35
	
36
	private static Text text_password;
37
	private static Text text_username;
38

    
39
	private String title;
40

    
41
	/**
42
	 * <p>Constructor for LoginDialog.</p>
43
	 *
44
	 * @param parentShell a {@link org.eclipse.swt.widgets.Shell} object.
45
	 */
46
	public LoginDialog(Shell parentShell) {
47
		super(parentShell);
48
		title = "Login";
49
	}
50
		
51

    
52
	/* (non-Javadoc)
53
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
54
	 */
55
	/** {@inheritDoc} */
56
	@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
		text_username = new Text(composite, SWT.BORDER);
72
		text_username.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
73

    
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
		text_password = new Text(composite, SWT.PASSWORD | SWT.BORDER);
80
		text_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
81
		
82
		
83
		return composite;
84
	}
85

    
86
    /*
87
     * (non-Javadoc)
88
     * 
89
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
90
     */
91
    /** {@inheritDoc} */
92
    protected void configureShell(Shell shell) {
93
        super.configureShell(shell);
94
        if (title != null) {
95
			shell.setText(title);
96
		}
97
    }
98

    
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
101
	 */
102
	/** {@inheritDoc} */
103
	@Override
104
	protected void okPressed() {
105
		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
		
114
	}	
115
	
116
	@Override
117
	protected void cancelPressed() {		
118
		if(CdmStore.getLoginManager().getAuthenticatedUser() != null){
119
			super.cancelPressed();
120
		}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
		}
129
	}
130
}
(1-1/2)