Example usage for com.vaadin.ui Button addListener

List of usage examples for com.vaadin.ui Button addListener

Introduction

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

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

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

License:Open Source License

private void renderEntries() {
    int row = 0;/*  w  ww .ja va2  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.UsersPicker.java

License:Open Source License

@SuppressWarnings({ "serial", "deprecation" })
private void renderTable() {
    table = new Table();
    table.addStyleName(STYLE_TABLE);/*from w  w w.  ja v  a2  s.c  o  m*/
    table.setSelectable(true);
    table.setContainerDataSource(tableDateSource);

    table.addGeneratedColumn(COLUMN_USER, new Table.ColumnGenerator() {
        @Override
        public Component generateCell(Table source, Object itemId, Object columnId) {
            String userId = itemId.toString();
            User user = UserServices.getUser(userId);
            PeopleComponent peopleComponent = new PeopleComponent(user);
            return peopleComponent;
        }
    });

    if (!readOnly) {
        table.addGeneratedColumn(COLUMN_REMOVE, new Table.ColumnGenerator() {
            @Override
            public Component generateCell(Table source, final Object itemId, Object columnId) {
                Button b = new Button("remove");
                b.setStyleName(Button.STYLE_LINK);
                b.addStyleName(STYLE_BUTTON);
                b.setDescription("Remove this member");
                b.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        removeItem(itemId);
                        adjustPageLength(table);
                    }
                });
                return b;
            }
        });
    }

    table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
    if (!readOnly) {
        table.setVisibleColumns(new String[] { COLUMN_USER, COLUMN_REMOVE });
        table.setColumnExpandRatio(COLUMN_USER, 0.5f);
        table.setColumnWidth(COLUMN_REMOVE, 50);
        table.setColumnHeaders(new String[] { "User", "Remove" });
    } else {
        table.setVisibleColumns(new String[] { COLUMN_USER });
        table.setColumnHeaders(new String[] { "User", });
    }

    table.setSelectable(false);
    table.setWidth("100%"); // do not change that! otherwise right border of table is hidden in IE!
    table.setReadOnly(readOnly);
    adjustPageLength(table);

    layout.addComponent(table);
    layout.setExpandRatio(table, 1.0f);

    if (!readOnly) {
        Button searchButton = new Button("Add user", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                PeopleSearchWindow search = new PeopleSearchWindow(UsersPicker.this, UsersPicker.this);
                search.show();
                adjustPageLength(table);
            }
        });
        searchButton.setStyle(Button.STYLE_LINK);
        searchButton.setDescription("Add user");
        searchButton.setWidth("80px");
        layout.addComponent(searchButton);
    }
}

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

License:Open Source License

@SuppressWarnings({ "deprecation", "serial" })
private void addMoreButton(final Layout layout, final Project project, final String userId,
        final HashMap<String, SourceDetails> sourceFilter) {
    final Button moreButton = new Button("more ...");
    moreButton.setStyle(Button.STYLE_LINK);
    moreButton.addListener(new Button.ClickListener() {
        @Override/*  www .  j  a v a2  s .co m*/
        public void buttonClick(ClickEvent event) {
            maxFeedEntries = maxFeedEntries + 30;
            renderContentPanel(layout, project, userId, sourceFilter);
        }
    });
    layout.addComponent(moreButton);
}

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

License:Open Source License

@SuppressWarnings({ "serial", "deprecation" })
private void paintReviewButton(HorizontalLayout hl, final ProjectRating rating) {
    Button btn = new Button();
    if (util.getLoggedInUser() != null) {
        btn.addListener(new Button.ClickListener() {
            @Override//  w  ww .j  a  v  a 2s  .co m
            public void buttonClick(ClickEvent event) {
                reviewPopup = createReviewWindow(rating);
                getWindow().addWindow(reviewPopup);
            }
        });
        btn.setDescription(getDescription(rating));
    } else {
        btn.setEnabled(false);
        btn.setDescription("Login to rate this project.");
    }
    btn.setStyleName(Button.STYLE_LINK);
    btn.setIcon(getIcon(rating));
    hl.addComponent(btn);
}

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);//from  ww  w . ja v  a2  s  .c  o  m
    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.ext.impl.internal.infobox.TagComponent.java

License:Open Source License

@SuppressWarnings({ "deprecation", "serial" })
private void paintTagView() {
    layout.removeAllComponents();//  ww w  .j a  va 2 s. co  m

    Set<String> tags = TaggingUtils.getTags(project);
    if (tags != null && tags.size() > 0) {
        Layout tagListLayout = new CssLayout() {
            @Override
            protected String getCss(Component c) {
                if (c instanceof Label) {
                    return "float: left; line-height:18px; padding-right: 3px;";
                } else {
                    return "float: left; padding-right: 5px";
                }
            }
        };
        tagListLayout.setSizeFull();
        Label tagLabel = new Label("Tags:");
        tagLabel.setSizeUndefined();
        tagListLayout.addComponent(tagLabel);

        for (String tag : tags) {
            Button tagButton = new Button(tag, new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    String tag = event.getButton().getCaption();
                    util.getNavigator().navigateTagView(tag);
                }
            });
            tagButton.setStyleName(Button.STYLE_LINK);
            tagListLayout.addComponent(tagButton);
        }

        Button editButton = new Button("(edit tags)");
        if (util.getLoggedInUser() != null) {
            editButton.addListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    paintTagEdit();
                }
            });
        } else {
            editButton.setEnabled(false);
            editButton.setDescription("Login to tag this project");
        }
        editButton.setStyleName(Button.STYLE_LINK);
        tagListLayout.addComponent(editButton);

        layout.addComponent(tagListLayout);
    } else {
        if (util.getLoggedInUser() != null) {
            Button addTagButton = new Button("(add tags)", new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    paintTagEdit();
                }
            });
            addTagButton.setStyleName(Button.STYLE_LINK);
            layout.addComponent(addTagButton);
        }
    }

}

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

License:Open Source License

/**
 * Renders the OK/Cancel button bar./*  www .  j a  va  2  s  .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

/**
 * Renders a OK/Cancel/Validate/Expand All/Collapse All button bar.
 *//* www  .  ja v  a2  s . c o m*/
@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;
}

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

License:Open Source License

@SuppressWarnings("deprecation")
private void layoutLinkButton(Button button, HorizontalLayout layout, ClickListener listener) {
    button.setStyle(Button.STYLE_LINK);
    button.addListener(listener);
    layout.addComponent(button);/*from   www. j  av  a 2s  . c  o  m*/
    layout.setExpandRatio(button, 0);
    layout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);
}

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

License:Open Source License

private void layoutIconButton(Button button, HorizontalLayout layout, ClickListener listener) {
    button.addListener(listener);
    layout.addComponent(button);/*  www  . ja v a 2 s.co  m*/
    layout.setExpandRatio(button, 0);
    layout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);
}