ref #4611 Restructure string externalization for taxeditor.store
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / LoginDialog.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.dialog;
11
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;
21
22 import eu.etaxonomy.taxeditor.l10n.Messages;
23 import eu.etaxonomy.taxeditor.model.AbstractUtility;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
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 final String title;
40
41 public LoginDialog(Shell parentShell) {
42 super(parentShell);
43 title = Messages.LoginDialog_LOGIN;
44 }
45
46
47 /** {@inheritDoc} */
48 @Override
49 protected Control createDialogArea(Composite parent) {
50 Composite composite = (Composite) super.createDialogArea(parent);
51 //add controls to composite as necessary
52
53
54 // Label for the heading
55 final CLabel titleLabel = new CLabel(composite, SWT.NONE);
56 titleLabel.setText(Messages.LoginDialog_USER_LOGIN);
57
58 // Label for the username
59 final CLabel userNameLabel = new CLabel(composite, SWT.NONE);
60 userNameLabel.setText(Messages.LoginDialog_USER_NAME);
61
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));
65
66 // Label for the password
67 final CLabel passwordLabel = new CLabel(composite, SWT.NONE);
68 passwordLabel.setText(Messages.LoginDialog_PASSWORD);
69
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));
73
74
75 return composite;
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 protected void configureShell(Shell shell) {
81 super.configureShell(shell);
82 if (title != null) {
83 shell.setText(title);
84 }
85 }
86
87 /** {@inheritDoc} */
88 @Override
89 protected void okPressed() {
90 String username = text_username.getText();
91 String password = text_password.getText();
92
93 boolean result = CdmStore.getLoginManager().authenticate(username, password);
94
95 if(result){
96 super.okPressed();
97 }
98
99 }
100
101 @Override
102 protected void cancelPressed() {
103 if(CdmStore.getLoginManager().getAuthenticatedUser() != null){
104 super.cancelPressed();
105 }else{
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);
108
109 if(result){
110 CdmStore.close(AbstractUtility.getMonitor());
111 super.cancelPressed();
112 }
113 }
114 }
115 }