Example usage for com.vaadin.ui Button setStyleName

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

Introduction

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

Prototype

@Override
    public void setStyleName(String style) 

Source Link

Usage

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

License:Open Source License

private Button createAddButton() {
    Button b = new Button("Add");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);/*from  w  ww. j a va 2s . c  om*/
    b.setDescription("Add another entry");
    b.setEnabled(!readOnly);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            ComboBox cb = createComboBox(null);
            cb.setWidth(columns, Select.UNITS_EM);
            comboBoxEntries.add(new ComboBoxElement(cb));
            layout.removeAllComponents();
            renderComboBoxes();
        }
    });
    return b;
}

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

License:Open Source License

private Button createRemoveButton() {
    Button b = new Button("Remove");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);//  ww w  . ja  v  a2 s.  c  o m
    b.setDescription("Remove this entry");
    b.setEnabled(!readOnly);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            Iterator<ComboBoxElement> it = comboBoxEntries.iterator();
            while (it.hasNext()) {
                ComboBoxElement element = it.next();
                if (element.removeButton == b) {
                    it.remove();
                    break;
                }
            }
            layout.removeAllComponents();
            renderComboBoxes();
        }
    });
    return b;
}

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

License:Open Source License

@SuppressWarnings({ "serial", "deprecation" })
private void render() {
    layout.removeAllComponents();/* w  w w  .  j  av a 2s .c  o  m*/
    if (!readOnly) {
        layout.setColumns(2);
    }

    int groupsIdx = 0;
    int groupsSize = linkGroups.getItems().size();
    for (final LinkGroup linkGroup : linkGroups.getItems()) {
        Label linkGroupLabel = new Label(linkGroup.getCaption());
        linkGroupLabel.addStyleName(STYLE_LABEL_GROUP);

        layout.addComponent(linkGroupLabel);
        layout.setComponentAlignment(linkGroupLabel, Alignment.TOP_RIGHT);

        if (!readOnly) {
            Button btnUpGroup = null;
            Button btnDownGroup = null;
            Button btnRemoveGroup = null;
            // up
            if (groupsIdx > 0) {
                btnUpGroup = new Button("up");
                btnUpGroup.setStyleName(Button.STYLE_LINK);
                btnUpGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
                btnUpGroup.setDescription(String.format("Move up group '%s'", linkGroup.getCaption()));
                btnUpGroup.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroups.moveUp(linkGroup);
                        renderIfModified();
                    }
                });
            }
            // down
            if (groupsIdx < groupsSize - 1) {
                btnDownGroup = new Button("down");
                btnDownGroup.setStyleName(Button.STYLE_LINK);
                btnDownGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
                btnDownGroup.setDescription(String.format("Move down group '%s'", linkGroup.getCaption()));
                btnDownGroup.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroups.moveDown(linkGroup);
                        renderIfModified();
                    }
                });
            }
            // remove
            btnRemoveGroup = new Button("remove");
            btnRemoveGroup.setStyleName(Button.STYLE_LINK);
            btnRemoveGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
            btnRemoveGroup.setDescription(String.format("Remove group '%s'", linkGroup.getCaption()));
            btnRemoveGroup.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    modified = linkGroups.remove(linkGroup);
                    renderIfModified();
                }
            });

            HorizontalLayout toolbar = getToolbar(btnUpGroup, btnDownGroup, btnRemoveGroup);
            layout.addComponent(toolbar);
            layout.setComponentAlignment(toolbar, Alignment.TOP_RIGHT);
        }

        layout.newLine();

        Collection<Link> links = linkGroup.getItems();
        int linksIdx = 0;
        int linksSize = links.size();
        for (final Link link : links) {

            if (readOnly) {
                // view
                Label linkLabel = new Label(link.getLabel());
                linkLabel.addStyleName(STYLE_LABEL_LINK);
                linkLabel.setDescription(StringUtils.abbreviate(link.getUrl(), 50));
                layout.addComponent(linkLabel);
                layout.setComponentAlignment(linkLabel, Alignment.TOP_LEFT);
            } else {
                // edit
                Button btnEditLink = new Button(link.getLabel());
                btnEditLink.setStyleName(Button.STYLE_LINK);
                btnEditLink.addStyleName(STYLE_LABEL_LINK);
                btnEditLink.setDescription(String.format("Edit link '%s' %s", link.getLabel(),
                        StringUtils.isBlank(link.getUrl()) ? "" : "[" + link.getUrl() + "]"));
                btnEditLink.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        LinkWindow editLinkWindow = new LinkWindow(MultiLinkField.this, linkGroups.getItems(),
                                linkGroup, link, MultiLinkField.this);
                        editLinkWindow.show();
                    }
                });
                layout.addComponent(btnEditLink);
                layout.setComponentAlignment(btnEditLink, Alignment.TOP_LEFT);
            }

            if (!readOnly) {
                Button btnUpLink = null;
                Button btnDownLink = null;
                Button btnRemoveLink = null;
                // up
                if (linksIdx > 0) {
                    btnUpLink = new Button("up");
                    btnUpLink.setStyleName(Button.STYLE_LINK);
                    btnUpLink.addStyleName(STYLE_BUTTON_LINKACTION);
                    btnUpLink.setDescription(String.format("Move up link '%s'", link.getLabel()));
                    btnUpLink.addListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            modified = linkGroup.moveUp(link);
                            renderIfModified();
                        }
                    });
                }
                // down
                if (linksIdx < linksSize - 1) {
                    btnDownLink = new Button("down");
                    btnDownLink.setStyleName(Button.STYLE_LINK);
                    btnDownLink.addStyleName(STYLE_BUTTON_LINKACTION);
                    btnDownLink.setDescription(String.format("Move down link '%s'", link.getLabel()));
                    btnDownLink.addListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            modified = linkGroup.moveDown(link);
                            renderIfModified();
                        }
                    });
                }
                // remove
                btnRemoveLink = new Button("remove");
                btnRemoveLink.setStyleName(Button.STYLE_LINK);
                btnRemoveLink.addStyleName(STYLE_BUTTON_LINKACTION);
                btnRemoveLink.setDescription(String.format("Remove link '%s'", link.getLabel()));
                btnRemoveLink.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroup.remove(link);
                        if (linkGroup.getItems().isEmpty()) {
                            linkGroups.remove(linkGroup);
                        }
                        renderIfModified();
                    }
                });

                HorizontalLayout toolbar = getToolbar(btnUpLink, btnDownLink, btnRemoveLink);
                layout.addComponent(toolbar);
                layout.setComponentAlignment(toolbar, Alignment.TOP_RIGHT);
            }

            layout.newLine();

            linksIdx++;
        }

        groupsIdx++;
    }

    if (!readOnly) {
        Button btnAddLink = new Button(buttonCaption, new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                LinkWindow addLinkWindow = new LinkWindow(MultiLinkField.this, linkGroups.getItems(),
                        MultiLinkField.this);
                addLinkWindow.show();
            }
        });
        btnAddLink.setStyleName(Button.STYLE_LINK);
        btnAddLink.addStyleName(STYLE_BUTTON_ADD);
        btnAddLink.setDescription("Add Link");
        layout.addComponent(btnAddLink);
    }
}

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

License:Open Source License

private Button createAddButton() {
    Button b = new Button("Add");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);//from  www.  j  ava2  s .c o  m
    b.setDescription("Add another entry");
    //b.setIcon(ICON_BUTTON_ADD);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            TextField tf = createTextField("");
            textFieldEntries.add(new TextFieldEntry(tf));
            layout.removeAllComponents();
            renderTextFields();
        }
    });
    return b;
}

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

License:Open Source License

private Button createRemoveButton() {
    Button b = new Button("Remove");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);/*  w  ww  .j a  v  a 2  s  .c  o  m*/
    b.setDescription("Remove this entry");
    //b.setIcon(ICON_BUTTON_REMOVE);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            Iterator<TextFieldEntry> it = textFieldEntries.iterator();
            while (it.hasNext()) {
                TextFieldEntry textFieldEntry = it.next();
                if (textFieldEntry.removeButton == b) {
                    it.remove();
                    break;
                }
            }
            layout.removeAllComponents();
            renderTextFields();
        }
    });
    return b;
}

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

License:Open Source License

private void createContents() {
    setModal(true);/*from w w  w .j  a v a  2  s .c  om*/
    setCaption("Search people...");

    setWidth("310px"); //$NON-NLS-1$
    setHeight("400px"); //$NON-NLS-1$

    root = new VerticalLayout();
    root.setMargin(true);
    root.setSpacing(true);

    HorizontalLayout search = new HorizontalLayout();
    search.setSpacing(true);

    searchField = new TextField("Search for:");
    searchField.setWidth("20em"); //$NON-NLS-1$
    searchField.setImmediate(true);
    searchField.addListener(new ValueChangeListener() {
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            search((String) searchField.getValue());
            list.focus();
        }
    });
    search.addComponent(searchField);
    search.setComponentAlignment(searchField, Alignment.BOTTOM_LEFT);
    search.setExpandRatio(searchField, 1.0f);

    Button searchButton = new NativeButton("", new Button.ClickListener() { //$NON-NLS-1$
        @Override
        public void buttonClick(ClickEvent event) {
            search((String) searchField.getValue());
        }
    });
    searchButton.setDescription("Search");
    searchButton.setStyleName(STYLE_USER_DOSEARCH);
    search.addComponent(searchButton);
    search.setComponentAlignment(searchButton, Alignment.BOTTOM_LEFT);
    search.setExpandRatio(searchButton, 0);

    root.addComponent(search);

    list = new ListSelect("Search results:", dataSource);
    list.setSizeFull();
    list.setMultiSelect(true);
    list.setImmediate(true);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);

    Button addButton = new Button("Add");
    addButton.setIcon(ICON_BUTTON_ADD_SELECTED);
    addButton.setDescription("Adds the selected person to the list.");
    addButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Set<User> values = (Set<User>) list.getValue();
            if (selectHandler != null && values != null) {
                selectHandler.onPeopleSelected(values);
                list.removeAllItems();
                searchField.setValue(""); //$NON-NLS-1$
                searchField.focus();
            }
        }
    });
    buttons.addComponent(addButton);

    Button addAndCloseButton = new Button("Add & Close");
    addAndCloseButton.setIcon(ICON_BUTTON_ADD_SELECTED);
    addAndCloseButton.setDescription("Adds the selected person to the list and closes the dialog.");
    addAndCloseButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Set<User> values = (Set<User>) list.getValue();
            if (selectHandler != null && values != null) {
                selectHandler.onPeopleSelected(values);
                close();
            }
        }
    });
    buttons.addComponent(addAndCloseButton);

    root.addComponent(list);
    root.addComponent(buttons);
    root.setSizeFull();
    root.setExpandRatio(list, 1);
    //    root.setStyleName(STYLE_LAYOUT);
    setContent(root);
    searchField.focus();
}

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

License:Open Source License

private void renderEntries() {
    int row = 0;//from w ww.  j  ava2s  . c  om
    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);//  ww w.j  a  v  a 2s.c om
    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.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/*from   ww w .j  a v  a2 s .com*/
            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.TagComponent.java

License:Open Source License

@SuppressWarnings({ "deprecation", "serial" })
private void paintTagView() {
    layout.removeAllComponents();//from  w w  w.j  a v a  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);
        }
    }

}