Search in sources :

Example 1 with CommitFormWrapperClickListener

use of com.hack23.cia.web.impl.ui.application.views.pageclicklistener.CommitFormWrapperClickListener in project cia by Hack23.

the class FormFactoryImpl method addRequestInputFormFields.

@Override
public <T extends Serializable> void addRequestInputFormFields(final FormLayout panelContent, final T item, final Class<T> beanType, final List<String> displayProperties, final String buttonLabel, final ClickListener buttonListener) {
    final BeanValidationBinder<T> binder = new BeanValidationBinder<>(beanType);
    binder.setBean(item);
    binder.setReadOnly(true);
    for (final String property : displayProperties) {
        final AbstractField buildAndBind;
        if (property.contains(HIDDEN_FIELD_NAME)) {
            buildAndBind = new PasswordField();
            binder.bind(buildAndBind, property);
        } else {
            buildAndBind = new TextField();
            binder.bind(buildAndBind, property);
        }
        buildAndBind.setCaption(property);
        buildAndBind.setId(MessageFormat.format("{0}.{1}", buttonLabel, property));
        buildAndBind.setReadOnly(false);
        buildAndBind.setWidth(ContentSize.HALF_SIZE);
        panelContent.addComponent(buildAndBind);
    }
    final VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setWidth("50%");
    final Button button = new Button(buttonLabel, new CommitFormWrapperClickListener(binder, buttonListener));
    button.setId(buttonLabel);
    button.setWidth("25%");
    button.setIcon(VaadinIcons.BULLSEYE);
    button.setEnabled(false);
    binder.addStatusChangeListener(event -> {
        button.setEnabled(event.getBinder().isValid());
    });
    verticalLayout.addComponent(button);
    verticalLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);
    panelContent.addComponent(verticalLayout);
}
Also used : AbstractField(com.vaadin.ui.AbstractField) Button(com.vaadin.ui.Button) TextField(com.vaadin.ui.TextField) VerticalLayout(com.vaadin.ui.VerticalLayout) BeanValidationBinder(com.vaadin.data.BeanValidationBinder) PasswordField(com.vaadin.ui.PasswordField) CommitFormWrapperClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.CommitFormWrapperClickListener)

Aggregations

CommitFormWrapperClickListener (com.hack23.cia.web.impl.ui.application.views.pageclicklistener.CommitFormWrapperClickListener)1 BeanValidationBinder (com.vaadin.data.BeanValidationBinder)1 AbstractField (com.vaadin.ui.AbstractField)1 Button (com.vaadin.ui.Button)1 PasswordField (com.vaadin.ui.PasswordField)1 TextField (com.vaadin.ui.TextField)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1