Search in sources :

Example 81 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project vorto by eclipse.

the class ModelConversionUtils method copyProperty.

private static Property copyProperty(Property property) {
    Property newProperty = DatatypeFactory.eINSTANCE.createProperty();
    newProperty.setName(property.getName());
    newProperty.setPresence(property.getPresence());
    newProperty.setMultiplicity(property.isMultiplicity());
    newProperty.setDescription(property.getDescription());
    newProperty.setConstraintRule(property.getConstraintRule());
    if (property.getType() instanceof PrimitivePropertyType) {
        PrimitivePropertyType newPrimitiveType = DatatypeFactory.eINSTANCE.createPrimitivePropertyType();
        PrimitivePropertyType oldPrimitiveType = (PrimitivePropertyType) property.getType();
        newPrimitiveType.setType(oldPrimitiveType.getType());
        newProperty.setType(newPrimitiveType);
    } else if (property.getType() instanceof ObjectPropertyType) {
        ObjectPropertyType newObjectType = DatatypeFactory.eINSTANCE.createObjectPropertyType();
        ObjectPropertyType oldObjectType = (ObjectPropertyType) property.getType();
        newObjectType.setType(oldObjectType.getType());
        newProperty.setType(newObjectType);
    } else if (property.getType() instanceof DictionaryPropertyType) {
        DictionaryPropertyType newObjectType = DatatypeFactory.eINSTANCE.createDictionaryPropertyType();
        DictionaryPropertyType oldObjectType = (DictionaryPropertyType) property.getType();
        newObjectType.setKeyType(oldObjectType.getKeyType());
        newObjectType.setValueType(oldObjectType.getValueType());
        newProperty.setType(newObjectType);
    }
    EList<org.eclipse.vorto.core.api.model.datatype.PropertyAttribute> oldPropertyAtributeList = property.getPropertyAttributes();
    EList<PropertyAttribute> newPropertyAtributeList = new BasicEList<PropertyAttribute>();
    for (org.eclipse.vorto.core.api.model.datatype.PropertyAttribute oldProp : oldPropertyAtributeList) {
        if (oldProp instanceof BooleanPropertyAttribute) {
            BooleanPropertyAttribute newPropertyAtribute = DatatypeFactory.eINSTANCE.createBooleanPropertyAttribute();
            newPropertyAtribute.setType(((BooleanPropertyAttribute) oldProp).getType());
            newPropertyAtribute.setValue((((BooleanPropertyAttribute) oldProp).isValue()));
            newPropertyAtributeList.add(newPropertyAtribute);
        } else {
            EnumLiteralPropertyAttribute newPropertyAtribute = DatatypeFactory.eINSTANCE.createEnumLiteralPropertyAttribute();
            newPropertyAtribute.setType(((EnumLiteralPropertyAttribute) oldProp).getType());
            newPropertyAtribute.setValue((((EnumLiteralPropertyAttribute) oldProp).getValue()));
            newPropertyAtributeList.add(newPropertyAtribute);
        }
    }
    newProperty.getPropertyAttributes().addAll(newPropertyAtributeList);
    return newProperty;
}
Also used : ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) BasicEList(org.eclipse.emf.common.util.BasicEList) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Example 82 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project vorto by eclipse.

the class Utils method getReferencedTypes.

public static EList<Type> getReferencedTypes(Type type) {
    BasicEList<Type> types = new BasicEList<>();
    types.add(type);
    if (type instanceof Entity) {
        Entity entityType = (Entity) type;
        for (Property property : entityType.getProperties()) {
            types.addAll(getReferencedTypes(property));
        }
        types.add(entityType.getSuperType());
    }
    return types;
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

Example 83 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project vorto by eclipse.

the class ModelConversionUtils method getFlatStatusProperties.

private static List<Property> getFlatStatusProperties(FunctionblockModel fbm) {
    EList<Property> properties = new BasicEList<Property>();
    TreeIterator<EObject> iter = fbm.eAllContents();
    while (iter.hasNext()) {
        EObject obj = iter.next();
        if (obj instanceof Property) {
            Property property = (Property) obj;
            if (property.eContainer() instanceof Status) {
                properties.add(copyProperty(property));
                if (property.getType() instanceof ObjectPropertyType) {
                    ObjectPropertyType objectType = (ObjectPropertyType) property.getType();
                    if (objectType.getType() instanceof Entity) {
                        // only flatten entities
                        Entity entity = (Entity) ((ObjectPropertyType) property.getType()).getType();
                        EList<Property> entityProperties = getFlatProperties(entity);
                        entity.getProperties().clear();
                        entity.getProperties().addAll(entityProperties);
                        if (entity.getSuperType() != null) {
                            removeSuperTypeModelReference(entity);
                        }
                        entity.getProperties().stream().filter(p -> p.getType() instanceof ObjectPropertyType).forEach(p -> createReference(entity, (ObjectPropertyType) p.getType()));
                    }
                }
            }
        }
    }
    if (fbm.getSuperType() != null) {
        properties.addAll(getFlatStatusProperties(fbm.getSuperType()));
    }
    return properties;
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) java.util(java.util) BasicEList(org.eclipse.emf.common.util.BasicEList) ModelIdFactory(org.eclipse.vorto.core.api.model.model.ModelIdFactory) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) PropertyTypeImpl(org.eclipse.internal.xtend.type.baseimpl.types.PropertyTypeImpl) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) EcoreEList(org.eclipse.emf.ecore.util.EcoreEList) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ModelFactory(org.eclipse.vorto.core.api.model.model.ModelFactory) Function(java.util.function.Function) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Model(org.eclipse.vorto.core.api.model.model.Model) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DatatypePackage(org.eclipse.vorto.core.api.model.datatype.DatatypePackage) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockFactory(org.eclipse.vorto.core.api.model.functionblock.FunctionblockFactory) DatatypeFactory(org.eclipse.vorto.core.api.model.datatype.DatatypeFactory) MeasurementSystem(com.ibm.icu.util.LocaleData.MeasurementSystem) TreeIterator(org.eclipse.emf.common.util.TreeIterator) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ConfigurationImpl(org.eclipse.vorto.core.api.model.functionblock.impl.ConfigurationImpl) EObject(org.eclipse.emf.ecore.EObject) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Status(org.eclipse.vorto.core.api.model.functionblock.Status) BooleanAttribute(com.ibm.icu.text.DateFormat.BooleanAttribute) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) BasicEList(org.eclipse.emf.common.util.BasicEList) EObject(org.eclipse.emf.ecore.EObject) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Example 84 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabelColor_labelWithUnitValue.

@Test
public void getLabelColor_labelWithUnitValue() {
    String testLabel = "Label [%.3f " + UnitUtils.UNIT_PLACEHOLDER + "]";
    when(widget.getLabel()).thenReturn(testLabel);
    ColorArray colorArray = mock(ColorArray.class);
    when(colorArray.getState()).thenReturn("20");
    when(colorArray.getCondition()).thenReturn("==");
    when(colorArray.getArg()).thenReturn("yellow");
    BasicEList<ColorArray> colorArrays = new BasicEList<ColorArray>();
    colorArrays.add(colorArray);
    when(widget.getLabelColor()).thenReturn(colorArrays);
    when(item.getState()).thenReturn(new QuantityType<>("20 °C"));
    String color = uiRegistry.getLabelColor(widget);
    assertEquals("yellow", color);
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ColorArray(org.eclipse.smarthome.model.sitemap.ColorArray) Test(org.junit.Test)

Example 85 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project smarthome by eclipse.

the class GenericThingProviderMultipleBundlesTest method createModelThing.

private EList<ModelThing> createModelThing() {
    ModelThing thing = mock(ModelThing.class);
    // simulate a nested defined thing model with only type id & id given:
    when(thing.getThingTypeId()).thenReturn("thing");
    when(thing.getThingId()).thenReturn(THING_ID);
    when(thing.getBridgeUID()).thenReturn(BRIDGE_UID.toString());
    when(thing.getProperties()).thenReturn(new BasicEList<>(0));
    when(thing.getChannels()).thenReturn(new BasicEList<>(0));
    BasicEList<ModelThing> result = new BasicEList<ModelThing>();
    result.add(thing);
    return result;
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) ModelThing(org.eclipse.smarthome.model.thing.thing.ModelThing)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)86 Test (org.junit.Test)27 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)16 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)16 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)16 EEFFeatureEditorDialog (org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 GridData (org.eclipse.swt.layout.GridData)16 EObject (org.eclipse.emf.ecore.EObject)13 TdExpression (org.talend.cwm.relational.TdExpression)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Button (org.eclipse.swt.widgets.Button)8 EList (org.eclipse.emf.common.util.EList)7 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 ProductVersion (org.talend.utils.ProductVersion)7 Property (org.eclipse.vorto.core.api.model.datatype.Property)6 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)6