2 * Copyright (C) 2017 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.
9 package eu
.etaxonomy
.cdm
.vaadin
.view
;
11 import org
.vaadin
.spring
.events
.EventScope
;
13 import com
.vaadin
.data
.validator
.StringLengthValidator
;
14 import com
.vaadin
.event
.ShortcutAction
.KeyCode
;
15 import com
.vaadin
.navigator
.View
;
16 import com
.vaadin
.navigator
.ViewChangeListener
.ViewChangeEvent
;
17 import com
.vaadin
.spring
.annotation
.SpringView
;
18 import com
.vaadin
.ui
.Alignment
;
19 import com
.vaadin
.ui
.Button
.ClickEvent
;
20 import com
.vaadin
.ui
.VerticalLayout
;
21 import com
.vaadin
.ui
.themes
.ValoTheme
;
23 import eu
.etaxonomy
.cdm
.vaadin
.component
.LoginDialog
;
24 import eu
.etaxonomy
.cdm
.vaadin
.event
.AuthenticationAttemptEvent
;
25 import eu
.etaxonomy
.cdm
.vaadin
.event
.PasswordRevoveryEvent
;
26 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegisterNewUserEvent
;
27 import eu
.etaxonomy
.vaadin
.mvp
.AbstractView
;
28 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
31 * @author a.kohlbecker
35 @SpringView(name
=LoginViewBean
.NAME
)
36 public class LoginViewBean
extends AbstractView
<LoginPresenter
> implements LoginView
, View
{
38 private static final long serialVersionUID
= 8527714663738364972L;
40 public static final String NAME
= "login";
42 private LoginDialog loginDialog
= new LoginDialog();
44 public LoginViewBean() {
49 protected void initContent() {
50 VerticalLayout root
= new VerticalLayout();
52 root
.addComponent(loginDialog
);
54 root
.setComponentAlignment(loginDialog
, Alignment
.MIDDLE_CENTER
);
55 setCompositionRoot(root
);
57 loginDialog
.getLoginButton().addClickListener(e
-> handleLoginClick(e
));
58 loginDialog
.getLoginButton().setClickShortcut(KeyCode
.ENTER
);
59 loginDialog
.getRegisterButton().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new RegisterNewUserEvent(e
)));
60 loginDialog
.getSendOnetimeLogin().addClickListener(e
-> {
61 getViewEventBus().publish(this, new PasswordRevoveryEvent(e
));
63 // NOTE: null viewName will be replaced by the default view name in NavigationManagerBean
64 loginDialog
.getCancelLoginButton().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new NavigationEvent(null)));
66 loginDialog
.getCancelRegistrationButton().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new NavigationEvent(null)));
68 StringLengthValidator nameOrEmailValidator
= new StringLengthValidator("Please enter your username or email address.");
69 loginDialog
.getUserNameOrEmail().addValidator(nameOrEmailValidator
);
70 loginDialog
.getUserNameOrEmail().addTextChangeListener(e
-> {
71 String text
= e
.getText();
72 logger
.debug("text: " + text
);
73 loginDialog
.getSendOnetimeLogin().setEnabled(text
!= null && text
.length() > 1);
77 private void handleLoginClick(ClickEvent e
) {
78 getViewEventBus().publish(EventScope
.UI
, this, new AuthenticationAttemptEvent(e
, loginDialog
.getUserName().getValue()));
82 public LoginDialog
getLoginDialog(){
87 // TODO pull up to AbstractView and let AbstractView implement View?
88 public void enter(ViewChangeEvent event
) {
89 getPresenter().onViewEnter();
93 public void showErrorMessage(String text
){
94 loginDialog
.getLoginMessageLabel().setVisible(true);
95 loginDialog
.getLoginMessageLabel().setStyleName(ValoTheme
.BUTTON_TINY
+ " " + ValoTheme
.LABEL_FAILURE
);
96 loginDialog
.getLoginMessageLabel().setValue(text
);
100 public void clearMessage(){
101 loginDialog
.getLoginMessageLabel().setVisible(false);
102 loginDialog
.getLoginMessageLabel().setStyleName("");
103 loginDialog
.getLoginMessageLabel().setValue("");