Search in sources :

Example 1 with InputParameter

use of io.jmix.ui.app.inputdialog.InputParameter in project jmix by jmix-framework.

the class InputDialogFacetProvider method loadEntityParameter.

@SuppressWarnings("unchecked")
protected InputParameter loadEntityParameter(Element paramEl, ComponentLoader.ComponentContext context) {
    String paramId = paramEl.attributeValue("id");
    String classFqn = paramEl.attributeValue("entityClass");
    InputParameter parameter;
    Class clazz = loadParamClass(paramEl, classFqn, context);
    MetaClass entityClass = metadata.findClass(clazz);
    if (entityClass != null) {
        parameter = InputParameter.entityParameter(paramId, clazz).withCaption(loadParamCaption(paramEl, context)).withRequired(loadParamRequired(paramEl)).withRequiredMessage(loadRequiredMessage(paramEl, context));
        Field<?> field = loadField(paramId, paramEl, context);
        if (field != null) {
            parameter.withField(() -> field);
        }
    } else {
        throw new GuiDevelopmentException(String.format("Unable to create InputDialog parameter '%s'. Class '%s' is not entity class", paramId, classFqn), context);
    }
    return parameter;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) MetaClass(io.jmix.core.metamodel.model.MetaClass) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) InputParameter(io.jmix.ui.app.inputdialog.InputParameter)

Example 2 with InputParameter

use of io.jmix.ui.app.inputdialog.InputParameter in project jmix by jmix-framework.

the class InputDialogFacetProvider method loadEnumParameter.

@SuppressWarnings("unchecked")
protected InputParameter loadEnumParameter(Element paramEl, ComponentLoader.ComponentContext context) {
    String paramId = paramEl.attributeValue("id");
    String classFqn = paramEl.attributeValue("enumClass");
    InputParameter parameter;
    Class clazz = loadParamClass(paramEl, classFqn, context);
    if (EnumClass.class.isAssignableFrom(clazz)) {
        parameter = InputParameter.enumParameter(paramId, clazz).withCaption(loadParamCaption(paramEl, context)).withRequired(loadParamRequired(paramEl)).withRequiredMessage(loadRequiredMessage(paramEl, context));
        Field<?> field = loadField(paramId, paramEl, context);
        if (field != null) {
            parameter.withField(() -> field);
        }
    } else {
        throw new GuiDevelopmentException(String.format("Unable to create InputDialog parameter '%s'. Class '%s' is not enum class", paramId, classFqn), context);
    }
    return parameter;
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) MetaClass(io.jmix.core.metamodel.model.MetaClass) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) InputParameter(io.jmix.ui.app.inputdialog.InputParameter)

Example 3 with InputParameter

use of io.jmix.ui.app.inputdialog.InputParameter in project jmix by jmix-framework.

the class InputDialogFacetProvider method loadPrimitiveParameter.

protected InputParameter loadPrimitiveParameter(Element paramEl, ComponentLoader.ComponentContext context) {
    String paramId = paramEl.attributeValue("id");
    String paramName = paramEl.getName();
    InputParameter inputParameter;
    if ("bigDecimalParameter".equals(paramName)) {
        // Handle BigDecimal explicitly because its datatype id doesn't match with pattern "typeParameter"
        inputParameter = InputParameter.bigDecimalParameter(paramId).withCaption(loadParamCaption(paramEl, context)).withRequired(loadParamRequired(paramEl)).withRequiredMessage(loadRequiredMessage(paramEl, context)).withDefaultValue(loadDefaultValue(paramEl, datatypeRegistry.get(BigDecimal.class), context));
    } else {
        Datatype datatype = loadDatatype(paramEl, context);
        inputParameter = InputParameter.parameter(paramId).withCaption(loadParamCaption(paramEl, context)).withRequired(loadParamRequired(paramEl)).withRequiredMessage(loadRequiredMessage(paramEl, context)).withUseUserTimeZone(loadUseUserTimeZone(paramEl)).withTimeZone(loadTimeZone(paramEl, context)).withDatatype(datatype).withDefaultValue(loadDefaultValue(paramEl, datatype, context));
    }
    Field<?> field = loadField(paramId, paramEl, context);
    if (field != null) {
        inputParameter.withField(() -> field);
    }
    return inputParameter;
}
Also used : InputParameter(io.jmix.ui.app.inputdialog.InputParameter) BigDecimal(java.math.BigDecimal) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 4 with InputParameter

use of io.jmix.ui.app.inputdialog.InputParameter in project jmix by jmix-framework.

the class InputDialogFacetProvider method loadInputParameters.

protected void loadInputParameters(InputDialogFacet facet, Element element, ComponentLoader.ComponentContext context) {
    List<InputParameter> inputParameters = new ArrayList<>();
    Set<String> paramIds = new HashSet<>();
    Element paramsEl = element.element("parameters");
    if (paramsEl == null) {
        return;
    }
    for (Element paramEl : paramsEl.elements()) {
        String paramId = paramEl.attributeValue("id");
        if (!paramIds.contains(paramId)) {
            inputParameters.add(loadInputParameter(paramEl, context));
            paramIds.add(paramId);
        } else {
            throw new GuiDevelopmentException("InputDialog parameters should have unique ids", context);
        }
    }
    if (inputParameters.isEmpty()) {
        throw new GuiDevelopmentException("InputDialog Facet cannot be used without parameters", context);
    }
    facet.setParameters(inputParameters.toArray(new InputParameter[] {}));
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InputParameter(io.jmix.ui.app.inputdialog.InputParameter)

Aggregations

InputParameter (io.jmix.ui.app.inputdialog.InputParameter)4 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)3 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 BigDecimal (java.math.BigDecimal)1 Element (org.dom4j.Element)1