Пример #1
0
  public static void addClassName(String className, Element element) {
    assert (className != null) : "Unexpectedly null class name";

    className = className.trim();
    assert (className.length() != 0) : "Unexpectedly empty class name";

    // Get the current style string.
    String oldClassName = element.getClassName();
    int idx = oldClassName.indexOf(className);

    // Calculate matching index.
    while (idx != -1) {
      if (idx == 0 || oldClassName.charAt(idx - 1) == ' ') {
        int last = idx + className.length();
        int lastPos = oldClassName.length();
        if ((last == lastPos) || ((last < lastPos) && (oldClassName.charAt(last) == ' '))) {
          break;
        }
      }
      idx = oldClassName.indexOf(className, idx + 1);
    }

    // Only add the style if it's not already present.
    if (idx == -1) {
      if (oldClassName.length() > 0) {
        oldClassName += " ";
      }
      element.setClassName(oldClassName + className);
    }
  }
Пример #2
0
  private void renderParameters(
      Element parent, SignatureInfo signatureInfo, Optional<Integer> activeParameter) {
    int end = signatureInfo.getLabel().length();
    int idx;
    Element element;
    for (int i = signatureInfo.getParameters().get().size() - 1; i >= 0; i--) {
      ParameterInfo parameterInfo = signatureInfo.getParameters().get().get(i);
      idx = signatureInfo.getLabel().lastIndexOf(parameterInfo.getLabel(), end);
      int signatureLabelOffset = 0;
      int signatureLabelEnd = 0;
      if (idx >= 0) {
        signatureLabelOffset = idx;
        signatureLabelEnd = idx + parameterInfo.getLabel().length();
      }

      element = Elements.createSpanElement();
      element.setTextContent(signatureInfo.getLabel().substring(signatureLabelEnd, end));
      parent.insertBefore(element, parent.getFirstElementChild());

      element = Elements.createSpanElement(resources.css().parameter());
      if (activeParameter.isPresent() && i == activeParameter.get()) {
        Elements.addClassName(resources.css().active(), element);
      }
      element.setTextContent(
          signatureInfo.getLabel().substring(signatureLabelOffset, signatureLabelEnd));
      parent.insertBefore(element, parent.getFirstElementChild());
      end = signatureLabelOffset;
    }
    element = Elements.createSpanElement();
    element.setTextContent(signatureInfo.getLabel().substring(0, end));
    parent.insertBefore(element, parent.getFirstElementChild());
  }
Пример #3
0
  private void renderDocumentation(
      Element element, SignatureInfo signatureInfo, Optional<Integer> activeParameter) {
    if (signatureInfo.getDocumentation().isPresent()) {
      elemental.html.DivElement documentation =
          Elements.createDivElement(resources.css().documentation());
      documentation.setTextContent(signatureInfo.getDocumentation().get());
      element.appendChild(documentation);
    }

    if (signatureInfo.getParameters().isPresent()
        && activeParameter.isPresent()
        && signatureInfo.getParameters().get().size() > activeParameter.get()) {
      ParameterInfo parameterInfo = signatureInfo.getParameters().get().get(activeParameter.get());
      if (parameterInfo.getDocumentation().isPresent()) {
        elemental.html.DivElement parameter =
            Elements.createDivElement(resources.css().documentationParameter());
        SpanElement label = Elements.createSpanElement(resources.css().documentationParameter());
        label.setTextContent(parameterInfo.getLabel());

        SpanElement documentation = Elements.createSpanElement(resources.css().documentation());
        documentation.setTextContent(parameterInfo.getDocumentation().get());

        parameter.appendChild(label);
        parameter.appendChild(documentation);
        element.appendChild(parameter);
      }
    }
  }
Пример #4
0
  public HomepageSection(
      final String token, final String header, final String intro, final String... steps) {
    // @formatter:off
    Elements.Builder builder =
        new Elements.Builder()
            .div()
            .div()
            .css("eap-toggle-controls")
            .a()
            .css("clickable")
            .rememberAs("toggle")
            .start("i")
            .css("icon-angle-down")
            .rememberAs("icon")
            .end()
            .span()
            .textContent(" " + header)
            .end()
            .end()
            .a()
            .attr("href", "#" + token)
            .span()
            .textContent("Start ")
            .end()
            .start("i")
            .css("icon-circle-arrow-right")
            .end()
            .end()
            .end()
            .div()
            .css("eap-toggle-container")
            .rememberAs("body")
            .p()
            .textContent(intro)
            .end()
            .ol()
            .rememberAs("steps")
            .end()
            .end()
            .end();
    // @formatter:on
    wireToggle(builder.referenceFor("toggle"));

    Document document = Browser.getDocument();
    Element ol = builder.referenceFor("steps");
    for (String step : steps) {
      Element li = document.createLIElement();
      li.setInnerHTML(step);
      ol.appendChild(li);
    }

    this.icon = builder.referenceFor("icon");
    this.body = builder.referenceFor("body");
    this.root = builder.build();
    this.collapsed = false;
  }
Пример #5
0
 public void toggle() {
   if (collapsed) {
     Elements.setVisible(body, true);
     icon.getClassList().remove("icon-angle-right");
     icon.getClassList().add("icon-angle-down");
   } else {
     Elements.setVisible(body, false);
     icon.getClassList().remove("icon-angle-down");
     icon.getClassList().add("icon-angle-right");
   }
   this.collapsed = !collapsed;
 }
Пример #6
0
 // TODO: Long term we need a markdown engine :)
 public static void markup(Element e, String text, String linkCssClass) {
   e.setInnerHTML("");
   List<String> paragraphs = StringUtils.split(text, "\n\n");
   for (String paragraph : paragraphs) {
     markupParagraph(e, paragraph, linkCssClass);
   }
 }
Пример #7
0
  private void select(int position) {
    Pair<Integer, Integer> signaturePosition = signatureViews.get(position);
    if (signaturePosition == null) {
      return;
    }

    signatures.getStyle().setHeight(signaturePosition.second + "px");
    signatures.setScrollTop(signaturePosition.first);
    String overloads = "" + (position + 1);
    if (signatureViews.size() < 10) {
      overloads += ("/" + signatureViews.size());
    }

    this.overloads.setInnerText(overloads);
    setPopupPosition(x, y - getElement().getOffsetHeight());
  }
Пример #8
0
 @Override
 public void remove() {
   if (index == 0) {
     throw new IllegalStateException();
   }
   index--;
   parent.removeChild(children.item(index));
   size = children.getLength();
 }
Пример #9
0
 public static boolean hasClassName(String className, Element element) {
   assert className != null : "Unexpected null class name";
   String currentClassName = element.getClassName();
   return (currentClassName != null)
       && (currentClassName.equals(className)
           || currentClassName.startsWith(className + " ")
           || currentClassName.endsWith(" " + className)
           || currentClassName.indexOf(" " + className + " ") != -1);
 }
Пример #10
0
  private Element renderSignature(
      Element signatures, SignatureInfo signatureInfo, Optional<Integer> activeParameter) {
    Element signatureElement = Elements.createDivElement();
    signatures.appendChild(signatureElement);

    Element code = Elements.createDivElement();
    signatureElement.appendChild(code);
    boolean hasParameters =
        signatureInfo.getParameters().isPresent() && !signatureInfo.getParameters().get().isEmpty();

    if (hasParameters) {
      renderParameters(code, signatureInfo, activeParameter);
    } else {
      Node label = code.appendChild(Elements.createSpanElement());
      label.setTextContent(signatureInfo.getLabel());
    }

    return signatureElement;
  }
Пример #11
0
  public static void removeClassName(String className, Element element) {
    assert (className != null) : "Unexpectedly null class name";

    className = className.trim();
    assert (className.length() != 0) : "Unexpectedly empty class name";

    // Get the current style string.
    String oldStyle = element.getClassName();
    int idx = oldStyle.indexOf(className);

    // Calculate matching index.
    while (idx != -1) {
      if (idx == 0 || oldStyle.charAt(idx - 1) == ' ') {
        int last = idx + className.length();
        int lastPos = oldStyle.length();
        if ((last == lastPos) || ((last < lastPos) && (oldStyle.charAt(last) == ' '))) {
          break;
        }
      }
      idx = oldStyle.indexOf(className, idx + 1);
    }

    // Don't try to remove the style if it's not there.
    if (idx != -1) {
      // Get the leading and trailing parts, without the removed name.
      String begin = oldStyle.substring(0, idx).trim();
      String end = oldStyle.substring(idx + className.length()).trim();

      // Some contortions to make sure we don't leave extra spaces.
      String newClassName;
      if (begin.length() == 0) {
        newClassName = end;
      } else if (end.length() == 0) {
        newClassName = begin;
      } else {
        newClassName = begin + " " + end;
      }

      element.setClassName(newClassName);
    }
  }
Пример #12
0
  private void render() {
    if (signatureHelp.getSignatures().size() > 1) {
      Elements.addClassName(resources.css().multiple(), rootElement);
      overloads.getStyle().setDisplay("block");
    } else {
      Elements.removeClassName(resources.css().multiple(), rootElement);
      overloads.getStyle().setDisplay("none");
    }

    signatures.setInnerHTML("");
    signatureViews = new ArrayList<>();
    int height = 0;
    for (SignatureInfo signatureInfo : signatureHelp.getSignatures()) {
      Element signatureElement =
          renderSignature(signatures, signatureInfo, signatureHelp.getActiveParameter());
      renderDocumentation(signatureElement, signatureInfo, signatureHelp.getActiveParameter());

      int signatureHeight = signatureElement.getOffsetHeight();
      signatureViews.add(Pair.of(height, signatureHeight));
      height += signatureHeight;
    }
  }
Пример #13
0
  /** Creates a paragraph tag and fills it with spans and anchor tags internally. */
  private static void markupParagraph(Element parent, String text, String linkCssClass) {
    if (StringUtils.isNullOrWhitespace(text)) {
      // don't add any dom here
      return;
    }

    ParagraphElement myParagraph = createParagraphElement();
    int index = 0;
    REGEXP_MARKUP.setLastIndex(0);

    SpanElement current = createSpanElement();
    for (MatchResult match = REGEXP_MARKUP.exec(text);
        match != null;
        match = REGEXP_MARKUP.exec(text)) {
      current.setTextContent(text.substring(index, match.getIndex()));
      myParagraph.appendChild(current);
      current = createSpanElement();

      /*
       * If our match is a \n we need to create a <br/> element to force a line break, otherwise we
       * matched an http/www link so let's make an anchor tag out of it.
       */
      if (match.getGroup(0).equals("\n")) {
        myParagraph.appendChild(createBRElement());
      } else {
        AnchorElement anchor = createAnchorElement(linkCssClass);
        anchor.setHref(match.getGroup(0));
        anchor.setTarget("_blank");
        anchor.setTextContent(match.getGroup(0));
        myParagraph.appendChild(anchor);
      }

      index = match.getIndex() + match.getGroup(0).length();
    }
    current.setTextContent(text.substring(index));
    myParagraph.appendChild(current);
    parent.appendChild(myParagraph);
  }
Пример #14
0
 static PolymerElement newButton(String text) {
   Element icon = newElement("paper-button");
   icon.setInnerText(text);
   icon.setClassName("xapi-button");
   return (PolymerElement) icon;
 }
Пример #15
0
  @Inject
  public SignatureHelpView(SignatureHelpResources resources) {
    super(true);
    this.resources = resources;
    rootElement =
        Elements.createDivElement(resources.css().main(), resources.css().parameterHintsWidget());
    Element wrapper = Elements.createDivElement(resources.css().wrapper());
    rootElement.appendChild(wrapper);
    Element buttons = Elements.createDivElement(resources.css().buttons());
    wrapper.appendChild(buttons);
    Element previous =
        Elements.createDivElement(resources.css().button(), resources.css().previous());
    previous.appendChild((Node) resources.arrow().getSvg().getElement());
    buttons.appendChild(previous);
    previous.addEventListener(
        elemental.events.Event.CLICK,
        new EventListener() {
          @Override
          public void handleEvent(elemental.events.Event evt) {
            previous();
          }
        },
        true);

    Element next = Elements.createDivElement(resources.css().button(), resources.css().next());
    next.appendChild((Node) resources.arrow().getSvg().getElement());
    next.addEventListener(
        elemental.events.Event.CLICK,
        new EventListener() {
          @Override
          public void handleEvent(elemental.events.Event evt) {
            next();
          }
        },
        true);

    buttons.appendChild(next);

    overloads = Elements.createDivElement(resources.css().overloads());
    wrapper.appendChild(overloads);

    signatures = Elements.createDivElement(resources.css().signatures());
    wrapper.appendChild(signatures);

    Widget widget = new ElementWidget((com.google.gwt.dom.client.Element) rootElement);

    setWidget(widget);
  }
Пример #16
0
 public ChildrenIterator(final Element parent) {
   this.parent = parent;
   this.children = parent.getChildren();
   this.size = children.getLength();
   this.index = 0;
 }
Пример #17
0
 /** Replaces the contents of a container with the given contents. */
 public static void replaceContents(Element container, Element contents) {
   container.setInnerHTML("");
   container.appendChild(contents);
 }
Пример #18
0
 public static void injectJs(String js) {
   Element scriptElem = createElement("script");
   scriptElem.setAttribute("language", "javascript");
   scriptElem.setTextContent(js);
   getBody().appendChild(scriptElem);
 }
Пример #19
0
 static PolymerElement newIcon(String iconName) {
   Element icon = newElement("core-icon");
   icon.setAttribute("icon", iconName);
   return (PolymerElement) icon;
 }
Пример #20
0
 static Element newIconButtonFloating(String iconName) {
   Element icon = newElement("paper-fab");
   icon.setAttribute("icon", iconName);
   return icon;
 }