Search in sources :

Example 1 with IMapped

use of org.eclipse.vorto.codegen.api.mapping.IMapped in project vorto by eclipse.

the class UIComponentFactory method getByModelId.

public static IFunctionBlockUITemplate getByModelId(FunctionblockModel fbm, InvocationContext ctx) {
    IMapped<FunctionblockModel> mappedElement = ctx.getMappedElement(fbm, STEREOTYPE_COMPONENT);
    String uiType = mappedElement.getAttributeValue(ATTRIBUTE_TYPE, "default");
    if (uiType.equalsIgnoreCase("barchart")) {
        List<String> properties = new ArrayList<String>();
        for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
            IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
            String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
            if (uiProperty.equalsIgnoreCase("value")) {
                properties.add(property.getName());
            }
        }
        return new BarChartUITemplate(properties);
    } else if (uiType.equalsIgnoreCase("map")) {
        String latitude = null;
        String longitude = null;
        for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
            IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
            String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
            if (uiProperty.equalsIgnoreCase("longitude")) {
                longitude = property.getName();
            } else if (uiProperty.equalsIgnoreCase("latitude")) {
                latitude = property.getName();
            }
        }
        return new LocationMapUITemplate(longitude, latitude);
    } else if (uiType.equalsIgnoreCase("gauge")) {
        String value = null;
        String min = null;
        String max = null;
        String symbol = null;
        for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
            IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
            String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
            if (uiProperty.equalsIgnoreCase("value")) {
                value = property.getName();
            } else if (uiProperty.equalsIgnoreCase("min")) {
                min = property.getName();
            } else if (uiProperty.equalsIgnoreCase("max")) {
                max = property.getName();
            } else if (uiProperty.equalsIgnoreCase("symbol")) {
                symbol = property.getName();
            }
        }
        return new GaugeUITemplate(symbol, min, max, value);
    } else {
        return new DefaultUITemplate();
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) GaugeUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.GaugeUITemplate) ArrayList(java.util.ArrayList) LocationMapUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.LocationMapUITemplate) BarChartUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.BarChartUITemplate) IMapped(org.eclipse.vorto.codegen.api.mapping.IMapped) Property(org.eclipse.vorto.core.api.model.datatype.Property) DefaultUITemplate(org.eclipse.vorto.codegen.webui.templates.resources.ui.components.DefaultUITemplate)

Aggregations

ArrayList (java.util.ArrayList)1 IMapped (org.eclipse.vorto.codegen.api.mapping.IMapped)1 BarChartUITemplate (org.eclipse.vorto.codegen.webui.templates.resources.ui.components.BarChartUITemplate)1 DefaultUITemplate (org.eclipse.vorto.codegen.webui.templates.resources.ui.components.DefaultUITemplate)1 GaugeUITemplate (org.eclipse.vorto.codegen.webui.templates.resources.ui.components.GaugeUITemplate)1 LocationMapUITemplate (org.eclipse.vorto.codegen.webui.templates.resources.ui.components.LocationMapUITemplate)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1