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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations