use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.
the class ItemDTOMapper method fillProperties.
private static void fillProperties(ItemDTO itemDTO, Item item) {
if (item instanceof GroupItem) {
GroupItem groupItem = (GroupItem) item;
GroupItemDTO groupItemDTO = (GroupItemDTO) itemDTO;
if (groupItem.getBaseItem() != null) {
groupItemDTO.groupType = groupItem.getBaseItem().getType();
groupItemDTO.function = mapFunction(groupItem.getFunction());
}
}
itemDTO.name = item.getName();
itemDTO.type = item.getType();
itemDTO.label = item.getLabel();
itemDTO.tags = item.getTags();
itemDTO.category = item.getCategory();
itemDTO.groupNames = item.getGroupNames();
}
use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.
the class AbstractRuleBasedInterpreter method addItem.
private void addItem(Locale locale, HashMap<Item, ArrayList<HashSet<String>>> target, HashSet<String> tokens, Item item) {
HashSet<String> nt = new HashSet<String>(tokens);
nt.addAll(tokenize(locale, item.getLabel()));
ArrayList<HashSet<String>> list = target.get(item);
if (list == null) {
target.put(item, list = new ArrayList<HashSet<String>>());
}
list.add(nt);
if (item instanceof GroupItem) {
for (Item member : ((GroupItem) item).getMembers()) {
addItem(locale, target, nt, member);
}
}
}
use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.
the class ItemResource method removeMember.
@DELETE
@RolesAllowed({ Role.ADMIN })
@Path("/{itemName: [a-zA-Z_0-9]*}/members/{memberItemName: [a-zA-Z_0-9]*}")
@ApiOperation(value = "Removes an existing member from a group item.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Item or member item not found or item is not of type group item."), @ApiResponse(code = 405, message = "Member item is not editable.") })
public Response removeMember(@PathParam("itemName") @ApiParam(value = "item name", required = true) String itemName, @PathParam("memberItemName") @ApiParam(value = "member item name", required = true) String memberItemName) {
try {
Item item = itemRegistry.getItem(itemName);
if (!(item instanceof GroupItem)) {
return Response.status(Status.NOT_FOUND).build();
}
GroupItem groupItem = (GroupItem) item;
Item memberItem = itemRegistry.getItem(memberItemName);
if (!(memberItem instanceof GenericItem)) {
return Response.status(Status.NOT_FOUND).build();
}
if (managedItemProvider.get(memberItemName) == null) {
return Response.status(Status.METHOD_NOT_ALLOWED).build();
}
GenericItem genericMemberItem = (GenericItem) memberItem;
genericMemberItem.removeGroupName(groupItem.getName());
managedItemProvider.update(genericMemberItem);
return Response.ok(null, MediaType.TEXT_PLAIN).build();
} catch (ItemNotFoundException e) {
return Response.status(Status.NOT_FOUND).build();
}
}
use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.
the class ChartRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Chart chart = (Chart) w;
try {
String itemParam = null;
Item item = itemUIRegistry.getItem(chart.getItem());
if (item instanceof GroupItem) {
itemParam = "groups=" + chart.getItem();
} else {
itemParam = "items=" + chart.getItem();
}
String chartUrl = "/chart?" + itemParam + "&period=" + chart.getPeriod();
if (chart.getService() != null) {
chartUrl += "&service=" + chart.getService();
}
// if legend parameter is given, add corresponding GET parameter
if (chart.getLegend() != null) {
if (chart.getLegend()) {
chartUrl += "&legend=true";
} else {
chartUrl += "&legend=false";
}
}
// add theme GET parameter
String chartTheme = null;
switch(config.getTheme()) {
case WebAppConfig.THEME_NAME_DEFAULT:
chartTheme = "bright";
break;
case WebAppConfig.THEME_NAME_DARK:
chartTheme = "dark";
break;
}
if (chartTheme != null) {
chartUrl += "&theme=" + chartTheme;
}
String url;
boolean ignoreRefresh;
if (!itemUIRegistry.getVisiblity(w)) {
url = URL_NONE_ICON;
ignoreRefresh = true;
} else {
// add timestamp to circumvent browser cache
url = chartUrl + "&t=" + (new Date()).getTime();
ignoreRefresh = false;
}
String snippet = getSnippet("chart");
snippet = preprocessSnippet(snippet, w);
if (chart.getRefresh() > 0) {
snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(chart.getRefresh()));
} else {
snippet = StringUtils.replace(snippet, "%update_interval%", "0");
}
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%proxied_url%", chartUrl);
snippet = StringUtils.replace(snippet, "%valid_url%", "true");
snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false");
snippet = StringUtils.replace(snippet, "%url%", url);
sb.append(snippet);
} catch (ItemNotFoundException e) {
logger.warn("Chart cannot be rendered as item '{}' does not exist.", chart.getItem());
}
return null;
}
Aggregations