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
.event
.ShortcutAction
.KeyCode
;
14 import com
.vaadin
.navigator
.View
;
15 import com
.vaadin
.navigator
.ViewChangeListener
.ViewChangeEvent
;
16 import com
.vaadin
.spring
.annotation
.SpringView
;
17 import com
.vaadin
.ui
.Alignment
;
18 import com
.vaadin
.ui
.Button
.ClickEvent
;
19 import com
.vaadin
.ui
.VerticalLayout
;
20 import com
.vaadin
.ui
.themes
.ValoTheme
;
22 import eu
.etaxonomy
.cdm
.vaadin
.component
.LoginDialog
;
23 import eu
.etaxonomy
.cdm
.vaadin
.event
.AuthenticationAttemptEvent
;
24 import eu
.etaxonomy
.cdm
.vaadin
.event
.PasswordRevoveryEvent
;
25 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegisterNewUserEvent
;
26 import eu
.etaxonomy
.vaadin
.mvp
.AbstractView
;
27 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
30 * @author a.kohlbecker
34 @SpringView(name
=LoginViewBean
.NAME
)
35 public class LoginViewBean
extends AbstractView
<LoginPresenter
> implements LoginView
, View
{
37 private static final long serialVersionUID
= 8527714663738364972L;
39 public static final String NAME
= "login";
41 private LoginDialog loginDialog
= new LoginDialog();
43 public LoginViewBean() {
48 protected void initContent() {
49 VerticalLayout root
= new VerticalLayout();
51 root
.addComponent(loginDialog
);
53 root
.setComponentAlignment(loginDialog
, Alignment
.MIDDLE_CENTER
);
54 setCompositionRoot(root
);
56 loginDialog
.getLoginButton().addClickListener(e
-> handleLoginClick(e
));
57 loginDialog
.getLoginButton().setClickShortcut(KeyCode
.ENTER
);
58 loginDialog
.getRegisterButton().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new RegisterNewUserEvent(e
)));
59 loginDialog
.getSendOnetimeLogin().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new PasswordRevoveryEvent(e
)));
60 // NOTE: null viewName will be replaced by the default view name in NavigationManagerBean
61 loginDialog
.getCancelLoginButton().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new NavigationEvent(null)));
62 loginDialog
.getCancelRegistrationButton().addClickListener(e
-> getViewEventBus().publish(EventScope
.UI
, this, new NavigationEvent(null)));
68 private void handleLoginClick(ClickEvent e
) {
69 getViewEventBus().publish(EventScope
.UI
, this, new AuthenticationAttemptEvent(e
, loginDialog
.getUserName().getValue()));
73 public LoginDialog
getLoginDialog(){
81 // TODO pull up to AbstractView and let AbstractView implement View?
82 public void enter(ViewChangeEvent event
) {
83 getPresenter().onViewEnter();
87 public void showErrorMessage(String text
){
88 loginDialog
.getMessageLabel().setVisible(true);
89 loginDialog
.getMessageLabel().setStyleName(ValoTheme
.BUTTON_TINY
+ " " + ValoTheme
.LABEL_FAILURE
);
90 loginDialog
.getMessageLabel().setValue(text
);
95 public void clearMessage(){
96 loginDialog
.getMessageLabel().setVisible(false);
97 loginDialog
.getMessageLabel().setStyleName("");
98 loginDialog
.getMessageLabel().setValue("");