1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.cdm.vaadin.view;
|
10
|
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
|
13
|
import com.vaadin.navigator.View;
|
14
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
15
|
import com.vaadin.spring.annotation.SpringView;
|
16
|
import com.vaadin.ui.Alignment;
|
17
|
import com.vaadin.ui.Button.ClickEvent;
|
18
|
import com.vaadin.ui.VerticalLayout;
|
19
|
|
20
|
import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
|
21
|
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
|
22
|
import eu.etaxonomy.cdm.vaadin.event.PasswordRevoveryEvent;
|
23
|
import eu.etaxonomy.cdm.vaadin.event.RegisterNewUserEvent;
|
24
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUI;
|
25
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
26
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
27
|
|
28
|
/**
|
29
|
* @author a.kohlbecker
|
30
|
* @since Apr 25, 2017
|
31
|
*
|
32
|
*/
|
33
|
@SpringView(name=LoginViewBean.NAME)
|
34
|
public class LoginViewBean extends AbstractView<LoginPresenter> implements LoginView, View {
|
35
|
|
36
|
private static final long serialVersionUID = 8527714663738364972L;
|
37
|
|
38
|
public static final String NAME = "login";
|
39
|
|
40
|
private LoginDialog loginDialog = new LoginDialog();
|
41
|
|
42
|
public LoginViewBean() {
|
43
|
super();
|
44
|
VerticalLayout root = new VerticalLayout();
|
45
|
root.setSizeFull();
|
46
|
root.addComponent(loginDialog);
|
47
|
root.setMargin(true);
|
48
|
root.setComponentAlignment(loginDialog, Alignment.MIDDLE_CENTER);
|
49
|
setCompositionRoot(root);
|
50
|
|
51
|
loginDialog.getLoginButton().addClickListener(e -> handleLoginClick(e));
|
52
|
loginDialog.getRegisterButton().addClickListener(e -> eventBus.publishEvent(new RegisterNewUserEvent(e)));
|
53
|
loginDialog.getSendOnetimeLogin().addClickListener(e -> eventBus.publishEvent(new PasswordRevoveryEvent(e)));
|
54
|
loginDialog.getCancelLoginButton().addClickListener(e -> eventBus.publishEvent(new NavigationEvent(RegistrationUI.INITIAL_VIEW)));
|
55
|
loginDialog.getCancelRegistrationButton().addClickListener(e -> eventBus.publishEvent(new NavigationEvent(RegistrationUI.INITIAL_VIEW)));
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* @param e
|
60
|
*/
|
61
|
private void handleLoginClick(ClickEvent e) {
|
62
|
eventBus.publishEvent(new AuthenticationAttemptEvent(e, loginDialog.getUserName().getValue()));
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public LoginDialog getLoginDialog(){
|
67
|
return loginDialog;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* {@inheritDoc}
|
72
|
*/
|
73
|
@Override
|
74
|
@Autowired
|
75
|
// TODO pull up to AbstractView?
|
76
|
protected void injectPresenter(LoginPresenter presenter) {
|
77
|
setPresenter(presenter);
|
78
|
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* {@inheritDoc}
|
83
|
*/
|
84
|
@Override
|
85
|
// TODO pull up to AbstractView and let AbstractView implement View?
|
86
|
public void enter(ViewChangeEvent event) {
|
87
|
getPresenter().onViewEnter();
|
88
|
}
|
89
|
|
90
|
}
|