Search in sources :

Example 1 with ListModelType

use of com.vaadin.flow.templatemodel.ListModelType in project flow by vaadin.

the class PolymerTemplate method getModelType.

/**
 * Get the {@code ModelType} for given class.
 *
 * @param type
 *            Type to get the ModelType for
 * @return ModelType for given Type
 */
public ModelType getModelType(Type type) {
    List<ModelType> modelTypes = ModelDescriptor.get(getModelType()).getPropertyNames().map(this::getModelType).collect(Collectors.toList());
    for (ModelType mtype : modelTypes) {
        if (type.equals(mtype.getJavaType())) {
            return mtype;
        } else if (mtype instanceof ListModelType) {
            ModelType modelType = getModelTypeForListModel(type, mtype);
            if (modelType != null) {
                return modelType;
            }
        }
    }
    String msg = String.format("Couldn't find ModelType for requested class %s", type.getTypeName());
    throw new IllegalArgumentException(msg);
}
Also used : ListModelType(com.vaadin.flow.templatemodel.ListModelType) BeanModelType(com.vaadin.flow.templatemodel.BeanModelType) ListModelType(com.vaadin.flow.templatemodel.ListModelType) ModelType(com.vaadin.flow.templatemodel.ModelType)

Example 2 with ListModelType

use of com.vaadin.flow.templatemodel.ListModelType in project flow by vaadin.

the class PolymerTemplate method isSupportedClass.

/**
 * Check if the given Class {@code type} is found in the Model.
 *
 * @param type
 *            Class to check support for
 * @return True if supported by this PolymerTemplate
 */
public boolean isSupportedClass(Class<?> type) {
    List<ModelType> modelTypes = ModelDescriptor.get(getModelType()).getPropertyNames().map(this::getModelType).collect(Collectors.toList());
    boolean result = false;
    for (ModelType modelType : modelTypes) {
        if (type.equals(modelType.getJavaType())) {
            result = true;
        } else if (modelType instanceof ListModelType) {
            result = checkListType(type, modelType);
        }
        if (result) {
            break;
        }
    }
    return result;
}
Also used : ListModelType(com.vaadin.flow.templatemodel.ListModelType) BeanModelType(com.vaadin.flow.templatemodel.BeanModelType) ListModelType(com.vaadin.flow.templatemodel.ListModelType) ModelType(com.vaadin.flow.templatemodel.ModelType)

Example 3 with ListModelType

use of com.vaadin.flow.templatemodel.ListModelType in project flow by vaadin.

the class AbstractTemplate method getModelType.

/**
 * Get the {@code ModelType} for given class.
 *
 * @param type
 *            Type to get the ModelType for
 * @return ModelType for given Type
 */
public ModelType getModelType(Type type) {
    List<ModelType> modelTypes = ModelDescriptor.get(getModelType()).getPropertyNames().map(this::getModelType).collect(Collectors.toList());
    for (ModelType mtype : modelTypes) {
        if (type.equals(mtype.getJavaType())) {
            return mtype;
        } else if (mtype instanceof ListModelType) {
            ModelType modelType = getModelTypeForListModel(type, mtype);
            if (modelType != null) {
                return modelType;
            }
        }
    }
    String msg = String.format("Couldn't find ModelType for requested class %s", type.getTypeName());
    throw new IllegalArgumentException(msg);
}
Also used : ListModelType(com.vaadin.flow.templatemodel.ListModelType) BeanModelType(com.vaadin.flow.templatemodel.BeanModelType) ListModelType(com.vaadin.flow.templatemodel.ListModelType) ModelType(com.vaadin.flow.templatemodel.ModelType)

Example 4 with ListModelType

use of com.vaadin.flow.templatemodel.ListModelType in project flow by vaadin.

the class AbstractTemplate method isSupportedClass.

/**
 * Check if the given Class {@code type} is found in the Model.
 *
 * @param type
 *            Class to check support for
 * @return True if supported by this PolymerTemplate
 */
public boolean isSupportedClass(Class<?> type) {
    List<ModelType> modelTypes = ModelDescriptor.get(getModelType()).getPropertyNames().map(this::getModelType).collect(Collectors.toList());
    boolean result = false;
    for (ModelType modelType : modelTypes) {
        if (type.equals(modelType.getJavaType())) {
            result = true;
        } else if (modelType instanceof ListModelType) {
            result = checkListType(type, modelType);
        }
        if (result) {
            break;
        }
    }
    return result;
}
Also used : ListModelType(com.vaadin.flow.templatemodel.ListModelType) BeanModelType(com.vaadin.flow.templatemodel.BeanModelType) ListModelType(com.vaadin.flow.templatemodel.ListModelType) ModelType(com.vaadin.flow.templatemodel.ModelType)

Aggregations

BeanModelType (com.vaadin.flow.templatemodel.BeanModelType)4 ListModelType (com.vaadin.flow.templatemodel.ListModelType)4 ModelType (com.vaadin.flow.templatemodel.ModelType)4