Project

General

Profile

Download (3.25 KB) Statistics
| Branch: | Tag: | Revision:
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
import com.vaadin.ui.themes.ValoTheme;
18

    
19
import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
20
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
21
import eu.etaxonomy.cdm.vaadin.event.PasswordRevoveryEvent;
22
import eu.etaxonomy.cdm.vaadin.event.RegisterNewUserEvent;
23
import eu.etaxonomy.vaadin.mvp.AbstractView;
24
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
25

    
26
/**
27
 * @author a.kohlbecker
28
 * @since Apr 25, 2017
29
 *
30
 */
31
@SpringView(name=LoginViewBean.NAME)
32
public class LoginViewBean  extends AbstractView<LoginPresenter> implements LoginView, View  {
33

    
34
    private static final long serialVersionUID = 8527714663738364972L;
35

    
36
    public static final String NAME = "login";
37

    
38
    private LoginDialog loginDialog = new LoginDialog();
39

    
40
    public LoginViewBean() {
41
        super();
42
    }
43

    
44
    @Override
45
    protected void initContent() {
46
        VerticalLayout root = new VerticalLayout();
47
        root.setSizeFull();
48
        root.addComponent(loginDialog);
49
        root.setMargin(true);
50
        root.setComponentAlignment(loginDialog, Alignment.MIDDLE_CENTER);
51
        setCompositionRoot(root);
52

    
53
        loginDialog.getLoginButton().addClickListener(e -> handleLoginClick(e));
54
        loginDialog.getRegisterButton().addClickListener(e -> eventBus.publishEvent(new RegisterNewUserEvent(e)));
55
        loginDialog.getSendOnetimeLogin().addClickListener(e -> eventBus.publishEvent(new PasswordRevoveryEvent(e)));
56
        // NOTE: null viewName will be replaced by the default view name in NavigationManagerBean
57
        loginDialog.getCancelLoginButton().addClickListener(e -> eventBus.publishEvent(new NavigationEvent(null)));
58
        loginDialog.getCancelRegistrationButton().addClickListener(e -> eventBus.publishEvent(new NavigationEvent(null)));
59
    }
60

    
61
    /**
62
     * @param e
63
     */
64
    private void handleLoginClick(ClickEvent e) {
65
        eventBus.publishEvent(new AuthenticationAttemptEvent(e, loginDialog.getUserName().getValue()));
66
    }
67

    
68
    @Override
69
    public LoginDialog getLoginDialog(){
70
        return loginDialog;
71
    }
72

    
73
    /**
74
     * {@inheritDoc}
75
     */
76
    @Override
77
    // TODO pull up to AbstractView and let AbstractView implement View?
78
    public void enter(ViewChangeEvent event) {
79
        getPresenter().onViewEnter();
80
    }
81

    
82
    @Override
83
    public void showErrorMessage(String text){
84
        loginDialog.getMessageLabel().setVisible(true);
85
        loginDialog.getMessageLabel().setStyleName(ValoTheme.BUTTON_TINY + " " +  ValoTheme.LABEL_FAILURE);
86
        loginDialog.getMessageLabel().setValue(text);
87
    }
88

    
89

    
90
    @Override
91
    public void clearMessage(){
92
        loginDialog.getMessageLabel().setVisible(false);
93
        loginDialog.getMessageLabel().setStyleName("");
94
        loginDialog.getMessageLabel().setValue("");
95
    }
96
}
(8-8/10)