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));
}
}
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);
}
}
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));
}
}
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;
}
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;
}
Aggregations