loginLayout = new VerticalLayout();
loginLayout.setSizeFull();
loginLayout.addStyleName("login-layout");
root.addComponent(loginLayout);
final CssLayout loginPanel = new CssLayout();
loginPanel.addStyleName("login-panel");
HorizontalLayout labels = new HorizontalLayout();
labels.setWidth("100%");
labels.setMargin(true);
labels.addStyleName("labels");
loginPanel.addComponent(labels);
Label welcome = new Label("Bienvenido");
welcome.setSizeUndefined();
welcome.addStyleName("h4");
labels.addComponent(welcome);
labels.setComponentAlignment(welcome, Alignment.MIDDLE_LEFT);
Label title = new Label("Finanzas Budget");
title.setSizeUndefined();
title.addStyleName("h2");
title.addStyleName("light");
labels.addComponent(title);
labels.setComponentAlignment(title, Alignment.MIDDLE_RIGHT);
HorizontalLayout fields = new HorizontalLayout();
fields.setSpacing(true);
fields.setMargin(true);
fields.addStyleName("fields");
final TextField username = new TextField("Username");
username.focus();
fields.addComponent(username);
final PasswordField password = new PasswordField("Password");
fields.addComponent(password);
//TODO: Borrar
password.setValue("root");
username.setValue("admin@tesis.com");
final Button signin = new Button("Sign In");
signin.addStyleName("default");
fields.addComponent(signin);
fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);
final ShortcutListener enter = new ShortcutListener("Sign In",
KeyCode.ENTER, null) {
/**
*
*/
private static final long serialVersionUID = -2425923923914266067L;
@Override
public void handleAction(Object sender, Object target) {
signin.click();
}
};
signin.addClickListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = 8646342267124075364L;
@Override
public void buttonClick(ClickEvent event) {
if (username.getValue() != null
&& password.getValue() != null
)
idUsuario = Usuario.Login(username.getValue(),password.getValue());
if (idUsuario != null){
signin.removeShortcutListener(enter);
buildMainView();
} else {
if (loginPanel.getComponentCount() > 2) {
// Remove the previous error message
loginPanel.removeComponent(loginPanel.getComponent(2));
}
// Add new error message
Label error = new Label(
"Wrong username or password. <span>Hint: try empty values</span>",
ContentMode.HTML);
error.addStyleName("error");
error.setSizeUndefined();
error.addStyleName("light");
// Add animation
error.addStyleName("v-animate-reveal");
loginPanel.addComponent(error);
username.focus();
}
}
});
signin.addShortcutListener(enter);
loginPanel.addComponent(fields);
loginLayout.addComponent(loginPanel);
loginLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
}