Example usage for com.vaadin.ui FormLayout FormLayout

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

Introduction

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

Prototype

public FormLayout() 

Source Link

Usage

From source file:de.kaiserpfalzEdv.vaadin.LoginScreen.java

License:Apache License

private Component buildLoginForm() {
    FormLayout loginForm = new FormLayout();

    loginForm.addStyleName("login-form");
    loginForm.setSizeUndefined();//from  www .  j  a v a2 s . c  om
    loginForm.setMargin(false);

    loginForm.addComponent(username = new TextField(translate("login.name.caption")));
    username.setDescription(translate("login.name.description"));
    username.setWidth(15, Unit.EM);
    loginForm.addComponent(password = new PasswordField(translate("login.password.caption")));
    password.setWidth(15, Unit.EM);
    password.setDescription(translate("login.password.description"));
    CssLayout buttons = new CssLayout();
    buttons.setStyleName("buttons");
    loginForm.addComponent(buttons);

    login = new Button(translate("login.login-button.caption"));
    buttons.addComponent(login);
    login.setDescription(translate("login.login-button.description"));
    login.setDisableOnClick(true);
    login.addClickListener(event -> {
        try {
            login();
        } finally {
            login.setEnabled(true);
        }
    });
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    Button forgotPassword;
    buttons.addComponent(forgotPassword = new Button(translate("login.password-forgotten.caption")));
    forgotPassword.setDescription(translate("login.password-forgotten.description"));
    forgotPassword.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            NotificationPayload notification = new NotificationPayload("login.password-forgotten.text");
            bus.post(new NotificationEvent(this, notification));
        }
    });
    forgotPassword.addStyleName(ValoTheme.BUTTON_LINK);
    return loginForm;
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultFormView.java

License:Apache License

private Layout layoutAsForm() {
    return new FormLayout();
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultRowEditingFormView.java

License:Apache License

private void buildViewComponents(boolean addSwitchModeButton) {
    fieldLayout = new FormLayout();
    addComponent(fieldLayout);/*from w ww  . java  2 s.  c om*/

    errorLabel = new Label();
    errorLabel.setStyleName("error");
    errorLabel.setVisible(false);
    addComponent(errorLabel);

    footerLayout = new CssLayout();
    footerLayout.setStyleName("actions");
    addComponent(footerLayout);

    if (addSwitchModeButton) {
        switchModeButton = new Button(getMessage("portlet.crud.button.editMode"));
        switchModeButton.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(ClickEvent event) {
                presenter.changeMode();
            }
        });
        footerLayout.addComponent(switchModeButton);
    }

    saveButton = new Button(getMessage("portlet.crud.button.save"));
    saveButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.save();
        }
    });

    resetButton = new Button(getMessage("portlet.crud.button.reset"));
    resetButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.resetFields();
        }
    });

    deleteButton = new Button(getMessage("portlet.crud.button.remove"));
    deleteButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.delete();
        }
    });

    previousRowButton = new Button(getMessage("portlet.crud.button.previousRow"));
    previousRowButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.previousRow();
        }
    });

    nextRowButton = new Button(getMessage("portlet.crud.button.nextRow"));
    nextRowButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.nextRow();
        }
    });

    Button cancelButton = new Button(getMessage("portlet.crud.button.cancel"));
    cancelButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.cancel();
        }
    });
    footerLayout.addComponents(saveButton, saveButton, deleteButton, previousRowButton, nextRowButton,
            cancelButton);
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ChangeExperimentMetadataComponent.java

License:Open Source License

private void buildFormLayout() {
    final FieldGroup fieldGroup = new FieldGroup();
    final FormLayout form2 = new FormLayout();

    Map<String, PropertyBean> controlledVocabularies = getControlledVocabularies();
    Map<String, PropertyBean> properties = getProperties();
    List<Property> xmlProps = getXMLProperties();

    for (Property f : xmlProps) {
        PropertyType type = f.getType();

        String label = f.getLabel();
        if (f.hasUnit())
            label += " in " + f.getUnit();
        TextField tf = new TextField(label);
        tf.setData(type);// save property type for later, when it is written back
        fieldGroup.bind(tf, label);/*  www .  j  a va 2  s  .  co  m*/
        tf.setCaption(label);
        tf.setDescription("Q_PROPERTIES");
        tf.setValue((String) f.getValue());
        form2.addComponent(tf);
    }

    for (String key : properties.keySet()) {
        if (controlledVocabularies.keySet().contains(key)) {
            ComboBox select = new ComboBox(controlledVocabularies.get(key).getLabel());
            fieldGroup.bind(select, key);

            // Add items with given item IDs
            select.addItems(controlledVocabularies.get(key).getVocabularyValues());

            select.setDescription(controlledVocabularies.get(key).getCode());
            select.setValue(properties.get(key).getValue());

            form2.addComponent(select);

        } else {
            TextField tf = new TextField(key);
            fieldGroup.bind(tf, key);
            tf.setCaption(properties.get(key).getLabel());
            tf.setDescription(properties.get(key).getCode());
            tf.setValue((String) properties.get(key).getValue());
            form2.addComponent(tf);
        }
    }
    this.fieldGroup = fieldGroup;
    this.form = form2;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ChangeMetadataComponent.java

License:Open Source License

private void buildFormLayout(SampleBean sample) {
    final FieldGroup fieldGroup = new FieldGroup();
    final FormLayout form2 = new FormLayout();

    Map<String, PropertyBean> controlledVocabularies = getControlledVocabularies(sample);
    Map<String, PropertyBean> properties = getProperties(sample);

    for (String key : properties.keySet()) {
        if (controlledVocabularies.keySet().contains(key)) {
            ComboBox select = new ComboBox(controlledVocabularies.get(key).getLabel());
            fieldGroup.bind(select, key);

            // Add items with given item IDs
            select.addItems(controlledVocabularies.get(key).getVocabularyValues());

            /*/*from ww  w.  j  ava  2  s  .co m*/
             * for(Object itemID: select.getItemIds()) { System.out.println(itemID); }
             */
            select.setDescription(controlledVocabularies.get(key).getCode());
            select.setValue(properties.get(key).getValue());

            form2.addComponent(select);

        } else {
            TextField tf = new TextField(key);
            fieldGroup.bind(tf, key);
            tf.setCaption(properties.get(key).getLabel());
            tf.setDescription(properties.get(key).getCode());
            tf.setValue((String) properties.get(key).getValue());
            form2.addComponent(tf);
        }
    }
    this.fieldGroup = fieldGroup;
    this.form = form2;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ChangeProjectMetadataComponent.java

License:Open Source License

private void buildFormLayout() {
    final FieldGroup fieldGroup = new FieldGroup();
    final FormLayout form2 = new FormLayout();

    TextArea tf = new TextArea("Description");
    tf.setWidth("50%");
    tf.setHeight("50%");
    fieldGroup.bind(tf, "Description");
    tf.setCaption("Description");
    tf.setDescription("Description of this project.");
    tf.setValue(currentDescription);//from   ww  w . j a  v a 2  s . c  om
    form2.addComponent(tf);

    this.fieldGroup = fieldGroup;
    this.form = form2;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ChangeSampleMetadataComponent.java

License:Open Source License

private void buildFormLayout() {
    final FieldGroup fieldGroup = new FieldGroup();
    final FormLayout form2 = new FormLayout();
    this.fieldGroup = new FieldGroup();
    this.form = new FormLayout();

    Map<String, PropertyBean> controlledVocabularies = getControlledVocabularies();
    Map<String, PropertyBean> properties = getProperties();
    List<Property> xmlProps = getXMLProperties();

    for (Property f : xmlProps) {
        properties.PropertyType type = f.getType();

        String label = f.getLabel();
        if (f.hasUnit())
            label += " in " + f.getUnit();
        TextField tf = new TextField(label);
        tf.setData(type);// save property type for later, when it is written back
        fieldGroup.bind(tf, label);/*from w w  w.  j  av  a2  s . c  o  m*/
        tf.setCaption(label);
        tf.setDescription("Q_PROPERTIES");
        tf.setValue((String) f.getValue());
        form2.addComponent(tf);
    }

    for (String key : properties.keySet()) {
        if (controlledVocabularies.keySet().contains(key)) {
            ComboBox select = new ComboBox(controlledVocabularies.get(key).getLabel());
            fieldGroup.bind(select, key);

            // Add items with given item IDs
            select.addItems(controlledVocabularies.get(key).getVocabularyValues());

            select.setDescription(controlledVocabularies.get(key).getCode());
            select.setValue(properties.get(key).getValue());

            form2.addComponent(select);

        } else {
            TextField tf = new TextField(key);
            fieldGroup.bind(tf, key);
            tf.setCaption(properties.get(key).getLabel());
            tf.setDescription(properties.get(key).getCode());
            tf.setValue((String) properties.get(key).getValue());
            form2.addComponent(tf);
        }
    }
    this.fieldGroup = fieldGroup;
    this.form = form2;
}

From source file:dhbw.clippinggorilla.userinterface.windows.ActivateWindow.java

public static Window get() {
    Window window = new Window();
    window.setModal(true);//from  w w w  .  jav a2  s  .c om
    window.setResizable(false);
    window.setDraggable(false);
    window.setCaption(Language.get(Word.ACTIVATION_CODE));
    window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null);

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setMargin(false);
    windowLayout.setSizeUndefined();

    FormLayout forms = new FormLayout();
    forms.setMargin(true);
    forms.setSizeUndefined();

    Button save = new Button(Language.get(Word.ACTIVATE));

    TextField activationCode = new TextField(Language.get(Word.ACTIVATION_CODE));
    activationCode.setMaxLength(6);
    activationCode.focus();
    activationCode.addValueChangeListener(e -> {
        if (activationCode.getValue().length() > 5) {
            save.setEnabled(true);
            activationCode.setComponentError(null);
        } else {
            save.setEnabled(false);
            activationCode.setComponentError(new UserError(Language.get(Word.ACTIVATION_CODE_SIX_CHARS),
                    AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_CODE_SIX_CHARS));
        }
    });
    forms.addComponent(activationCode);

    Button resendMail = new Button(Language.get(Word.RESEND_ACTIVATION_CODE));
    resendMail.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    resendMail.addClickListener(ce -> {
        try {
            UserUtils.resendActivationMail(UserUtils.getCurrent());
            VaadinUtils.infoNotification(Language.get(Word.RESEND_ACTIVATION_CODE_SUCCESSFUL));
        } catch (EmailException ex) {
            VaadinUtils.errorNotification(Language.get(Word.RESEND_ACTIVATION_CODE_FAILED));
        }
    });
    forms.addComponent(resendMail);

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Sizeable.Unit.PERCENTAGE);

    Label placeholder = new Label();

    Button cancel = new Button(Language.get(Word.CANCEL));
    cancel.setIcon(VaadinIcons.CLOSE);
    cancel.addClickListener(ce -> {
        window.close();
    });
    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);

    save.setEnabled(false);
    save.setIcon(VaadinIcons.CHECK);
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);
    save.addClickListener(ce -> {
        try {
            String code = activationCode.getValue();
            User user = UserUtils.getCurrent();
            if (UserUtils.activateUser(user, code)) {
                VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_SUCCESSFUL));
                window.close();
            } else {
                activationCode.setValue("");
                VaadinUtils.errorNotification(Language.get(Word.ACTIVATION_FAILED));
            }
        } catch (NumberFormatException e) {
        }
    });
    save.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    footer.setSizeUndefined();
    footer.setWidth("100%");
    footer.addComponents(placeholder, cancel, save);
    footer.setColumnExpandRatio(0, 1);//ExpandRatio(placeholder, 1);
    footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(save, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(forms);
    windowLayout.addComponent(footer);

    window.setContent(windowLayout);
    return window;
}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

public Component getFirstStage() {
    Label header = new Label(Language.get(Word.RSS));
    header.addStyleName(ValoTheme.LABEL_H1);

    FormLayout forms = new FormLayout();
    forms.setSizeFull();/*from   w  w  w  .j ava 2  s  .  c o  m*/

    TextField rssField = new TextField(Language.get(Word.RSS));
    rssField.setWidth("750px");
    forms.addComponents(rssField);

    Runnable cancel = () -> close();
    Runnable next = () -> validateFirstStage(rssField.getValue());

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.addComponents(header, forms, getFooter(cancel, next));
    windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
    return windowLayout;
}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

/**
 * If no value present, choose a empty string
 *
 * @param title/* w  w w .j  av  a 2s . com*/
 * @param link
 * @param description
 * @param language
 * @param imageUrl
 * @return
 */
private Component getSecondStage(Source s) {
    Label header = new Label(Language.get(Word.SOURCE));
    header.addStyleName(ValoTheme.LABEL_H1);

    FormLayout forms = new FormLayout();
    forms.setSizeFull();

    TextField textFieldId = new TextField(Language.get(Word.ID));
    textFieldId.setEnabled(false);
    textFieldId.setValue(s.getId());
    textFieldId.setWidth("750px");

    TextField textFieldName = new TextField(Language.get(Word.NAME));
    textFieldName.setValue(s.getName());
    textFieldName.setWidth("750px");

    TextField textFieldDescription = new TextField(Language.get(Word.DESCRIPTION));
    textFieldDescription.setValue(s.getDescription());
    textFieldDescription.setWidth("750px");

    TextField textFieldURL = new TextField(Language.get(Word.URL));
    if (s.getUrl() != null) {
        textFieldURL.setValue(s.getUrl().toExternalForm());
    }
    textFieldURL.setWidth("750px");

    ComboBox<Category> comboBoxCategories = new ComboBox<>(Language.get(Word.CATEGORY),
            EnumSet.allOf(Category.class));
    comboBoxCategories.setItemCaptionGenerator(c -> c.getName());
    comboBoxCategories.setItemIconGenerator(c -> c.getIcon());
    comboBoxCategories.setEmptySelectionAllowed(false);
    comboBoxCategories.setTextInputAllowed(false);
    comboBoxCategories.setWidth("375px");
    if (s.getCategory() != null) {
        comboBoxCategories.setSelectedItem(s.getCategory());
    }

    ComboBox<Locale> comboBoxLanguage = new ComboBox<>(Language.get(Word.LANGUAGE), getLanguages());
    comboBoxLanguage.setItemCaptionGenerator(l -> l.getDisplayLanguage(VaadinSession.getCurrent().getLocale()));
    comboBoxLanguage.setEmptySelectionAllowed(false);
    comboBoxLanguage.setWidth("375px");
    if (!s.getLanguage().isEmpty()) {
        Locale selected = new Locale(s.getLanguage());
        comboBoxLanguage.setSelectedItem(selected);
    }

    Locale loc = VaadinSession.getCurrent().getLocale();

    Map<String, Locale> countries = getCountries();
    List<Locale> locales = countries.values().parallelStream()
            .sorted((l1, l2) -> l1.getDisplayCountry(loc).compareTo(l2.getDisplayCountry(loc)))
            .collect(Collectors.toList());
    ComboBox<Locale> comboBoxCountry = new ComboBox<>(Language.get(Word.COUNTRY), locales);
    comboBoxCountry.setItemCaptionGenerator(l -> l.getDisplayCountry(VaadinSession.getCurrent().getLocale()));
    comboBoxCountry.setItemIconGenerator(l -> FamFamFlags.fromLocale(l));
    comboBoxCountry.setEmptySelectionAllowed(false);
    comboBoxCountry.setWidth("375px");
    if (!s.getCountry().isEmpty()) {
        comboBoxCountry.setSelectedItem(countries.getOrDefault(s.getCountry(), Locale.ROOT));
    }

    Image imageLogo = new Image(Language.get(Word.LOGO));

    TextField textFieldLogo = new TextField(Language.get(Word.LOGO_URL));
    if (s.getLogo() != null) {
        textFieldLogo.setValue(s.getLogo().toExternalForm());
        imageLogo.setSource(new ExternalResource(s.getLogo()));
    }
    textFieldLogo.addValueChangeListener(ce -> imageLogo.setSource(new ExternalResource(ce.getValue())));
    textFieldLogo.setWidth("750px");

    if (imageLogo.getHeight() > 125) {
        imageLogo.setHeight("125px");
    }

    forms.addComponents(textFieldId, textFieldName, textFieldDescription, textFieldURL, comboBoxCategories,
            comboBoxLanguage, comboBoxCountry, textFieldLogo, imageLogo);

    Runnable cancel = () -> close();
    Runnable next = () -> validateSecondStage(s, textFieldId.getValue(), textFieldName.getValue(),
            textFieldURL.getValue(), textFieldDescription.getValue(),
            comboBoxCategories.getSelectedItem().orElse(null),
            comboBoxLanguage.getSelectedItem().orElse(Locale.ROOT),
            comboBoxCountry.getSelectedItem().orElse(Locale.ROOT), textFieldLogo.getValue());

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.addComponents(header, forms, getFooter(cancel, next));
    windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
    return windowLayout;
}