Example usage for com.vaadin.ui CustomComponent CustomComponent

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

Introduction

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

Prototype

public CustomComponent() 

Source Link

Document

Constructs a new custom component.

Usage

From source file:org.vaadin.tori.component.DebugControlPanel.java

License:Apache License

private Component createPostControl(final Method setter, final List<Post> posts) throws Exception {
    if (posts == null || posts.isEmpty()) {
        final Label label = new Label(getNameForCheckBox(setter));
        label.setEnabled(false);/*from ww  w.j a  va  2s  .c  om*/
        return label;
    }

    Component content = new CustomComponent() {
        {
            final CssLayout root = new CssLayout();
            root.addStyleName("postselect-content");
            root.addStyleName(setter.getName());
            setCompositionRoot(root);
            root.setWidth("100%");
            setWidth("400px");

            root.addComponent(new Label(setter.getName()));

            for (final Post post : posts) {
                final Method getter = getGetterFrom(setter);
                final boolean getterValue = (Boolean) getter.invoke(authorizationService, post.getId());

                final String authorName = post.getAuthor().getDisplayedName();

                String postBody = post.getBodyRaw();
                if (postBody.length() > 20) {
                    postBody = postBody.substring(0, 20);
                }

                final CheckBox checkbox = new CheckBox(authorName + " :: " + postBody);
                checkbox.setValue(getterValue);
                checkbox.addValueChangeListener(new PostCheckboxListener(post, setter));
                checkbox.setImmediate(true);
                checkbox.setWidth("100%");
                root.addComponent(checkbox);
            }
        }
    };
    final PopupView popup = new PopupView(getNameForCheckBox(setter), content);
    popup.setHideOnMouseOut(false);
    popup.setHeight(30.0f, Unit.PIXELS);
    return popup;
}