UISliderControl.java

  1. /*
  2.  * Copyright (C) 2003-2008 eXo Platform SAS.
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Affero General Public License
  6.  * as published by the Free Software Foundation; either version 3
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, see<http://www.gnu.org/licenses/>.
  16.  */
  17. package org.exoplatform.forum.webui;

  18. import java.io.Writer;

  19. import org.exoplatform.forum.ForumUtils;
  20. import org.exoplatform.webui.application.WebuiRequestContext;
  21. import org.exoplatform.webui.form.UIFormInputBase;

  22. public class UISliderControl extends UIFormInputBase<String> {
  23.  
  24.  
  25.   int maxValue = 100;

  26.   public UISliderControl(String name, String bindingExpression, String value) {
  27.      this(name, bindingExpression, value, 100);
  28.   }

  29.   public UISliderControl(String name, String bindingExpression, String value, int maxValue) {
  30.     super(name, bindingExpression, String.class);
  31.     this.value_ = value;
  32.     this.maxValue = maxValue;
  33.   }

  34.   public void processRender(WebuiRequestContext context) throws Exception {
  35.     Writer w = context.getWriter();
  36.     w.write("<div class=\"uiFormSliderInput clearfix\" id=\"uiSliderContainer" + getName() + "\" >");
  37.     w.write("  <div class=\"slideSearch pull-left\">");
  38.     w.write("    <div class=\"slide slideContainer\">");
  39.     w.write("      <div class=\"slideRange sllideHeader\" style=\"width: 0px;\"></div>");
  40.     w.write("      <a href=\"javascript:void(0);\" class=\"circleDefault\" style=\"left: 0%;\"></a>");
  41.     w.write("    </div>");
  42.     w.write("  </div>");
  43.     w.write("  <div class=\"boxNumber pull-left\">");
  44.     w.write(new StringBuilder("    <input class=\"uiSliderInput\" type=\"text\" name=\"").append(getName())
  45.                     .append("\" id=\"").append(getName()).append("\" value=\"").append(value_).append("\" readonly/>").toString());
  46.     w.write("  </div>");
  47.     w.write("</div>");

  48.     ForumUtils.addScripts("UISliderControl", "forumSliderControl", "forumSliderControl.init('uiSliderContainer" + getId() + "', " + maxValue + ");");
  49.   }

  50.   public void decode(Object input, WebuiRequestContext context) {
  51.     String val = (String) input;
  52.     if (ForumUtils.isEmpty(val) || (val.equals("null"))){
  53.       value_ = "0";
  54.     } else {
  55.       value_ = val;
  56.     }
  57.   }

  58. }