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