Search in sources :

Example 1 with PropertyType

use of org.kie.workbench.common.services.datamodeller.core.PropertyType in project kie-wb-common by kiegroup.

the class DataModelHelper method setBaseTypes.

public void setBaseTypes(List<PropertyType> baseTypes) {
    if (baseTypes != null) {
        for (PropertyType type : baseTypes) {
            orderedBaseTypes.put(type.getName(), type);
            baseTypesByClassName.put(type.getClassName(), type);
        }
    }
}
Also used : PropertyType(org.kie.workbench.common.services.datamodeller.core.PropertyType)

Example 2 with PropertyType

use of org.kie.workbench.common.services.datamodeller.core.PropertyType in project kie-wb-common by kiegroup.

the class DataModelerUtils method buildFieldTypeOptions.

public static List<Pair<String, String>> buildFieldTypeOptions(final Collection<PropertyType> baseTypes, final Collection<DataObject> dataObjects, final Collection<JavaEnum> javaEnums, final Collection<DataObject> externalClasses, final Collection<JavaEnum> externalEnums, final String selectedType, final boolean includeEmptyItem) {
    List<Pair<String, String>> typeList = new ArrayList<Pair<String, String>>();
    Collection<JavaType> javaTypes = new ArrayList<JavaType>();
    Collection<JavaType> externalJavaTypes = new ArrayList<JavaType>();
    SortedMap<String, String> sortedModelTypeNames = new TreeMap<String, String>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    SortedMap<String, String> sortedExternalTypeNames = new TreeMap<String, String>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    Map<String, PropertyType> orderedBaseTypes = new TreeMap<String, PropertyType>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    Map<String, PropertyType> baseTypesByClassName = new TreeMap<String, PropertyType>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    boolean selectedTypeIncluded = false;
    if (includeEmptyItem) {
        typeList.add(UIUtil.emptyValue());
    }
    if (baseTypes != null) {
        for (PropertyType type : baseTypes) {
            orderedBaseTypes.put(type.getName(), type);
            baseTypesByClassName.put(type.getClassName(), type);
        }
    }
    // First add all base types, ordered
    for (Map.Entry<String, PropertyType> baseType : orderedBaseTypes.entrySet()) {
        if (!baseType.getValue().isPrimitive()) {
            typeList.add(new Pair(baseType.getKey(), baseType.getValue().getClassName()));
        }
    }
    // collect all model types, ordered
    if (dataObjects != null) {
        javaTypes.addAll(dataObjects);
    }
    if (javaEnums != null) {
        javaTypes.addAll(javaEnums);
    }
    for (JavaType javaType : javaTypes) {
        String className = javaType.getClassName();
        String classLabel;
        if (javaType instanceof DataObject) {
            classLabel = DataModelerUtils.getDataObjectFullLabel((DataObject) javaType);
        } else {
            classLabel = javaType.getClassName();
        }
        sortedModelTypeNames.put(classLabel, className);
        if (selectedType != null && selectedType.equals(className)) {
            selectedTypeIncluded = true;
        }
    }
    // collect external types, ordered
    if (externalClasses != null) {
        externalJavaTypes.addAll(externalClasses);
    }
    if (externalEnums != null) {
        externalJavaTypes.addAll(externalEnums);
    }
    if (externalClasses != null) {
        for (JavaType externalJavaType : externalJavaTypes) {
            String extClass = externalJavaType.getClassName();
            sortedExternalTypeNames.put(DataModelerUtils.EXTERNAL_PREFIX + extClass, extClass);
            if (selectedType != null && selectedType.equals(extClass)) {
                selectedTypeIncluded = true;
            }
        }
    }
    // check selectedType isn't present
    if (selectedType != null && !selectedTypeIncluded && !baseTypesByClassName.containsKey(selectedType)) {
        // uncommon case. A field was loaded but the class isn't within the model or external classes.
        String extClass = selectedType;
        sortedExternalTypeNames.put(DataModelerUtils.EXTERNAL_PREFIX + extClass, extClass);
    }
    // add project classes to the selector.
    for (Map.Entry<String, String> typeName : sortedModelTypeNames.entrySet()) {
        typeList.add(new Pair<String, String>(typeName.getKey(), typeName.getValue()));
    }
    // add external classes to the selector.
    for (Map.Entry<String, String> typeName : sortedExternalTypeNames.entrySet()) {
        typeList.add(new Pair<String, String>(typeName.getKey(), typeName.getValue()));
    }
    // finally add primitives
    for (Map.Entry<String, PropertyType> baseType : orderedBaseTypes.entrySet()) {
        if (baseType.getValue().isPrimitive()) {
            typeList.add(new Pair<String, String>(baseType.getKey(), baseType.getValue().getClassName()));
        }
    }
    return typeList;
}
Also used : ArrayList(java.util.ArrayList) PropertyType(org.kie.workbench.common.services.datamodeller.core.PropertyType) TreeMap(java.util.TreeMap) JavaType(org.kie.workbench.common.services.datamodeller.core.JavaType) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Pair(org.uberfire.commons.data.Pair)

Aggregations

PropertyType (org.kie.workbench.common.services.datamodeller.core.PropertyType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)1 JavaType (org.kie.workbench.common.services.datamodeller.core.JavaType)1 Pair (org.uberfire.commons.data.Pair)1