Example usage for com.vaadin.ui FormLayout setSizeUndefined

List of usage examples for com.vaadin.ui FormLayout setSizeUndefined

Introduction

In this page you can find the example usage for com.vaadin.ui FormLayout setSizeUndefined.

Prototype

@Override
    public void setSizeUndefined() 

Source Link

Usage

From source file:org.vaadin.spring.samples.security.shared.LoginUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    getPage().setTitle("Vaadin Shared Security Demo Login");

    FormLayout loginForm = new FormLayout();
    loginForm.setSizeUndefined();

    userName = new TextField("Username");
    passwordField = new PasswordField("Password");
    rememberMe = new CheckBox("Remember me");
    login = new Button("Login");
    loginForm.addComponent(userName);//from  w ww .  jav  a2s  .  com
    loginForm.addComponent(passwordField);
    loginForm.addComponent(rememberMe);
    loginForm.addComponent(login);
    login.addStyleName(ValoTheme.BUTTON_PRIMARY);
    login.setDisableOnClick(true);
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            login();
        }
    });

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setSpacing(true);
    loginLayout.setSizeUndefined();

    if (request.getParameter("logout") != null) {
        loggedOutLabel = new Label("You have been logged out!");
        loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS);
        loggedOutLabel.setSizeUndefined();
        loginLayout.addComponent(loggedOutLabel);
        loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER);
    }

    loginLayout.addComponent(loginFailedLabel = new Label());
    loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER);
    loginFailedLabel.setSizeUndefined();
    loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    loginFailedLabel.setVisible(false);

    loginLayout.addComponent(loginForm);
    loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER);

    VerticalLayout rootLayout = new VerticalLayout(loginLayout);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER);
    setContent(rootLayout);
    setSizeFull();
}

From source file:trader.LoginUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    setLocale(Locale.ENGLISH);/*from   ww  w . java2 s  .  com*/

    FormLayout loginForm = new FormLayout();
    loginForm.setSizeUndefined();

    loginForm.addComponent(userName = new TextField("Username"));
    loginForm.addComponent(passwordField = new PasswordField("Password"));
    loginForm.addComponent(rememberMe = new CheckBox("Remember me"));
    loginForm.addComponent(login = new Button("Login"));
    login.addStyleName(ValoTheme.BUTTON_PRIMARY);
    login.setDisableOnClick(true);
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(new Button.ClickListener() {
        /**
        * 
        */
        private static final long serialVersionUID = 7813011112417170727L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            login();
        }
    });

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setSpacing(true);
    loginLayout.setSizeUndefined();

    if (request.getParameter("logout") != null) {
        loggedOutLabel = new Label("You have been logged out!");
        loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS);
        loggedOutLabel.setSizeUndefined();
        loginLayout.addComponent(loggedOutLabel);
        loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER);
    }

    loginLayout.addComponent(loginFailedLabel = new Label());
    loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER);
    loginFailedLabel.setSizeUndefined();
    loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    loginFailedLabel.setVisible(false);

    loginLayout.addComponent(loginForm);
    loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER);

    VerticalLayout rootLayout = new VerticalLayout(loginLayout);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER);
    setContent(rootLayout);
    setSizeFull();
}

From source file:xyz.iipster.ui.ChangePasswordComponent.java

License:Apache License

@Override
public void attach() {
    super.attach();

    setModal(true);/*from  w ww. j  a v  a2 s .  co m*/
    setClosable(false);
    setResizable(false);

    setCaption(i18N.get("iipster.changePassword.title"));

    oldPasswordField.setCaption(i18N.get("iipster.changePassword.oldPassword.label"));
    newPasswordField1.setCaption(i18N.get("iipster.changePassword.newPassword1.label"));
    newPasswordField2.setCaption(i18N.get("iipster.changePassword.newPassword2.label"));

    VerticalLayout vl = new VerticalLayout();
    vl.setSizeUndefined();
    vl.setMargin(true);

    if (currentPassword != null) {
        // currentPassowrd is not null, that means we are on login screen and the password is expired
        Label expiredLabel = new Label(i18N.get("iipster.changePassword.expired.text"));
        vl.addComponent(expiredLabel);
    }

    FormLayout fl = new FormLayout();
    fl.setSizeUndefined();
    fl.addComponents(oldPasswordField, newPasswordField1, newPasswordField2);
    vl.addComponent(fl);
    vl.setExpandRatio(fl, 1F);

    okButton.setCaption(i18N.get("iipster.ok"));
    okButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    okButton.addClickListener(e -> {
        try {
            ibmiService.changePassword(
                    securityUtils.getAuthentication() == null ? userName
                            : securityUtils.getAuthentication().getPrincipal().toString(),
                    oldPasswordField.getValue(), newPasswordField1.getValue());
            close();
            eventBus.post(new PasswordChangedEvent(newPasswordField1.getValue()));
        } catch (BadCredentialsException e1) {
            Notification.show(i18N.get("iipster.changePassword.oldPassword.error"),
                    Notification.Type.WARNING_MESSAGE);
            oldPasswordField.focus();
        } catch (IOException e1) {
            Notification.show("Error while changing password", Notification.Type.ERROR_MESSAGE);
        } catch (NewPasswordInvalidException e1) {
            Notification.show(i18N.get(e1.getMessageId()), Notification.Type.WARNING_MESSAGE);
            newPasswordField1.focus();
        }
    });

    cancelButton.setCaption(i18N.get("iipster.cancel"));
    cancelButton.setClickShortcut(ShortcutAction.KeyCode.F12);
    cancelButton.addClickListener(e -> {
        close();
    });

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSizeUndefined();
    hl.setSpacing(true);
    hl.addComponents(okButton, cancelButton);

    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

    setContent(vl);

    if (currentPassword == null) {
        // currentPassword is null so we are not forced to change password during login
        oldPasswordField.setValue("");
        oldPasswordField.setEnabled(true);

        oldPasswordField.focus();
    } else {
        oldPasswordField.setValue(currentPassword);
        oldPasswordField.setEnabled(false);

        newPasswordField1.focus();
    }

    newPasswordField1.setValue("");
    newPasswordField2.setValue("");
}

From source file:xyz.iipster.ui.DefaultIbmiLoginComponent.java

License:Apache License

@Override
public void attach() {
    super.attach();
    final FormLayout fl = new FormLayout();
    fl.setSizeUndefined();

    userNameTF.setCaption(i18N.get("iipster.login.username.label"));
    //        userNameTF.setRequired(true);
    userNameTF.addStyleName("upper-case");
    userNameTF.setMaxLength(10);//from   w  w w . j  av a  2s.c o  m
    passwordPF.setCaption(i18N.get("iipster.login.password.label"));
    //        passwordPF.setRequired(true);

    fl.addComponent(userNameTF);
    fl.addComponent(passwordPF);

    final VerticalLayout vl = new VerticalLayout();
    vl.setSizeUndefined();
    vl.addComponent(fl);
    vl.setExpandRatio(fl, 1F);
    vl.setComponentAlignment(fl, Alignment.MIDDLE_CENTER);

    final HorizontalLayout hl = new HorizontalLayout();
    hl.setSizeUndefined();

    loginButton.setCaption(i18N.get("iipster.login.loginButton.label"));
    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    loginButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    loginButton.addClickListener(event -> {
        if (userNameTF.isEmpty()) {
            Notification.show(i18N.get("iipster.login.username.missing"), Notification.Type.WARNING_MESSAGE);
            userNameTF.focus();
            return;
        }
        if (passwordPF.isEmpty()) {
            Notification.show(i18N.get("iipster.login.password.missing"), Notification.Type.WARNING_MESSAGE);
            passwordPF.focus();
            return;
        }

        try {
            Authentication auth = securityUtils.login(userNameTF.getValue(), passwordPF.getValue());
            eventBus.post(new LoginEvent(auth.getPrincipal().toString()));
        } catch (BadCredentialsException e) {
            Notification.show(i18N.get("iipster.login.bad.credential"), Notification.Type.WARNING_MESSAGE);
        } catch (DisabledException e) {
            Notification.show(i18N.get("iipster.login.disabled"), Notification.Type.WARNING_MESSAGE);
        } catch (CredentialsExpiredException e) {
            changePasswordComponent.setUserName(userNameTF.getValue());
            changePasswordComponent.setCurrentPassword(passwordPF.getValue());
            UI.getCurrent().addWindow(changePasswordComponent);
        } catch (Exception e) {
            Notification.show(i18N.get("iipster.login.error"), Notification.Type.WARNING_MESSAGE);
        }
    });
    hl.addComponent(loginButton);
    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);
    vl.setSizeUndefined();

    vl.setMargin(true);
    final Panel panel = new Panel(i18N.get("iipster.login.panel.title"), vl);
    panel.setSizeUndefined();

    rootLayout.addComponent(panel);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    setCompositionRoot(rootLayout);
    setSizeFull();
}