Java Code Examples for com.google.gwt.dom.client.Style.HasCssName

The following are Jave code examples for showing how to use HasCssName of the com.google.gwt.dom.client.Style class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gwt-material   File: EnumHelper.java   Source Code and License Vote up 5 votes
/**
 * Returns first enum constant found in at space-separated list of style names.
 *
 * @param styleName    Space-separated list of styles
 * @param enumClass    Type of enum
 * @param defaultValue Default value of no match was found
 * @return First enum constant found or default value
 */
@SuppressWarnings("unchecked")
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName,
                                                                           final Class<E> enumClass,
                                                                           final E defaultValue,
                                                                           final boolean ignoreSpaces) {
    if (styleName == null || enumClass == null) {
        return defaultValue;
    }

    for (final Enum<? extends Style.HasCssName> constant : enumClass.getEnumConstants()) {
        final Style.HasCssName anEnum = (Style.HasCssName) constant;
        final String cssClass = anEnum.getCssName();

        if(cssClass != null) {
            boolean contains;
            if (ignoreSpaces) {
                contains = styleName.equals(cssClass);
            } else {
                contains = StyleHelper.containsStyle(styleName, cssClass);
            }
            if (contains) {
                return (E) anEnum;
            }
        }
    }
    return defaultValue;
}
 
Example 2
Project: gwt-material   File: StyleHelper.java   Source Code and License Vote up 5 votes
/**
 * Convenience method for first removing all enum style constants and then adding the single one.
 *
 * @see #removeEnumStyleNames(UIObject, Class)
 * @see #addEnumStyleName(UIObject, Style.HasCssName)
 */
public static <E extends Style.HasCssName, F extends Enum<? extends Style.HasCssName>> void addUniqueEnumStyleName(final UIObject uiObject,
                                                                                                                   final Class<F> enumClass,
                                                                                                                   final E style) {
    removeEnumStyleNames(uiObject, enumClass);
    addEnumStyleName(uiObject, style);
}
 
Example 3
Project: gwt-material   File: StyleHelper.java   Source Code and License Vote up 5 votes
/**
 * Removes all CSS style names specified by an enum that implements {@link Style.HasCssName} from an UIObject.
 *
 * @param uiObject  Object to remove CSS class names from
 * @param enumClass Enum representing CSS class names
 * @param <E>       Enum type implementing {@link Style.HasCssName}
 */
public static <E extends Enum<? extends Style.HasCssName>> void removeEnumStyleNames(final UIObject uiObject,
                                                                                     final Class<E> enumClass) {

    for (final Enum<? extends Style.HasCssName> constant : enumClass.getEnumConstants()) {
        final String cssClass = ((Style.HasCssName) constant).getCssName();

        if (cssClass != null && !cssClass.isEmpty()) {
            uiObject.removeStyleName(cssClass);
        }
    }
}
 
Example 4
Project: gwt-material   File: StyleHelper.java   Source Code and License Vote up 5 votes
/**
 * Adds enum value style name to UIObject unless style is {@code null}.
 *
 * @param uiObject Object to add style to
 * @param style    Style name
 */
public static <E extends Style.HasCssName> void addEnumStyleName(final UIObject uiObject,
                                                                 final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        uiObject.addStyleName(style.getCssName());
    }
}
 
Example 5
Project: gwt-material   File: StyleHelper.java   Source Code and License Vote up 5 votes
/**
 * Removes enum value style name from UIObject unless style is {@code null}.
 *
 * @param uiObject Object to remove style from
 * @param style    Style name
 */
public static <E extends Style.HasCssName> void removeEnumStyleName(final UIObject uiObject,
                                                                    final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        uiObject.removeStyleName(style.getCssName());
    }
}
 
Example 6
Project: gwt-jui   File: JuiWrapper.java   Source Code and License Vote up 5 votes
protected void setOption(String option, MultiTypeOption value) {
    Object foundType = value.get();
    if(foundType instanceof Style.HasCssName) {
        setOption(option, (Style.HasCssName) foundType);
    } else if(foundType instanceof IsJavaScriptObject) {
        setOption(option, (IsJavaScriptObject) foundType);
    } else {
        setNativeOption(getElement(), option, value.get());
    }
}
 
Example 7
Project: appformer   File: StyleHelper.java   Source Code and License Vote up 5 votes
public static <E extends Style.HasCssName, F extends Enum<? extends Style.HasCssName>> void addUniqueEnumStyleName(final Element element,
                                                                                                                   final Class<F> enumClass,
                                                                                                                   final E style) {
    removeEnumStyleNames(element,
                         enumClass);
    addEnumStyleName(element,
                     style);
}
 
Example 8
Project: appformer   File: StyleHelper.java   Source Code and License Vote up 5 votes
public static <E extends Enum<? extends Style.HasCssName>> void removeEnumStyleNames(final Element element,
                                                                                     final Class<E> enumClass) {

    for (final Enum<? extends Style.HasCssName> constant : enumClass.getEnumConstants()) {
        final String cssClass = ((Style.HasCssName) constant).getCssName();

        if (cssClass != null && !cssClass.isEmpty()) {
            element.removeClassName(cssClass);
        }
    }
}
 
Example 9
Project: appformer   File: StyleHelper.java   Source Code and License Vote up 5 votes
public static <E extends Style.HasCssName> void addEnumStyleName(final Element element,
                                                                 final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        element.addClassName(style.getCssName());
    }
}
 
Example 10
Project: appformer   File: StyleHelper.java   Source Code and License Vote up 5 votes
public static <E extends Style.HasCssName> void removeEnumStyleName(final Element element,
                                                                    final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        element.removeClassName(style.getCssName());
    }
}
 
Example 11
Project: gwt-material   File: StyleHelper.java   Source Code and License Vote up 4 votes
public static <F extends Enum<? extends Style.HasCssName>> F fromStyleName(final Class<F> enumClass,
                                                                           final Style.HasCssName styleName) {
    return EnumHelper.fromStyleName(styleName.getCssName(), enumClass, null);
}
 
Example 12
Project: gwt-jui   File: JuiLayer.java   Source Code and License Vote up 4 votes
protected void setOption(String option, Style.HasCssName value) {
    setOption(getElement(), option, value.getCssName());
}
 
Example 13
Project: gwt-jui   File: JuiWrapper.java   Source Code and License Vote up 4 votes
protected void setOption(String option, Style.HasCssName value) {
    setNativeOption(getElement(), option, value.getCssName());
}
 
Example 14
Project: gwt-material   File: EnumHelper.java   Source Code and License Vote up 2 votes
/**
 * Returns first enum constant found in at space-separated list of style names.
 *
 * @param styleName    Space-separated list of styles
 * @param enumClass    Type of enum
 * @param defaultValue Default value of no match was found
 * @return First enum constant found or default value
 */
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName,
                                                                           final Class<E> enumClass,
                                                                           final E defaultValue) {
    return EnumHelper.fromStyleName(styleName, enumClass, defaultValue, false);
}
 
Example 15
Project: gwt-material   File: ColorHelper.java   Source Code and License Vote up 2 votes
/**
 * Returns first enum constant found..
 *
 * @param styleName    Space-separated list of styles
 * @param enumClass    Type of enum
 * @param defaultValue Default value of no match was found
 * @return First enum constant found or default value
 */
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName,
                                                                           final Class<E> enumClass,
                                                                           final E defaultValue) {
    return EnumHelper.fromStyleName(styleName, enumClass, defaultValue, true);
}