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.vaadin.spring.events.EventScope;
|
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
|
import com.vaadin.ui.themes.ValoTheme;
|
20
|
|
21
|
import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
|
22
|
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
|
23
|
import eu.etaxonomy.cdm.vaadin.event.PasswordRevoveryEvent;
|
24
|
import eu.etaxonomy.cdm.vaadin.event.RegisterNewUserEvent;
|
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
|
}
|
45
|
|
46
|
@Override
|
47
|
protected void initContent() {
|
48
|
VerticalLayout root = new VerticalLayout();
|
49
|
root.setSizeFull();
|
50
|
root.addComponent(loginDialog);
|
51
|
root.setMargin(true);
|
52
|
root.setComponentAlignment(loginDialog, Alignment.MIDDLE_CENTER);
|
53
|
setCompositionRoot(root);
|
54
|
|
55
|
loginDialog.getLoginButton().addClickListener(e -> handleLoginClick(e));
|
56
|
loginDialog.getRegisterButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new RegisterNewUserEvent(e)));
|
57
|
loginDialog.getSendOnetimeLogin().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new PasswordRevoveryEvent(e)));
|
58
|
// NOTE: null viewName will be replaced by the default view name in NavigationManagerBean
|
59
|
loginDialog.getCancelLoginButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new NavigationEvent(null)));
|
60
|
loginDialog.getCancelRegistrationButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new NavigationEvent(null)));
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* @param e
|
65
|
*/
|
66
|
private void handleLoginClick(ClickEvent e) {
|
67
|
getViewEventBus().publish(EventScope.UI, this, new AuthenticationAttemptEvent(e, loginDialog.getUserName().getValue()));
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public LoginDialog getLoginDialog(){
|
72
|
return loginDialog;
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* {@inheritDoc}
|
77
|
*/
|
78
|
@Override
|
79
|
// TODO pull up to AbstractView and let AbstractView implement View?
|
80
|
public void enter(ViewChangeEvent event) {
|
81
|
getPresenter().onViewEnter();
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
public void showErrorMessage(String text){
|
86
|
loginDialog.getMessageLabel().setVisible(true);
|
87
|
loginDialog.getMessageLabel().setStyleName(ValoTheme.BUTTON_TINY + " " + ValoTheme.LABEL_FAILURE);
|
88
|
loginDialog.getMessageLabel().setValue(text);
|
89
|
}
|
90
|
|
91
|
|
92
|
@Override
|
93
|
public void clearMessage(){
|
94
|
loginDialog.getMessageLabel().setVisible(false);
|
95
|
loginDialog.getMessageLabel().setStyleName("");
|
96
|
loginDialog.getMessageLabel().setValue("");
|
97
|
}
|
98
|
}
|