Search in sources :

Example 1 with ComponentDecorator

use of com.haulmont.cuba.desktop.theme.ComponentDecorator in project cuba by cuba-platform.

the class CustomDecorator method decorate.

@Override
public void decorate(Object component, Set<String> state) {
    try {
        ComponentDecorator delegate = (ComponentDecorator) decoratorClass.newInstance();
        delegate.decorate(component, state);
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
Also used : ComponentDecorator(com.haulmont.cuba.desktop.theme.ComponentDecorator)

Example 2 with ComponentDecorator

use of com.haulmont.cuba.desktop.theme.ComponentDecorator in project cuba by cuba-platform.

the class DesktopThemeLoaderImpl method loadStyle.

private DesktopStyle loadStyle(Element element) {
    final String componentsSubTag = "components";
    String styleName = element.attributeValue("name");
    List<Class> components = null;
    if (element.attributeValue("component") != null) {
        String className = element.attributeValue("component");
        try {
            components = Collections.singletonList((Class) Class.forName(className));
        } catch (ClassNotFoundException e) {
            log.error("Unknown component class: " + className);
        }
    } else {
        Element componentsElement = element.element(componentsSubTag);
        if (componentsElement != null) {
            String componentsStr = componentsElement.getTextTrim();
            StrTokenizer tokenizer = new StrTokenizer(componentsStr);
            components = new ArrayList<>();
            for (String className : tokenizer.getTokenArray()) {
                try {
                    components.add(Class.forName(className));
                } catch (ClassNotFoundException e) {
                    log.error("Unknown component class: " + className);
                }
            }
        }
    }
    List<ComponentDecorator> decorators = new ArrayList<>();
    for (Element childElement : (List<Element>) element.elements()) {
        if (!componentsSubTag.equals(childElement.getName())) {
            ComponentDecorator decorator = loadDecorator(childElement);
            if (decorator != null) {
                decorators.add(decorator);
            }
        }
    }
    return new DesktopStyle(styleName, decorators, components);
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ComponentDecorator(com.haulmont.cuba.desktop.theme.ComponentDecorator) ArrayList(java.util.ArrayList) List(java.util.List) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Aggregations

ComponentDecorator (com.haulmont.cuba.desktop.theme.ComponentDecorator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StrTokenizer (org.apache.commons.lang.text.StrTokenizer)1 Element (org.dom4j.Element)1