com.vaadin.ui.StyleGenerator Java Examples

The following examples show how to use com.vaadin.ui.StyleGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected T readItem(final Element child, final Set<T> selected, final DesignContext context) {
    final T item = super.readItem(child, selected, context);

    if (child.hasAttr("style")) {
        final StyleGenerator<T> styleGenerator = getStyleGenerator();
        if (styleGenerator instanceof DeclarativeStyleGenerator) {
            ((DeclarativeStyleGenerator) styleGenerator).setStyle(item, child.attr("style"));
        }
        else {
            throw new IllegalStateException(String.format("Don't know how " + "to set style using current style generator '%s'", styleGenerator.getClass()
                                                          .getName()));
        }
    }
    return item;
}
 
Example #2
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected T readItem(final Element child, final Set<T> selected, final DesignContext context) {
    final T item = super.readItem(child, selected, context);

    if (child.hasAttr("style")) {
        final StyleGenerator<T> styleGenerator = getStyleGenerator();
        if (styleGenerator instanceof DeclarativeStyleGenerator) {
            ((DeclarativeStyleGenerator) styleGenerator).setStyle(item, child.attr("style"));
        }
        else {
            throw new IllegalStateException(String.format("Don't know how " + "to set style using current style generator '%s'", styleGenerator.getClass()
                                                          .getName()));
        }
    }
    return item;
}
 
Example #3
Source File: BugSeverityComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public BugSeverityComboBox() {
    super(BugSeverity.class, OptionI18nEnum.bug_severities);
    setWidth(WebThemes.FORM_CONTROL_WIDTH);
    setItemIconGenerator((IconGenerator<BugSeverity>) severity -> VaadinIcons.STAR);
    setStyleGenerator((StyleGenerator<BugSeverity>) severity -> {
        if (severity != null) {
            return "bug-severity-" + severity.toString().toLowerCase();
        } else {
            return null;
        }
    });
    setValue(Major);
}
 
Example #4
Source File: PriorityComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public PriorityComboBox() {
    super(Priority.class, Urgent, High, Medium, Low, None);
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
    this.setItemIconGenerator((IconGenerator<Priority>) item -> {
        if (item == Urgent || item == High || item == Medium) {
            return VaadinIcons.ARROW_UP;
        } else {
            return VaadinIcons.ARROW_DOWN;
        }
    });
    this.setStyleGenerator((StyleGenerator<Priority>) itemId -> String.format("priority-%s", itemId.name().toLowerCase()));
    this.setValue(Medium);
}
 
Example #5
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
public DeclarativeStyleGenerator(final StyleGenerator<T> fallback) {
    this.fallback = fallback;
}
 
Example #6
Source File: CubaComboBoxPickerField.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void setStyleGenerator(StyleGenerator<T> generateItemStylename) {
    getFieldInternal().setStyleGenerator(generateItemStylename);
}
 
Example #7
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
public DeclarativeStyleGenerator(final StyleGenerator<T> fallback) {
    this.fallback = fallback;
}
 
Example #8
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the style generator that is used to produce custom class names for items visible in the popup. The CSS class name that will be added to the item is
 * <tt>v-filterselect-item-[style name]</tt>. Returning null from the generator results in no custom style name being set.
 *
 * @see StyleGenerator
 *
 * @param itemStyleGenerator the item style generator to set, not null
 * @throws NullPointerException if {@code itemStyleGenerator} is {@code null}
 * @since 8.0
 */
public void setStyleGenerator(final StyleGenerator<T> itemStyleGenerator) {
    Objects.requireNonNull(itemStyleGenerator, "Item style generator must not be null");
    this.itemStyleGenerator = itemStyleGenerator;
    getDataCommunicator().reset();
}
 
Example #9
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the currently used style generator that is used to generate CSS class names for items. The default item style provider returns null for all items,
 * resulting in no custom item class names being set.
 *
 * @see StyleGenerator
 * @see #setStyleGenerator(StyleGenerator)
 *
 * @return the currently used item style generator, not null
 * @since 8.0
 */
public StyleGenerator<T> getStyleGenerator() {
    return this.itemStyleGenerator;
}
 
Example #10
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the style generator that is used to produce custom class names for items visible in the popup. The CSS class name that will be added to the item is
 * <tt>v-filterselect-item-[style name]</tt>. Returning null from the generator results in no custom style name being set.
 *
 * @see StyleGenerator
 *
 * @param itemStyleGenerator the item style generator to set, not null
 * @throws NullPointerException if {@code itemStyleGenerator} is {@code null}
 * @since 8.0
 */
public void setStyleGenerator(final StyleGenerator<T> itemStyleGenerator) {
    Objects.requireNonNull(itemStyleGenerator, "Item style generator must not be null");
    this.itemStyleGenerator = itemStyleGenerator;
    getDataCommunicator().reset();
}
 
Example #11
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the currently used style generator that is used to generate CSS class names for items. The default item style provider returns null for all items,
 * resulting in no custom item class names being set.
 *
 * @see StyleGenerator
 * @see #setStyleGenerator(StyleGenerator)
 *
 * @return the currently used item style generator, not null
 * @since 8.0
 */
public StyleGenerator<T> getStyleGenerator() {
    return this.itemStyleGenerator;
}