use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemUIRegistryImpl method processColorDefinition.
private String processColorDefinition(State state, List<ColorArray> colorList) {
// Sanity check
if (colorList == null) {
return null;
}
if (colorList.size() == 0) {
return null;
}
String colorString = null;
// static colour
if (colorList.size() == 1 && colorList.get(0).getState() == null) {
colorString = colorList.get(0).getArg();
} else {
// with the supplied value
for (ColorArray color : colorList) {
// Use a local state variable in case it gets overridden below
State cmpState = state;
if (color.getState() == null) {
logger.error("Error parsing color");
continue;
}
// If there's an item defined here, get its state
String itemName = color.getItem();
if (itemName != null) {
// Try and find the item to test.
// If it's not found, return visible
Item item;
try {
item = itemRegistry.getItem(itemName);
// Get the item state
cmpState = item.getState();
} catch (ItemNotFoundException e) {
logger.warn("Cannot retrieve color item {} for widget", color.getItem());
}
}
// Handle the sign
String value;
if (color.getSign() != null) {
value = color.getSign() + color.getState();
} else {
value = color.getState();
}
if (matchStateToValue(cmpState, value, color.getCondition()) == true) {
// We have the color for this value - break!
colorString = color.getArg();
break;
}
}
}
// Remove quotes off the colour - if they exist
if (colorString == null) {
return null;
}
if (colorString.startsWith("\"") && colorString.endsWith("\"")) {
colorString = colorString.substring(1, colorString.length() - 1);
}
return colorString;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemUIRegistryImpl method getDynamicGroupChildren.
/**
* This method creates a list of children for a group dynamically.
* If there are no explicit children defined in a sitemap, the children
* can thus be created on the fly by iterating over the members of the group item.
*
* @param group The group widget to get children for
* @return a list of default widgets provided for the member items
*/
private EList<Widget> getDynamicGroupChildren(Group group) {
EList<Widget> children = new BasicEList<Widget>();
String itemName = group.getItem();
try {
if (itemName != null) {
Item item = getItem(itemName);
if (item instanceof GroupItem) {
GroupItem groupItem = (GroupItem) item;
for (Item member : groupItem.getMembers()) {
Widget widget = getDefaultWidget(member.getClass(), member.getName());
if (widget != null) {
widget.setItem(member.getName());
children.add(widget);
}
}
} else {
logger.warn("Item '{}' is not a group.", item.getName());
}
} else {
logger.warn("Group does not specify an associated item - ignoring it.");
}
} catch (ItemNotFoundException e) {
logger.warn("Dynamic group with label '{}' will be ignored, because its item '{}' does not exist.", group.getLabel(), itemName);
}
return children;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemUIRegistryImpl method getVisiblity.
@Override
public boolean getVisiblity(Widget w) {
// Default to visible if parameters not set
List<VisibilityRule> ruleList = w.getVisibility();
if (ruleList == null) {
return true;
}
if (ruleList.size() == 0) {
return true;
}
logger.debug("Checking visiblity for widget '{}'.", w.getLabel());
for (VisibilityRule rule : w.getVisibility()) {
String itemName = rule.getItem();
if (itemName == null) {
continue;
}
if (rule.getState() == null) {
continue;
}
// Try and find the item to test.
// If it's not found, return visible
Item item;
try {
item = itemRegistry.getItem(itemName);
} catch (ItemNotFoundException e) {
logger.error("Cannot retrieve visibility item {} for widget {}", rule.getItem(), w.eClass().getInstanceTypeName());
// Default to visible!
return true;
}
// Get the item state
State state = item.getState();
// Handle the sign
String value;
if (rule.getSign() != null) {
value = rule.getSign() + rule.getState();
} else {
value = rule.getState();
}
if (matchStateToValue(state, value, rule.getCondition()) == true) {
// We have the name for this value!
return true;
}
}
logger.debug("Widget {} is not visible.", w.getLabel());
// The state wasn't in the list, so we don't display it
return false;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_transformationContainingPercentS.
@Test
public void getLabel_transformationContainingPercentS() throws ItemNotFoundException {
// It doesn't matter that "FOO" doesn't exist - this is to assert it doesn't fail before because of the two "%s"
String testLabel = "Memory [FOO(echo %s):%s]";
Widget w = mock(Widget.class);
Item item = mock(Item.class);
when(w.getLabel()).thenReturn(testLabel);
when(w.getItem()).thenReturn("Item");
when(registry.getItem("Item")).thenReturn(item);
when(item.getState()).thenReturn(new StringType("State"));
String label = uiRegistry.getLabel(w);
assertEquals("Memory [State]", label);
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithZonedDate.
@Test
public void getLabel_labelWithZonedDate() throws ItemNotFoundException {
String testLabel = "Label [%1$td.%1$tm.%1$tY]";
Widget w = mock(Widget.class);
Item item = mock(Item.class);
when(w.getLabel()).thenReturn(testLabel);
when(w.getItem()).thenReturn("Item");
when(registry.getItem("Item")).thenReturn(item);
when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00Z"));
String label = uiRegistry.getLabel(w);
assertEquals("Label [01.06.2011]", label);
}
Aggregations