Search in sources :

Example 1 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class AbstractOptionsBaseLoader method loadOptionsEnum.

@SuppressWarnings("unchecked")
protected void loadOptionsEnum(T resultComponent, Element element) {
    String optionsEnumClass = element.attributeValue("optionsEnum");
    if (StringUtils.isNotEmpty(optionsEnumClass)) {
        Scripting scripting = AppBeans.get(Scripting.class);
        resultComponent.setOptionsEnum((Class<? extends EnumClass>) scripting.loadClass(optionsEnumClass));
    }
}
Also used : Scripting(com.haulmont.cuba.core.global.Scripting)

Example 2 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class AbstractCondition method resolveParam.

protected void resolveParam(Element element) {
    Scripting scripting = AppBeans.get(Scripting.NAME);
    String aclass = element.attributeValue("class");
    if (!isBlank(aclass)) {
        javaClass = scripting.loadClass(aclass);
    }
    String operatorName = element.attributeValue("operatorType", null);
    if (operatorName != null) {
        operator = Op.valueOf(operatorName);
    }
    List<Element> paramElements = Dom4j.elements(element, "param");
    if (!paramElements.isEmpty()) {
        Element paramElem = paramElements.iterator().next();
        if (BooleanUtils.toBoolean(paramElem.attributeValue("hidden", "false"), "true", "false")) {
            paramElem = paramElements.iterator().next();
        }
        paramName = paramElem.attributeValue("name");
        if (!isBlank(paramElem.attributeValue("javaClass"))) {
            paramClass = scripting.loadClass(paramElem.attributeValue("javaClass"));
        }
        ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class);
        if (Strings.isNullOrEmpty(paramName)) {
            paramName = paramBuilder.createParamName(this);
        }
        param = paramBuilder.createParam(this);
        param.setDateInterval(BooleanUtils.toBoolean(paramElem.attributeValue("isDateInterval", "false"), "true", "false"));
        param.parseValue(paramElem.getText());
        param.setDefaultValue(param.getValue());
    }
    if ("EMPTY".equals(operatorName)) {
        // for backward compatibility with old filters that still use EMPTY operator
        operatorName = "NOT_EMPTY";
        if (BooleanUtils.isTrue((Boolean) param.getValue()))
            param.setValue(false);
        param.setDefaultValue(false);
        operator = Op.valueOf(operatorName);
    }
}
Also used : ConditionParamBuilder(com.haulmont.cuba.gui.components.filter.ConditionParamBuilder) Element(org.dom4j.Element) Scripting(com.haulmont.cuba.core.global.Scripting)

Example 3 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class ScriptValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    Boolean isValid = false;
    if (params == null) {
        params = new HashMap<>();
        params.put("value", value);
    } else {
        params.put("value", value);
    }
    Scripting scripting = AppBeans.get(Scripting.NAME);
    if (innerScript) {
        isValid = scripting.evaluateGroovy(script, params);
    } else if (scriptPath != null) {
        isValid = scripting.runGroovyScript(scriptPath, params);
    }
    if (!isValid) {
        String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : ValidationException(com.haulmont.cuba.gui.components.ValidationException) Scripting(com.haulmont.cuba.core.global.Scripting)

Example 4 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class WindowInfo method getScreenClass.

/**
 * Screen class as set in <code>screens.xml</code>
 */
@Nullable
public Class getScreenClass() {
    if (screenClass == null) {
        String className = descriptor.attributeValue("class");
        if (className != null) {
            Scripting scripting = AppBeans.get(Scripting.NAME);
            screenClass = scripting.loadClass(className);
        }
    }
    return screenClass;
}
Also used : Scripting(com.haulmont.cuba.core.global.Scripting) Nullable(javax.annotation.Nullable)

Example 5 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class DynamicAttributeCustomFieldGenerator method generateField.

@Override
public Component generateField(Datasource datasource, String propertyId) {
    ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
    ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
    MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(datasource.getMetaClass(), propertyId);
    if (metaPropertyPath == null) {
        log.error("MetaPropertyPath for dynamic attribute {} not found", propertyId);
        return null;
    }
    CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty());
    if (categoryAttribute == null) {
        log.error("Dynamic attribute {} not found", propertyId);
        return null;
    }
    listEditor.setEntityJoinClause(categoryAttribute.getJoinClause());
    listEditor.setEntityWhereClause(categoryAttribute.getWhereClause());
    ListEditor.ItemType itemType = listEditorItemTypeFromDynamicAttrType(categoryAttribute.getDataType());
    listEditor.setItemType(itemType);
    Metadata metadata = AppBeans.get(Metadata.class);
    Scripting scripting = AppBeans.get(Scripting.class);
    if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) {
        Class<?> clazz = scripting.loadClass(categoryAttribute.getEntityClass());
        if (clazz == null) {
            log.error("Unable to find class of entity {} for dynamic attribute {}", categoryAttribute.getEntityClass(), categoryAttribute.getCode());
            return null;
        }
        MetaClass metaClass = metadata.getClassNN(clazz);
        listEditor.setEntityName(metaClass.getName());
        listEditor.setUseLookupField(BooleanUtils.isTrue(categoryAttribute.getLookup()));
    }
    // noinspection unchecked
    datasource.addStateChangeListener(e -> {
        if (e.getState() == Datasource.State.VALID) {
            Object value = datasource.getItem().getValue(propertyId);
            if (value != null && value instanceof Collection) {
                listEditor.setValue(value);
            }
        }
    });
    listEditor.addValueChangeListener(e -> {
        datasource.getItem().setValue(propertyId, e.getValue());
    });
    listEditor.setWidthFull();
    return listEditor;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) ListEditor(com.haulmont.cuba.gui.components.ListEditor) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Metadata(com.haulmont.cuba.core.global.Metadata) Collection(java.util.Collection) Scripting(com.haulmont.cuba.core.global.Scripting)

Aggregations

Scripting (com.haulmont.cuba.core.global.Scripting)7 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 ListEditor (com.haulmont.cuba.gui.components.ListEditor)1 ValidationException (com.haulmont.cuba.gui.components.ValidationException)1 ConditionParamBuilder (com.haulmont.cuba.gui.components.filter.ConditionParamBuilder)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 Binding (groovy.lang.Binding)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1 Nullable (javax.annotation.Nullable)1 Element (org.dom4j.Element)1