Subversion Repositories SmartDukaan

Rev

Rev 1962 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
3
import com.google.gwt.event.dom.client.ClickEvent;
4
import com.google.gwt.event.dom.client.ClickHandler;
5
import com.google.gwt.user.client.ui.Button;
6
import com.google.gwt.user.client.ui.Composite;
7
import com.google.gwt.user.client.ui.HorizontalPanel;
8
import com.google.gwt.user.client.ui.Label;
9
import com.google.gwt.user.client.ui.PasswordTextBox;
10
import com.google.gwt.user.client.ui.TextBox;
11
import com.google.gwt.user.client.ui.VerticalPanel;
12
 
2427 ankur.sing 13
/**
14
 * Login screen for the catalog dashboard. 
15
 * <p>In EntryPoint class CatalogDashboard.java, LoginScreen is initialised and added to the root panel.
16
 * If authentication is successful, root panel is cleared and dashboard widgets are added to the root panel.
17
 */
1961 ankur.sing 18
public class LoginScreen extends Composite {
19
    private Label errLabel = new Label("");
20
    private Label headerMessage = new Label("Please key in your credentials");
21
    private Label userLabel = new Label("Username");
22
    private Label passwordLabel = new Label("Password");
23
    private TextBox userTextBox = new TextBox();
24
    private PasswordTextBox passwordTextBox = new PasswordTextBox();
25
    private Button submitButton = new Button("Login");
26
 
27
    interface LoginListener {
28
        void onLoginPressed(String username, String password);
29
    }
30
    private LoginListener loginListener;
31
 
32
    public LoginScreen(){
33
 
34
        //errLabel.setVisible(false);
35
        VerticalPanel vertPanel = new VerticalPanel();
36
        vertPanel.setSpacing(5);
37
        HorizontalPanel horizontalPanel = new HorizontalPanel();
38
        horizontalPanel.setSpacing(5);
39
        vertPanel.add(headerMessage);
40
        vertPanel.add(errLabel);
41
        vertPanel.add(horizontalPanel);
42
        horizontalPanel.add(userLabel);
43
        horizontalPanel.add(userTextBox);
44
        horizontalPanel.setCellWidth(horizontalPanel.getWidget(0), "128px");
45
        horizontalPanel.setCellWidth(horizontalPanel.getWidget(1), "128px");
46
        vertPanel.setCellHeight(vertPanel.getWidget(0), "10px");
47
        vertPanel.setCellHeight(vertPanel.getWidget(1), "10px");
48
        vertPanel.setCellHeight(vertPanel.getWidget(2), "10px");
49
        horizontalPanel = new HorizontalPanel();
50
        horizontalPanel.setSpacing(5);
51
        vertPanel.add(horizontalPanel);
52
        horizontalPanel.add(passwordLabel);
53
        horizontalPanel.add(passwordTextBox);
54
        horizontalPanel.setCellWidth(horizontalPanel.getWidget(0), "128px");
55
        horizontalPanel.setCellWidth(horizontalPanel.getWidget(1), "128px");
56
        vertPanel.setCellHeight(vertPanel.getWidget(3), "10px");
57
        vertPanel.add(submitButton);
58
        vertPanel.setStyleName("centerBox");
59
 
60
        submitButton.addClickHandler(new ClickHandler() {
61
            @Override
62
            public void onClick(ClickEvent event) {
63
                loginListener.onLoginPressed(userTextBox.getText(), passwordTextBox.getText());
64
            }
65
        });
66
        initWidget(vertPanel);
67
    }
68
 
69
    public void setLoginListener(LoginListener loginListener) {
70
        this.loginListener = loginListener;
71
    }
72
 
73
    public void setErrorText(String errorMessage) {
74
        errLabel.setText(errorMessage);
75
    }
76
 
77
    public void clearFields() {
78
        userTextBox.setText("");
79
        passwordTextBox.setText("");
80
    }
81
}