All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.mateu.mdd.vaadin.components.views.PrintPOJOComponent Maven / Gradle / Ivy

There is a newer version: 1.1.60
Show newest version
package io.mateu.mdd.vaadin.components.views;

import com.vaadin.ui.FormLayout;
import com.vaadin.ui.Label;
import io.mateu.mdd.shared.annotations.Ignored;
import io.mateu.mdd.shared.reflection.FieldInterfaced;
import io.mateu.reflection.ReflectionHelper;
import io.mateu.util.notification.Notifier;

import javax.persistence.Version;
import java.util.List;
import java.util.stream.Collectors;

public class PrintPOJOComponent extends FormLayout {
    public PrintPOJOComponent(Object bean) {




        getAllFields(bean.getClass()).forEach(f -> {

            Object v = null;
            try {
                v = ReflectionHelper.getValue(f, bean);
            } catch (Exception e) {
                Notifier.alert(e);
            }

            Label l;
            addComponent(l = new Label((v != null)?v.toString():""));
            l.setCaption(ReflectionHelper.getCaption(f));

        });


    }


    private List getAllFields(Class beanType) {
        List allFields = ReflectionHelper.getAllFields(beanType);

        allFields = allFields.stream().filter((f) ->
                !(f.isAnnotationPresent(Version.class) || f.isAnnotationPresent(Ignored.class))
        ).collect(Collectors.toList());

        return allFields;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy