Ejemplo n.º 1
0
  protected void renderField(Field<?> field, int index, El target) {
    String ls = field.getLabelSeparator() != null ? field.getLabelSeparator() : labelSeparator;
    field.setLabelSeparator(ls);
    Params p = new Params();
    if (hideLabels) {
      field.setHideLabel(true);
    }

    p.add(field.getId());
    p.add(field.getFieldLabel());
    p.add(labelStyle);
    p.add(elementStyle);
    p.add(ls);
    p.add(field.isHideLabel() ? "x-hide-label" : "");
    p.add("x-form-clear-left");
    p.add(field.getLabelStyle());

    String inputId = field.getId();
    p.add(inputId);

    fieldTemplate.insert(target.dom, index, p);
    if (field.isRendered()) {
      target.selectNode(".x-form-el-" + field.getId()).appendChild(field.getElement());
    } else {
      field.render(target.selectNode(".x-form-el-" + field.getId()).dom);
    }

    if (field.getStyleName().contains("-wrap")) {
      inputId += "-input";
      target
          .selectNode(".x-form-el-" + field.getId())
          .previousSibling()
          .setAttribute("for", inputId);
    }
  }
Ejemplo n.º 2
0
  /**
   * Replaces the button icon <b>but</b> does not save icon reference into parent {@code icon}
   * attribute.
   *
   * @param icon The button icon to display.
   */
  private void replaceIcon(final AbstractImagePrototype icon) {

    if (rendered) {
      El oldIcon = buttonEl.selectNode("." + baseStyle + "-image");
      if (oldIcon != null) {
        oldIcon.remove();
        el().removeStyleName(baseStyle + "-text-icon", baseStyle + "-icon", baseStyle + "-noicon");
      }
      el().addStyleName(
              (icon != null
                  ? (!Util.isEmptyString(html)
                      ? " " + baseStyle + "-text-icon"
                      : " " + baseStyle + "-icon")
                  : " " + baseStyle + "-noicon"));
      Element e = null;

      if (icon != null) {
        e = (Element) icon.createElement().cast();

        Accessibility.setRole(e, "presentation");
        fly(e).addStyleName(baseStyle + "-image");

        buttonEl.insertFirst(e);
        El.fly(e).makePositionable(true);
      }
      autoWidth();
      alignIcon(e);
    }
  }
Ejemplo n.º 3
0
 @Override
 public void onComponentEvent(ComponentEvent ce) {
   super.onComponentEvent(ce);
   switch (ce.getEventTypeInt()) {
     case Event.ONCLICK:
       onClick(ce);
       break;
     case Event.ONMOUSEMOVE:
       onMouseMove(ce);
       break;
     case Event.ONMOUSEOUT:
       onMouseOut(ce);
       break;
     case Event.ONMOUSEOVER:
       onMouseOver(ce);
       break;
     case Event.ONMOUSEWHEEL:
       if (enableScrolling) {
         scrollMenu(ce.getEvent().getMouseWheelVelocityY() < 0);
       }
   }
   El t = ce.getTargetEl();
   if (enableScrolling && t.is(".x-menu-scroller")) {
     switch (ce.getEventTypeInt()) {
       case Event.ONMOUSEOVER:
         // deactiveActiveItem();
         onScrollerIn(t);
         break;
       case Event.ONMOUSEOUT:
         onScrollerOut(t);
         break;
     }
   }
 }
Ejemplo n.º 4
0
  protected void createScrollers() {
    if (el().select(".x-menu-scroller").getLength() == 0) {
      Listener<ClickRepeaterEvent> listener =
          new Listener<ClickRepeaterEvent>() {
            public void handleEvent(ClickRepeaterEvent be) {
              onScroll(be);
            }
          };

      El scroller;

      scroller = new El(DOM.createDiv());
      scroller.addStyleName("x-menu-scroller", "x-menu-scroller-top");
      scroller.setInnerHtml("&nbsp;");
      ClickRepeater cr = new ClickRepeater(scroller);
      cr.doAttach();
      cr.addListener(Events.OnClick, listener);
      addAttachable(cr);

      el().insertFirst(scroller.dom);

      scroller = new El(DOM.createDiv());
      scroller.addStyleName("x-menu-scroller", "x-menu-scroller-bottom");
      scroller.setInnerHtml("&nbsp;");
      cr = new ClickRepeater(scroller);
      cr.doAttach();
      cr.addListener(Events.OnClick, listener);
      addAttachable(cr);

      el().appendChild(scroller.dom);
    }
  }
Ejemplo n.º 5
0
  /**
   * Sets the button's icon style. The style name should match a CSS style that specifies a
   * background image using the following format:
   *
   * <pre>
   *
   * &lt;code&gt; .my-icon { background: url(images/icons/my-icon.png) no-repeat
   * center left !important; } &lt;/code&gt;
   *
   * </pre>
   *
   * @param icon the icon
   */
  public void setIcon(AbstractImagePrototype icon) {
    if (rendered) {
      if (buttonEl.selectNode("img") != null) {
        buttonEl.selectNode("img").remove();
        el().removeStyleName("x-btn-text-icon", "x-btn-icon", "x-btn-noicon");
      }
      el().addStyleName(
              (icon != null
                  ? ((text != null && text.length() > 0) ? " x-btn-text-icon" : " x-btn-icon")
                  : " x-btn-noicon"));
      if (icon != null) {

        Element e = (Element) icon.createElement().cast();
        buttonEl.insertFirst(e);
        El.fly(e).makePositionable(true);
        String align = "b-b";
        if (iconAlign == IconAlign.BOTTOM) {
          align = "b-b";
        } else if (iconAlign == IconAlign.TOP) {
          align = "t-t";
        } else if (iconAlign == IconAlign.LEFT) {
          align = "tl-tl";
        } else if (iconAlign == IconAlign.RIGHT) {
          align = "tr-tr";
        }
        El.fly(e).alignTo(buttonEl.dom, align, null);
      }
    }
    this.icon = icon;
  }
Ejemplo n.º 6
0
 private El findLabelElement(Component c) {
   El elem = findItemElement(c);
   if (elem != null) {
     return elem.firstChild();
   }
   return null;
 }
Ejemplo n.º 7
0
  @Override
  protected void onRender(Element parent, int pos) {
    setElement(DOM.createFieldSet(), parent, pos);

    legend = new El(DOM.createLegend());
    legend.addStyleName("x-fieldset-header");

    if (checkboxToggle && collapsible) {
      checkbox = DOM.createInputCheck().cast();
      sinkEvents(Event.ONCLICK);
      if (checkboxName != null) {
        checkbox.setAttribute("name", checkboxName);
      }
      legend.appendChild((Element) checkbox.cast());
      checkbox.setDefaultChecked(!collapsed);
      checkbox.setChecked(!collapsed);
      if (GXT.isAriaEnabled()) {
        checkbox.setTitle("Expand " + html);
      }
    } else if (!checkboxToggle && collapsible) {
      collapseBtn = new ToolButton("x-tool-toggle");
      collapseBtn.addListener(
          Events.Select,
          new Listener<ComponentEvent>() {
            public void handleEvent(ComponentEvent be) {
              setExpanded(!isExpanded());
            }
          });
      collapseBtn.render(legend.dom);
      collapseBtn.getAriaSupport().setRole("checkbox");
      if (GXT.isAriaEnabled()) {
        collapseBtn.setTitle("Expand " + html);
      }
      ComponentHelper.setParent(this, collapseBtn);
    }

    heading = DOM.createSpan();
    heading.setClassName("x-fieldset-header-text");
    legend.appendChild(heading);
    getElement().appendChild(legend.dom);

    body = el().appendChild(DOM.createDiv());

    if (html != null) {
      setHeadingHtml(html);
    }

    if (collapsed) {
      onCollapse();
    }

    updateIconTitles();

    if (GXT.isFocusManagerEnabled() && !getFocusSupport().isIgnore()) {
      el().setTabIndex(0);
      el().setElementAttribute("hideFocus", "true");
      sinkEvents(Event.FOCUSEVENTS);
    }
  }
Ejemplo n.º 8
0
 @Override
 protected void onRemove(Component component) {
   super.onRemove(component);
   El elem = findItemElement(component);
   if (elem != null) {
     elem.removeFromParent();
   }
 }
Ejemplo n.º 9
0
 @Override
 protected void onComponentShow(Component component) {
   super.onComponentShow(component);
   El e = findItemElement(component);
   if (e != null) {
     e.removeStyleName(component.getHideMode().value());
   }
 }
Ejemplo n.º 10
0
 protected void onScrollerIn(El t) {
   boolean top = t.is(".x-menu-scroller-top");
   if (top
       ? ul.getScrollTop() > 0
       : ul.getScrollTop() + activeMax < ul.dom.getPropertyInt("scrollHeight")) {
     t.addStyleName("x-menu-item-active", "x-menu-scroller-active");
   }
 }
Ejemplo n.º 11
0
 private El findItemElement(Component c) {
   if (c != null && c instanceof Field<?> && c.isRendered()) {
     El elem = target.selectNode(".x-form-el-" + c.getId());
     if (elem != null) {
       return elem.findParent(".x-form-item", 5);
     }
     return null;
   }
   return null;
 }
Ejemplo n.º 12
0
  protected void onRender(Element target, int index) {
    if (template == null) {
      if (buttonTemplate == null) {
        StringBuffer sb = new StringBuffer();
        sb.append(
            "<table cellspacing=\"0\" class=\"x-btn\" role=\"presentation\"><tbody class=\"{2}\" >");
        sb.append(
            "<tr><td class=\"x-btn-tl\"><i>&#160;</i></td><td class=\"x-btn-tc\"></td><td class=\"x-btn-tr\"><i>&#160;</i></td></tr>");
        sb.append(
            "<tr><td class=\"x-btn-ml\"><i>&#160;</i></td><td class=\"x-btn-mc\"><em class=\"{3}\" unselectable=\"on\"><button class=\"x-btn-text\" type=\"{1}\">{0}</button></em></td><td class=\"x-btn-mr\"><i>&#160;</i></td></tr>");
        sb.append(
            "<tr><td class=\"x-btn-bl\"><i>&#160;</i></td><td class=\"x-btn-bc\"></td><td class=\"x-btn-br\"><i>&#160;</i></td></tr>");
        sb.append("</tbody></table>");

        buttonTemplate = new Template(sb.toString());
      }
      template = buttonTemplate;
    }

    setElement(
        template.create(
            (text != null && text.length() > 0) ? text : "&nbsp;",
            getType(),
            "x-btn-"
                + scale.name().toLowerCase()
                + " x-btn-icon-"
                + scale.name().toLowerCase()
                + "-"
                + iconAlign.name().toLowerCase(),
            getMenuClass()),
        target,
        index);

    super.onRender(target, index);

    buttonEl = el().selectNode(buttonSelector);
    buttonEl.makePositionable();

    if (getFocusEl() != null) {
      getFocusEl().addEventsSunk(Event.FOCUSEVENTS);
    }

    preview.getIgnoreList().add(getElement());

    buttonEl.setTabIndex(0);

    if (GXT.isAriaEnabled()) {
      Accessibility.setRole(buttonEl.dom, Accessibility.ROLE_BUTTON);
      if (menu != null) {
        Accessibility.setState(buttonEl.dom, "aria-haspopup", "true");
      }
    }

    sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS);
  }
Ejemplo n.º 13
0
  protected void onScroll(ClickRepeaterEvent ce) {
    El target = ce.getEl();
    boolean top = target.is(".x-menu-scroller-top");
    scrollMenu(top);

    if (top
        ? ul.getScrollTop() <= 0
        : ul.getScrollTop() + activeMax >= ul.dom.getPropertyInt("scrollHeight")) {
      onScrollerOut(target);
    }
  }
Ejemplo n.º 14
0
 protected void onClick(ComponentEvent ce) {
   ce.preventDefault();
   if (!disabled) {
     El aElement = ce.getTarget("a", 3);
     String className = aElement.getStyleName();
     if (className.indexOf("color-") != -1) {
       select(
           className.substring(className.indexOf("color-") + 6, className.indexOf("color-") + 12));
     }
   }
 }
Ejemplo n.º 15
0
 @Override
 protected int adjustHeightAnchor(int height, Component comp) {
   if (comp instanceof Field<?>) {
     Field<?> f = (Field<?>) comp;
     if (!f.isHideLabel() && labelAlign.equals(LabelAlign.TOP)) {
       El elem = findLabelElement(comp);
       if (elem != null) {
         height -= elem.getHeight();
       }
     }
   }
   return super.adjustHeightAnchor(height, comp);
 }
Ejemplo n.º 16
0
 private El getGroup(String groupName) {
   El g = el().selectNode("#" + getId() + "-" + groupName);
   if (g == null) {
     g = new El(DOM.createDiv());
     g.makePositionable(true);
     g.dom.setAttribute("role", "group");
     g.addStyleName(HideMode.OFFSETS.value());
     g.addStyleName("x-menu-radio-group");
     g.setId(getId() + "-" + groupName);
     el().appendChild(g.dom);
   }
   return g;
 }
Ejemplo n.º 17
0
 protected void autoWidth() {
   if (rendered && isAutoWidth()) {
     setWidth("auto");
     if (GXT.isIE) {
       if (textEl != null) {
         textEl.clip();
         TextMetrics.get().bind(textEl.dom);
         int adj = iconStyle != null ? 25 : 0;
         int w = TextMetrics.get().getWidth(text) + adj + 5;
         textEl.setWidth(w, true);
       }
     }
   }
 }
Ejemplo n.º 18
0
 /**
  * Sets the item's icon.
  *
  * @param icon the icon
  */
 public void setIcon(AbstractImagePrototype icon) {
   this.icon = icon;
   if (rendered) {
     El node = el().selectNode(".x-tab-image");
     if (node != null) {
       node.remove();
     }
     if (icon != null) {
       Element e = icon.createElement().cast();
       e.setClassName("x-tab-image");
       el().appendChild(e);
     }
     el().setStyleName("x-tab-with-icon", icon != null);
   }
 }
Ejemplo n.º 19
0
  @Override
  protected void onRender(Element target, int index) {
    setElement(DOM.createDiv(), target, index);
    el().makePositionable(true);
    super.onRender(target, index);

    ul = new El(DOM.createDiv());
    ul.addStyleName(baseStyle + "-list");

    getElement().appendChild(ul.dom);

    // add menu to ignore list
    eventPreview.getIgnoreList().add(getElement());

    el().setTabIndex(0);
    el().setElementAttribute("hideFocus", "true");

    el().addStyleName("x-ignore");
    if (GXT.isAriaEnabled()) {
      Accessibility.setRole(getElement(), "menu");
      Accessibility.setRole(ul.dom, "presentation");
      handleRadioGroups();
    }

    if (plain) {
      addStyleName("x-menu-plain");
    }
    if (!showSeparator) {
      addStyleName("x-menu-nosep");
    }

    sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.KEYEVENTS | Event.ONMOUSEWHEEL);
  }
Ejemplo n.º 20
0
 protected Element getTextCellElement(int column) {
   if (column == 0) {
     return textSpanEl;
   } else {
     return El.fly(cells[column]).getSubChild(2);
   }
 }
Ejemplo n.º 21
0
  protected void updateCellValues(int col, Element cell, HorizontalAlignment align) {
    String salign;
    switch (align) {
      case START:
        {
          if (LocaleInfo.getCurrentLocale().isRTL()) salign = "right";
          else salign = "left";
          break;
        }
      case END:
        {
          if (LocaleInfo.getCurrentLocale().isRTL()) salign = "left";
          else salign = "right";
          break;
        }
      default:
        salign = align.name().toLowerCase();
    }

    String widthClassName = ((TreeTableItem) item).treeTable.getId() + "-col-" + col;

    String className = cell.getClassName();
    className = (className == null) ? widthClassName : className + " " + widthClassName;
    cell.setClassName(className);

    className = DOM.getElementProperty(DOM.getFirstChild(cell), "className");
    className = (className == null) ? widthClassName : className + " " + widthClassName;
    DOM.setElementProperty(DOM.getFirstChild(cell), "className", className);

    El.fly(cell).subChild(2).setStyleAttribute("textAlign", salign);
  }
Ejemplo n.º 22
0
 protected void clearGroups() {
   NodeList<Element> groups = el().select(".x-menu-radio-group");
   for (int i = 0; i < groups.getLength(); i++) {
     Element e = groups.getItem(i);
     El.fly(e).removeFromParent();
   }
 }
Ejemplo n.º 23
0
 /**
  * Sets the icon style.
  *
  * @param iconStyle the CSS style name
  */
 public void setIconStyle(String iconStyle) {
   if (this.iconStyle != iconStyle) {
     if (rendered) {
       if (this.iconStyle != null) {
         textEl.removeStyleName("x-status-icon");
         textEl.removeStyleName(this.iconStyle);
       }
       if (iconStyle != null) {
         textEl.addStyleName("x-status-icon");
         textEl.addStyleName(iconStyle);
       }
       autoWidth();
     }
     this.iconStyle = iconStyle;
   }
 }
Ejemplo n.º 24
0
  protected void constrainScroll(int y) {
    int full = ul.setHeight("auto").getHeight();

    int max = maxHeight != Style.DEFAULT ? maxHeight : (XDOM.getViewHeight(false) - y);
    if (full > max && max > 0) {
      activeMax = max - 10 - scrollerHeight * 2;
      ul.setHeight(activeMax, true);
      createScrollers();
    } else {
      ul.setHeight(full, true);
      NodeList<Element> nodes = el().select(".x-menu-scroller");
      for (int i = 0; i < nodes.getLength(); i++) {
        fly(nodes.getItem(i)).hide();
      }
    }
    ul.setScrollTop(0);
  }
Ejemplo n.º 25
0
 protected void autoWidth() {
   if (rendered && width == null) {
     setWidth("auto");
     if (GXT.isIE7 && GXT.isStrict) {
       if (buttonEl != null && buttonEl.getWidth() > 20) {
         buttonEl.clip();
         TextMetrics.get().bind(buttonEl.dom);
         buttonEl.setWidth(TextMetrics.get().getWidth(text) + buttonEl.getFrameWidth("lr"), true);
       }
     }
     if (minWidth != Style.DEFAULT) {
       if (getWidth() < minWidth) {
         setWidth(minWidth);
       }
     }
   }
 }
Ejemplo n.º 26
0
 @Override
 public void onSelectedChange(boolean selected) {
   if (item.isRendered()) {
     El.fly(tableItemEl).setStyleName("my-treetbl-item-sel", selected);
     if (!selected) {
       onMouseOut(null);
     }
   }
 }
Ejemplo n.º 27
0
 /**
  * Sets the text.
  *
  * @param text the text
  */
 public void setText(String text) {
   if (this.text != text) {
     this.text = text;
     if (rendered) {
       textEl.update((text == null || text.length() == 0) ? "&nbsp;" : text);
       autoWidth();
     }
   }
 }
Ejemplo n.º 28
0
 @Override
 protected void onFocus(ComponentEvent ce) {
   super.onFocus(ce);
   if (GXT.isFocusManagerEnabled()) {
     if (focusWidget != null) {
       El.fly(focusWidget.getElement()).focus();
     }
   }
 }
Ejemplo n.º 29
0
 private void resizeLiveScroller() {
   int h = grid.getHeight(true) - mainHd.getHeight(true);
   if (isHorizontalScrollBarShowing()) {
     h -= XDOM.getScrollBarWidth();
   }
   if (footer != null) {
     h -= footer.getHeight();
   }
   liveScroller.setHeight(h, true);
 }
Ejemplo n.º 30
0
 /**
  * Sets the button's text.
  *
  * @param text the new text
  */
 public void setText(String text) {
   this.text = text;
   if (rendered) {
     if (text != null && text.equals("")) {
       text = "&nbsp;";
     }
     buttonEl.update(text);
     autoWidth();
   }
 }