Example usage for com.vaadin.ui CssLayout addComponent

List of usage examples for com.vaadin.ui CssLayout addComponent

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:org.eclipse.skalli.view.component.RadioSelect.java

License:Open Source License

private void renderEntries() {
    int row = 0;//from   w  w  w  . j a  va 2  s .c o m
    radios = new ArrayList<Button>(entries.size());
    for (Entry entry : entries) {
        Button b = new Button();
        b.setIcon(row == selected ? SELECTED : UNSELECTED);
        b.setStyleName(Button.STYLE_LINK);
        b.addListener((Button.ClickListener) this);
        entriesGrid.addComponent(b, 0, row);
        radios.add(b);

        StringBuilder sb = new StringBuilder();
        sb.append("<span style=\"font-weight:bold\">"); //$NON-NLS-1$
        sb.append(StringEscapeUtils.escapeHtml(entry.getCaption()));
        sb.append("</span><br>"); //$NON-NLS-1$
        sb.append("<span style=\"white-space:normal\">"); //$NON-NLS-1$
        sb.append(HtmlUtils.clean(entry.getDescription()));
        sb.append("</span>"); //$NON-NLS-1$

        CssLayout css = new CssLayout() {

            private static final long serialVersionUID = 7370808823922141846L;

            @Override
            protected String getCss(Component c) {
                return "margin-bottom:10px;margin-left:3px"; //$NON-NLS-1$
            }
        };
        css.setSizeFull();
        Label comment = new Label(sb.toString(), Label.CONTENT_XHTML);
        css.addComponent(comment);

        entriesGrid.addComponent(css, 1, row);
        entriesGrid.setColumnExpandRatio(1, 1.0f);
        ++row;
    }
}

From source file:org.eclipse.skalli.view.component.Tray.java

License:Open Source License

private ComponentContainer createContent(String caption, String description, ThemeResource icon,
        boolean isRequired) {
    CssLayout layout = new CssLayout();
    layout.setStyleName(STYLE_TRAY);/*  ww w  . j  a v a2 s.co m*/
    layout.setMargin(true);

    HorizontalLayout header = new HorizontalLayout();
    header.setSpacing(true);
    header.setStyleName(STYLE_TRAY_HEADER);
    header.setWidth("100%");

    this.icon = icon;
    trayIcon = new Embedded(null, icon);
    trayIcon.setStyleName(STYLE_TRAY_HEADER_ICON);
    header.addComponent(trayIcon);
    header.setComponentAlignment(trayIcon, Alignment.MIDDLE_LEFT);
    header.setExpandRatio(trayIcon, 0);

    Label captionLabel = new Label(StringEscapeUtils.escapeHtml(caption), Label.CONTENT_XHTML);
    captionLabel.setStyleName(STYLE_TRAY_HEADER_LABEL);
    header.addComponent(captionLabel);
    header.setExpandRatio(captionLabel, 1);
    header.setComponentAlignment(captionLabel, Alignment.MIDDLE_LEFT);

    this.isRequired = isRequired;
    if (!isRequired) {
        activator = new NativeButton("", new ToggleEnabledListener());
        header.addComponent(activator);
        header.setExpandRatio(activator, 0);
        header.setComponentAlignment(activator, Alignment.MIDDLE_RIGHT);
    }

    opener = new NativeButton("", new ToggleVisibleListener());
    header.addComponent(opener);
    header.setExpandRatio(opener, 0);
    header.setComponentAlignment(opener, Alignment.MIDDLE_RIGHT);

    layout.addComponent(header);

    CssLayout content = new CssLayout();
    Label descriptionLabel = new Label(HtmlUtils.clean(description), Label.CONTENT_XHTML);
    descriptionLabel.setStyleName(STYLE_TRAY_DESCRIPTION);
    content.addComponent(descriptionLabel);

    layout.addComponent(content);
    setCompositionRoot(layout);
    return content;
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.ProjectAboutBox.java

License:Open Source License

@Override
public Component getContent(Project project, ExtensionUtil util) {
    CssLayout layout = new CssLayout();
    layout.addStyleName(STYLE_ABOUT_INFOBOX);
    layout.setSizeFull();//from w w w. j  a  v  a 2s .co  m

    String description = "No description available";
    if (StringUtils.isNotBlank(project.getDescription())) {
        description = HtmlUtils.clean(StringUtils.replace(project.getDescription(), "\n", "<br />")); //$NON-NLS-1$ //$NON-NLS-2$
        createLabel(layout, description, STYLE_ABOUT);
    }

    InfoExtension ext = project.getExtension(InfoExtension.class);
    if (ext != null && StringUtils.isNotBlank(ext.getPageUrl())) {
        createLink(layout, "Project Homepage", ext.getPageUrl(), DEFAULT_TARGET, STYLE_HOMEPAGE);
    }

    TaggingService taggingService = Services.getService(TaggingService.class);
    if (taggingService != null) {
        TagComponent tagComponent = new TagComponent(project, taggingService, util);
        layout.addComponent(tagComponent);
    }

    if (!util.getProjectTemplate().isHidden(Project.class.getName(), Project.PROPERTY_PHASE,
            util.isUserProjectAdmin(project))) {
        createLabel(layout, MessageFormat.format("This project is in the <b>{0}</b> phase.",
                StringEscapeUtils.escapeHtml(project.getPhase())), STYLE_PHASE);
    }

    // for ui testing
    // TODO need to understand why vaadin does not accept the layout to have the id
    // (it then cannot render a second project, throws ISE)
    layout.addComponent(new Label("<div id=" + DEBUG_ID + "></div>", Label.CONTENT_XHTML)); //$NON-NLS-1$ //$NON-NLS-2$

    addLastModifiedInfo(layout, project);

    return layout;
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.ProjectReviewBox.java

License:Open Source License

@Override
public Component getContent(Project project, ExtensionUtil util) {
    CssLayout layout = new CssLayout() {
        @Override/*from w  w w.java  2  s.co  m*/
        protected String getCss(Component c) {
            return "padding-left: 3px;";
        }
    };
    layout.setMargin(false);
    layout.setSizeFull();

    ReviewProjectExt ext = project.getExtension(ReviewProjectExt.class);
    if (ext != null) {
        ReviewComponent reviewComponent = new ReviewComponent(project, DEFAULT_PAGE_LENGH, MAX_PAGE_LENGH,
                util);
        layout.addComponent(reviewComponent);
    }
    return layout;
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.ReviewComponent.java

License:Open Source License

private void paintReviewGrid() {
    if (reviewGrid == null) {
        reviewGrid = new GridLayout(2, currentPageLength);
        reviewGrid.setSizeFull();/*from  w  w w . j av a 2  s .com*/
        reviewGrid.setSpacing(true);
        layout.addComponent(reviewGrid);
    } else {
        reviewGrid.removeAllComponents();
    }
    int rows = reviewGrid.getRows();
    if (rows != currentPageLength) {
        reviewGrid.setRows(Math.min(size, currentPageLength));
    }

    int row = 0;
    List<ReviewEntry> latestReviews = getLatestReviews(currentPage, currentPageLength);
    for (ReviewEntry review : latestReviews) {
        ProjectRating rating = review.getRating();
        Embedded e = new Embedded(null, getIcon(rating));
        e.setDescription(getDescription(rating));
        e.setWidth("22px"); //$NON-NLS-1$
        e.setHeight("22px"); //$NON-NLS-1$
        reviewGrid.addComponent(e, 0, row);

        StringBuilder sb = new StringBuilder();
        sb.append("<span style=\"white-space:normal\">"); //$NON-NLS-1$
        sb.append(HtmlUtils.clean(review.getComment()));
        sb.append("<br>"); //$NON-NLS-1$
        sb.append("<span style=\"font-size:x-small\">").append(" posted by "); //$NON-NLS-1$
        sb.append(StringEscapeUtils.escapeHtml(review.getVoter()));
        sb.append(" "); //$NON-NLS-1$

        long deltaMillis = System.currentTimeMillis() - review.getTimestamp();
        long deltaDays = deltaMillis / MILLIS_PER_DAY;
        if (deltaDays > 0) {
            sb.append(deltaDays);
            sb.append(" days ago");
        } else {
            long deltaHours = deltaMillis / MILLIS_PER_HOUR;
            if (deltaHours > 0) {
                sb.append(deltaHours).append(" hours ago");
            } else {
                long deltaMinutes = deltaMillis / MILLIS_PER_MINUTE;
                if (deltaMinutes > 0) {
                    sb.append(deltaMinutes).append(" minutes ago");
                } else {
                    sb.append(" just now");
                }
            }
            sb.append("</span></span>"); //$NON-NLS-1$
        }
        CssLayout css = new CssLayout();
        css.setSizeFull();
        Label comment = new Label(sb.toString(), Label.CONTENT_XHTML);
        comment.setSizeUndefined();
        css.addComponent(comment);
        reviewGrid.addComponent(css, 1, row);
        reviewGrid.setColumnExpandRatio(1, 1.0f);
        ++row;
    }
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.ReviewComponent.java

License:Open Source License

@SuppressWarnings("serial")
private Window createReviewWindow(final ProjectRating rating) {
    final Window subwindow = new Window("Rate and Review");
    subwindow.setModal(true);/*  ww  w  . j av a2  s. com*/
    subwindow.setWidth("420px"); //$NON-NLS-1$
    subwindow.setHeight("320px"); //$NON-NLS-1$

    VerticalLayout vl = (VerticalLayout) subwindow.getContent();
    vl.setSpacing(true);
    vl.setSizeFull();

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

    Embedded icon = new Embedded(null, getIcon(rating));
    Label iconLabel = new Label("<b>" + HSPACE + getReviewComment(rating) + "</b>", Label.CONTENT_XHTML); //$NON-NLS-1$ //$NON-NLS-2$
    String captionTextField = getReviewCommentQuestion(rating);
    hl.addComponent(icon);
    hl.addComponent(iconLabel);
    hl.setComponentAlignment(iconLabel, Alignment.MIDDLE_LEFT);
    vl.addComponent(hl);

    final TextField editor = new TextField(captionTextField);
    editor.setRows(3);
    editor.setColumns(30);
    editor.setImmediate(true);
    vl.addComponent(editor);

    final User user = util.getLoggedInUser();
    final ArrayList<String> userSelects = new ArrayList<String>(2);
    userSelects.add("I want to vote as " + user.getDisplayName());
    if (extension.getAllowAnonymous()) {
        userSelects.add("I want to vote as Anonymous!");
    }
    final OptionGroup userSelect = new OptionGroup(null, userSelects);
    userSelect.setNullSelectionAllowed(false);
    userSelect.select(userSelects.get(0));
    vl.addComponent(userSelect);

    CssLayout css = new CssLayout() {
        @Override
        protected String getCss(Component c) {
            return "margin-left:5px;margin-right:5px;margin-top:10px"; //$NON-NLS-1$
        }
    };

    Button okButton = new Button("OK");
    okButton.setIcon(ICON_BUTTON_OK);
    okButton.setDescription("Commit changes");
    okButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            String comment = (String) editor.getValue();
            if (StringUtils.isBlank(comment)) {
                comment = "No Comment";
            }
            ((Window) subwindow.getParent()).removeWindow(subwindow);
            String userName = "Anonymous";
            if (userSelects.get(0).equals(userSelect.getValue())) {
                userName = user.getDisplayName();
            }
            ReviewEntry review = new ReviewEntry(rating, comment, userName, System.currentTimeMillis());
            extension.addReview(review);
            util.persist(project);
            reviews = extension.getReviews();
            size = reviews.size();
            currentPage = 0;
            lastPage = size / currentPageLength;
            paintReviewList();
        }
    });
    css.addComponent(okButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.setIcon(ICON_BUTTON_CANCEL);
    cancelButton.setDescription("Discard changes");
    cancelButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            ((Window) subwindow.getParent()).removeWindow(subwindow);
        }
    });
    css.addComponent(cancelButton);

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

    return subwindow;
}

From source file:org.eclipse.skalli.view.internal.window.NewProjectPanel.java

License:Open Source License

/**
 * Renders the content of the panel.//from ww  w .j  a v  a  2 s  . c  o  m
 */
private void renderContent(VerticalLayout content) {

    CssLayout layout = new CssLayout();
    layout.setWidth("600px"); //$NON-NLS-1$
    content.addComponent(layout);
    content.setComponentAlignment(layout, Alignment.MIDDLE_CENTER);

    Label title = new Label("<h2>" + "Available Project Templates" + "</h2>", Label.CONTENT_XHTML); //$NON-NLS-1$//$NON-NLS-3$
    layout.addComponent(title);

    TreeSet<RadioSelect.Entry> entries = new TreeSet<RadioSelect.Entry>();
    for (ProjectTemplate projectTemplate : projectTemplates) {
        entries.add(new RadioSelect.Entry(projectTemplate.getId(), projectTemplate.getDisplayName(),
                projectTemplate.getDescription(), projectTemplate.getRank()));
    }
    select = new RadioSelect("", entries); //$NON-NLS-1$
    layout.addComponent(select);

    renderButtons(content);

    // for ui debugging
    content.setDebugId(DEBUG_ID_CONTENT);
}

From source file:org.eclipse.skalli.view.internal.window.NewProjectPanel.java

License:Open Source License

/**
 * Renders the OK/Cancel button bar./*from  w w  w .ja v a2s .c o  m*/
 */
private void renderButtons(VerticalLayout content) {
    CssLayout buttons = new CssLayout();
    buttons.addStyleName(STYLE_TEMPLATE_SELECT_BUTTONS);

    Button okButton = new Button("Create Project");
    okButton.setIcon(ICON_BUTTON_OK);
    okButton.addListener(new OKButtonListener());
    buttons.addComponent(okButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.setIcon(ICON_BUTTON_CANCEL);
    cancelButton.addListener(new CancelButtonListener());
    buttons.addComponent(cancelButton);

    content.addComponent(buttons);
    content.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
}

From source file:org.eclipse.skalli.view.internal.window.ProjectEditPanel.java

License:Open Source License

private Label renderMessageArea(VerticalLayout layout) {
    CssLayout messageArea = new CssLayout();
    messageArea.setMargin(true);/*from   w w  w  . j  a v  a2s.com*/
    messageArea.setWidth(PANEL_WIDTH);
    Label label = new Label("", Label.CONTENT_XHTML); //$NON-NLS-1$
    label.addStyleName(STYLE_ISSUES);
    label.setVisible(false);
    messageArea.addComponent(label);
    layout.addComponent(messageArea);
    layout.setComponentAlignment(messageArea, Alignment.MIDDLE_CENTER);
    return label;
}

From source file:org.eclipse.skalli.view.internal.window.ProjectEditPanel.java

License:Open Source License

/**
 * Renders a OK/Cancel/Validate/Expand All/Collapse All button bar.
 *///from ww  w. jav a 2  s.c  om
@SuppressWarnings("serial")
private Button renderButtons(VerticalLayout layout, boolean header) {
    CssLayout buttons = new CssLayout();
    buttons.addStyleName(STYLE_EDIT_PROJECT_BUTTONS);
    String prefix = header ? HEADER : FOOTER;

    Button okButton = new Button("OK");
    okButton.setIcon(ICON_BUTTON_OK);
    okButton.setDescription("Save the modified project");
    okButton.addStyleName(prefix + BUTTON_OK);
    okButton.addListener(new OKButtonListener());
    buttons.addComponent(okButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.setIcon(ICON_BUTTON_CANCEL);
    cancelButton.setDescription("Discard all changes to the project");
    cancelButton.addStyleName(prefix + BUTTON_CANCEL);
    cancelButton.addListener(new CancelButtonListener());
    buttons.addComponent(cancelButton);

    Button checkButton = new Button("Check");
    checkButton.setIcon(ICON_BUTTON_VALIDATE);
    checkButton.setDescription("Checks the modified project for issues without saving it");
    checkButton.addStyleName(prefix + BUTTON_VALIDATE);
    checkButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            validateModifiedProject();
        }
    });
    buttons.addComponent(checkButton);

    Button expandAllButton = new Button("Expand All");
    expandAllButton.setIcon(ICON_BUTTON_EXPAND_ALL);
    expandAllButton.setDescription("Expand all panels");
    expandAllButton.addStyleName(prefix + BUTTON_EXPAND_ALL);
    expandAllButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            expandAllPanels();
        }
    });
    buttons.addComponent(expandAllButton);

    Button collapseAllButton = new Button("Collapse All");
    collapseAllButton.setIcon(ICON_BUTTON_COLLAPSE_ALL);
    collapseAllButton.setDescription("Collapse all panels");
    collapseAllButton.addStyleName(prefix + BUTTON_COLLAPSE_ALL);
    collapseAllButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            collapseAllPanels();
        }
    });
    buttons.addComponent(collapseAllButton);

    layout.addComponent(buttons);
    layout.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    return checkButton;
}