use of org.eclipse.smarthome.model.items.ModelNormalItem in project smarthome by eclipse.
the class GenericItemProvider method createItemFromModelItem.
private Item createItemFromModelItem(ModelItem modelItem) {
GenericItem item = null;
if (modelItem instanceof ModelGroupItem) {
ModelGroupItem modelGroupItem = (ModelGroupItem) modelItem;
GenericItem baseItem;
try {
baseItem = createItemOfType(modelGroupItem.getType(), modelGroupItem.getName());
} catch (IllegalArgumentException e) {
logger.debug("Error creating base item for group item '{}', item will be ignored: {}", modelGroupItem.getName(), e.getMessage());
return null;
}
if (baseItem != null) {
// if the user did not specify a function the first value of the enum in xtext (EQUAL) will be used
ModelGroupFunction function = modelGroupItem.getFunction();
item = applyGroupFunction(baseItem, modelGroupItem, function);
} else {
item = new GroupItem(modelGroupItem.getName());
}
} else {
ModelNormalItem normalItem = (ModelNormalItem) modelItem;
try {
item = createItemOfType(normalItem.getType(), normalItem.getName());
} catch (IllegalArgumentException e) {
logger.debug("Error creating item '{}', item will be ignored: {}", normalItem.getName(), e.getMessage());
return null;
}
}
if (item != null) {
String label = modelItem.getLabel();
String format = StringUtils.substringBetween(label, "[", "]");
if (format != null) {
label = StringUtils.substringBefore(label, "[").trim();
stateDescriptions.put(modelItem.getName(), new StateDescription(null, null, null, format, false, null));
}
item.setLabel(label);
item.setCategory(modelItem.getIcon());
assignTags(modelItem, item);
return item;
} else {
return null;
}
}
Aggregations