Search in sources :

Example 26 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractScreenFacetProvider method loadProperty.

protected UiControllerProperty loadProperty(Element property, ComponentLoader.ComponentContext context) {
    String name = property.attributeValue("name");
    if (name == null || name.isEmpty()) {
        throw new GuiDevelopmentException("Screen property cannot have empty name", context);
    }
    String value = property.attributeValue("value");
    String ref = property.attributeValue("ref");
    if (StringUtils.isNotEmpty(value) && StringUtils.isNotEmpty(ref)) {
        throw new GuiDevelopmentException("Screen property can have either a value or a reference. Property: " + name, context);
    }
    if (StringUtils.isNotEmpty(value)) {
        return new UiControllerProperty(name, value, UiControllerProperty.Type.VALUE);
    } else if (StringUtils.isNotEmpty(ref)) {
        return new UiControllerProperty(name, ref, UiControllerProperty.Type.REFERENCE);
    } else {
        throw new GuiDevelopmentException("No value or reference found for screen property: " + name, context);
    }
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) UiControllerProperty(io.jmix.ui.sys.UiControllerProperty)

Example 27 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException 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 28 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class InputDialogFacetProvider method loadDialogActions.

protected void loadDialogActions(InputDialogFacet facet, Element element, ComponentLoader.ComponentContext context) {
    loadDialogActions(facet, element);
    Element actions = element.element("actions");
    if (actions != null) {
        if (facet.getDialogActions() == null) {
            loadActions(facet, element, context);
        } else {
            throw new GuiDevelopmentException("Predefined and custom actions cannot be used for InputDialog at the same time", context);
        }
    }
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 29 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException 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 30 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class InputDialogFacetProvider method loadDatatype.

protected Datatype loadDatatype(Element element, ComponentLoader.ComponentContext context) {
    String paramName = element.getName();
    Matcher matcher = PARAM_TYPE_REGEX.matcher(paramName);
    if (matcher.matches()) {
        String typeName = matcher.group(1);
        return datatypeRegistry.get(typeName);
    } else {
        throw new GuiDevelopmentException(String.format("Unsupported InputDialog parameter type: '%s'", paramName), context);
    }
}
Also used : Matcher(java.util.regex.Matcher) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Aggregations

GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)106 Element (org.dom4j.Element)42 FrameOwner (io.jmix.ui.screen.FrameOwner)16 Component (io.jmix.ui.component.Component)13 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 ScreenData (io.jmix.ui.model.ScreenData)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 MetaClass (io.jmix.core.metamodel.model.MetaClass)8 Action (io.jmix.ui.action.Action)7 BaseAction (io.jmix.ui.action.BaseAction)6 ParseException (java.text.ParseException)6 Date (java.util.Date)6 Nullable (javax.annotation.Nullable)6 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 ComponentLoader (io.jmix.ui.xml.layout.ComponentLoader)5 ArrayList (java.util.ArrayList)5 Datasource (com.haulmont.cuba.gui.data.Datasource)4 Formatter (io.jmix.ui.component.formatter.Formatter)4 JsonParser (com.google.gson.JsonParser)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3