Package org.openhab.model.sitemap

Examples of org.openhab.model.sitemap.Switch


 
  /**
   * {@inheritDoc}
   */
  public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Switch s = (Switch) w;
   
    String snippetName = null;
    Item item;
    try {
      item = itemUIRegistry.getItem(w.getItem());
      if(s.getMappings().size()==0) {
        if(item instanceof RollershutterItem) {
          snippetName = "rollerblind";
        } else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) {
          snippetName = "rollerblind";
        } else {
          snippetName = "switch";
        }
      } else {
        snippetName = "buttons";
      }
    } catch (ItemNotFoundException e) {
      logger.warn("Cannot determine item type of '{}'", w.getItem(), e);
      snippetName = "switch";
    }

    String snippet = getSnippet(snippetName);

    snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
    snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(w)));
    snippet = StringUtils.replace(snippet, "%item%", w.getItem());
    snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
   
    State state = itemUIRegistry.getState(w);
   
    if(s.getMappings().size()==0) {
      if(state instanceof PercentType) {
        state = ((PercentType) state).intValue() > 0 ? OnOffType.ON : OnOffType.OFF;
      }
      if(state.equals(OnOffType.ON)) {
        snippet = snippet.replaceAll("%checked%", "checked=true");
      } else {
        snippet = snippet.replaceAll("%checked%", "");
      }
    } else {
      StringBuilder buttons = new StringBuilder();
      for(Mapping mapping : s.getMappings()) {
        String button = getSnippet("button");
        button = StringUtils.replace(button, "%item%",w.getItem());
        button = StringUtils.replace(button, "%cmd%", mapping.getCmd());
        button = StringUtils.replace(button, "%label%", mapping.getLabel());
        if(s.getMappings().size()>1 && state.toString().equals(mapping.getCmd())) {
          button = StringUtils.replace(button, "%type%", "Warn"); // button with red color
        } else {
          button = StringUtils.replace(button, "%type%", "Action"); // button with blue color
        }
        buttons.insert(0, button);
View Full Code Here


        bean.linkedPage = createPageBean(sitemapName, itemUIRegistry.getLabel(widget), itemUIRegistry.getIcon(widget), pageName,
            drillDown ? children : null, drillDown, isLeaf(children), uri);
        }
    }
      if(widget instanceof Switch) {
        Switch switchWidget = (Switch) widget;
        for(Mapping mapping : switchWidget.getMappings()) {
          MappingBean mappingBean = new MappingBean();
        // Remove quotes - if they exist
        if(mapping.getCmd() != null) {
          if(mapping.getCmd().startsWith("\"") && mapping.getCmd().endsWith("\"")) {
            mappingBean.command = mapping.getCmd().substring(1, mapping.getCmd().length()-1);
View Full Code Here

TOP

Related Classes of org.openhab.model.sitemap.Switch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.