protected Widget getContent(AssetContentItem contentItem) {
   // Add the content
   HTML contentHTML = new HTML(contentItem.getContent());
   // So that lightbox centering in firefox works, enclose each sized <object>
   // with a div styled to exactly that size.
   NodeList<Element> objectElements = contentHTML.getElement().getElementsByTagName("object");
   Document document = Document.get();
   for (int i = 0, len = objectElements.getLength(); i < len; i++) {
     Element objectElement = objectElements.getItem(i);
     String width = objectElement.getAttribute("width");
     String height = objectElement.getAttribute("height");
     if (width.matches("[0-9]+%?") && height.matches("[0-9]+%?")) {
       DivElement div = document.createDivElement();
       div.getStyle().setProperty("width", width + (width.endsWith("%") ? "" : "px"));
       div.getStyle().setProperty("height", height + (height.endsWith("%") ? "" : "px"));
       objectElement.getParentElement().replaceChild(div, objectElement);
       div.appendChild(objectElement);
     }
   }
   // In case there are images within the content, we should fire a PopupImageLoadedEvent
   // so that any popup window displaying this view has a chance to reposition itself.
   NodeList<Element> imageElements = contentHTML.getElement().getElementsByTagName("img");
   for (int i = 0; i < imageElements.getLength(); i++) {
     ImageElement image = imageElements.getItem(i).cast();
     addImageLoadHandler(image);
   }
   return contentHTML;
 }
Esempio n. 2
0
  public boolean hasAttribute(String key) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    NodeList<Node> childNodes = attributesNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Element node = (Element) childNodes.getItem(i);
      if (node.hasAttribute("name") && node.getAttribute("name").equals(key)) {
        return true;
      }
    }

    return false;
  }
Esempio n. 3
0
  public String getAttribute(String key) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    NodeList<Node> childNodes = attributesNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Element node = (Element) childNodes.getItem(i);
      if (node.hasAttribute("name") && node.getAttribute("name").equals(key)) {
        return node.getAttribute("value");
      }
    }

    throw new RuntimeException("TaggedEntity does not have attribute '" + key + "'");
  }
Esempio n. 4
0
  private void setDefaultValues() {
    clickTestAction =
        new Function() {
          @Override
          public boolean f(Event e) {
            return testActiveClick(e);
          }
        };

    activateAction =
        new Function() {
          @Override
          public boolean f(Event e) {
            return activateField(e);
          }
        };

    activeField = false;
    mouseOnContainer = false;
    resultsShowing = false;

    NodeList<OptionElement> optionsList = selectElement.getOptions();
    allowSingleDeselect =
        options.isAllowSingleDeselect()
            && optionsList.getLength() > 0
            && "".equals(optionsList.getItem(0).getText());

    choices = 0;

    css = Resources.INSTANCE.css();
  }
 /**
  * Converts a node list to an element array.
  *
  * @param nodes the nodes
  * @return the element array
  */
 public static Element[] toElementArray(NodeList<Element> nodes) {
   Element[] e = new Element[nodes.getLength()];
   for (int i = 0; i < nodes.getLength(); i++) {
     e[i] = nodes.getItem(i);
   }
   return e;
 }
Esempio n. 6
0
  private void initPostion() {
    if (pns == null) {
      pns = new ArrayList<PositionNav>();
    }
    NodeList<Node> nodes = content.getChildNodes();
    for (int i = 1; i < nodes.getLength(); i = i + 2) {
      Element elm = nodes.getItem(i).<Element>cast();

      final int absoluteTop = elm.getAbsoluteTop() - OFFSET;

      LIElement li = Document.get().createLIElement().cast();
      li.setInnerHTML(elm.getId());
      EventGenerator.onClick(
          li,
          new Function() {
            @Override
            public void f(Event e) {
              root.getElement().setScrollTop(absoluteTop);
            }
          });
      ul.appendChild(li);

      pns.add(new PositionNav(absoluteTop, li));
    }
    currentli = pns.get(0).getElm();
    currentli.addClassName(style.active());
  }
Esempio n. 7
0
 /**
  * Img elements needs some special handling in custom layout. Img elements will get their onload
  * events sunk. This way custom layout can notify parent about possible size change.
  */
 private void initImgElements() {
   NodeList<Element> nodeList = getElement().getElementsByTagName("IMG");
   for (int i = 0; i < nodeList.getLength(); i++) {
     ImageElement img = ImageElement.as(nodeList.getItem(i));
     DOM.sinkEvents(img, Event.ONLOAD);
   }
 }
Esempio n. 8
0
 public static <T extends Node> ArrayList<T> fromNodeList(NodeList<T> childNodes) {
   ArrayList<T> res = new ArrayList<T>();
   for (int i = 0; i < childNodes.getLength(); i++) {
     res.add(childNodes.getItem(i));
   }
   return res;
 }
Esempio n. 9
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();
   }
 }
Esempio n. 10
0
 /**
  * Try to identify the embedded range elements input field (see ui xml)
  *
  * @return The found element or null if none found.
  */
 private Element getRangeElement() {
   if (rangeElement == null) {
     NodeList<Element> elements = this.getElement().getElementsByTagName(INPUT);
     if (elements != null && elements.getLength() > 0) {
       rangeElement = elements.getItem(0);
     }
   }
   return rangeElement;
 }
Esempio n. 11
0
  public void removeTopRows(int rowCount) {
    if (rowCount <= 0) return;

    NodeList<TableSectionElement> tBodies = table_.getTBodies();
    for (int i = 0; i < tBodies.getLength(); i++) {
      rowCount = removeTopRows(tBodies.getItem(i), rowCount);
      if (rowCount == 0) return;
    }
  }
 private static void getDescendantNodes(
     JsNodeArray matchingElms, String nextTagStr, Node prevRef) {
   NodeList<Element> children = getElementsByTagName(nextTagStr, prevRef);
   for (int k = 0, klen = children.getLength(); k < klen; k++) {
     Node child = children.getItem(k);
     if (child.getParentNode() == prevRef) {
       matchingElms.addNode(child);
     }
   }
 }
Esempio n. 13
0
  @Override
  protected NodeList<Element> getRows() {
    if (!enableGrouping) {
      return super.getRows();
    }
    if (!hasRows()) {
      return new JsArray().getJsObject().cast();
    }

    NodeList<Element> gs = getGroups();
    JsArray rows = new JsArray();
    for (int i = 0, len = gs.getLength(); i < len; i++) {
      NodeList<Element> g = gs.getItem(i).getChildNodes().getItem(1).getChildNodes().cast();
      for (int j = 0, len2 = g.getLength(); j < len2; j++) {
        rows.add(g.getItem(j));
      }
    }
    return rows.getJsObject().cast();
  }
Esempio n. 14
0
  @Ignore
  @Test
  public void checkParse() throws Exception {
    // Setup
    String html =
        "<div id=\"parent0\"></div><div id=\"parent1\"><div id=\"child0\"><span class=\"spanClass\" >test</span></div><BR><DIV id=\"child2\" style=\"color:red; font-style:italic; font-weight:bold; font-family:Arial\"></div>";

    // Test
    NodeList<Node> nodes = GwtHtmlParser.parse(html);

    // Assert
    Assert.assertEquals(2, nodes.getLength());
    DivElement parent0 = (DivElement) nodes.getItem(0);
    Assert.assertEquals("parent0", parent0.getId());
    Assert.assertEquals(0, parent0.getChildCount());

    DivElement parent1 = (DivElement) nodes.getItem(1);
    Assert.assertEquals("parent1", parent1.getId());
    Assert.assertEquals(3, parent1.getChildCount());

    DivElement child0 = (DivElement) parent1.getChild(0);
    Assert.assertEquals("child0", child0.getId());
    Assert.assertEquals(1, child0.getChildCount());

    SpanElement span = (SpanElement) child0.getChild(0);
    Assert.assertEquals("", span.getId());
    Assert.assertEquals("spanClass", span.getClassName());
    Assert.assertEquals(1, span.getChildCount());
    Assert.assertEquals(Node.TEXT_NODE, span.getChild(0).getNodeType());
    Text text = span.getChild(0).cast();
    Assert.assertEquals("test", text.getData());
    Assert.assertEquals("test", span.getInnerText());

    BRElement br = (BRElement) parent1.getChild(1);
    Assert.assertEquals("", br.getId());

    DivElement child2 = (DivElement) parent1.getChild(2);
    Assert.assertEquals("child2", child2.getId());
    Assert.assertEquals(0, child2.getChildCount());
    Style style = child2.getStyle();
    Assert.assertEquals("red", style.getColor());
  }
Esempio n. 15
0
  /**
   * Adds a new key-value attribute pair or changes an existing one.
   *
   * @param key
   * @param value
   */
  public void setAttribute(String key, String value) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    NodeList<Node> childNodes = attributesNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Element node = (Element) childNodes.getItem(i);
      if (node.hasAttribute("name") && node.getAttribute("name").equals(key)) {
        node.setAttribute("value", value);
        return;
      }
    }

    /* if you get here, the rootElement wasn't found */
    Element element = JSFunctions.createPlainElement("attribute");
    element.setAttribute("name", key);
    element.setAttribute("value", value);
    attributesNode.insertAfter(element, attributesNode.getLastChild());
  }
Esempio n. 16
0
 private void updateGroupWidths() {
   if (!enableGrouping || ds.getCount() < 1) {
     return;
   }
   String tw = Math.max(cm.getTotalWidth(), el.dom.getOffsetWidth() - getScrollAdjust()) + "px";
   NodeList<Element> gs = getGroups();
   for (int i = 0, len = gs.getLength(); i < len; i++) {
     Element e = gs.getItem(i).getFirstChild().cast();
     e.getStyle().setProperty("width", tw);
   }
 }
  @PatchMethod
  static TableRowElement insertRow(TableElement e, int index) {
    NodeList<TableRowElement> rows = e.getRows();
    TableRowElement newRow = Document.get().createTRElement();
    if (rows.getLength() < 1) {
      TableSectionElement tbody = Document.get().createTBodyElement();
      e.appendChild(tbody);
      tbody.appendChild(newRow);
    } else {

      if (index == -1 || index >= rows.getLength()) {
        TableRowElement after = rows.getItem(rows.getLength() - 1);
        after.getParentElement().insertAfter(newRow, after);
      } else {
        TableRowElement before = rows.getItem(index);
        before.getParentElement().insertBefore(newRow, before);
      }
    }

    return newRow;
  }
Esempio n. 18
0
  @PatchMethod
  static void setInnerHTML(Element element, String html) {
    List<Node> innerList =
        JavaScriptObjects.getObject(element.getChildNodes(), JsoProperties.NODE_LIST_INNER_LIST);
    innerList.clear();

    NodeList<Node> nodes = GwtHtmlParser.parse(html);

    for (int i = 0; i < nodes.getLength(); i++) {
      innerList.add(nodes.getItem(i));
    }
  }
Esempio n. 19
0
  private Element getElementByTagAndClassName(String tagName, String className) {
    NodeList<Element> elements = getElement().getElementsByTagName(tagName);

    for (int i = 0; i < elements.getLength(); i++) {
      Element element = elements.getItem(i);
      if (element.getClassName().contains(className)) {
        return element;
      }
    }

    return null;
  }
Esempio n. 20
0
 /** Improves splitter visibility. */
 private void tuneSplitter() {
   NodeList<Node> nodes = splitLayoutPanel.getElement().getChildNodes();
   for (int i = 0; i < nodes.getLength(); i++) {
     Node node = nodes.getItem(i);
     if (node.hasChildNodes()) {
       com.google.gwt.dom.client.Element el = node.getFirstChild().cast();
       if ("gwt-SplitLayoutPanel-HDragger".equals(el.getClassName())) {
         tuneSplitter(el);
         return;
       }
     }
   }
 }
Esempio n. 21
0
  @Test
  public void checkGetElementByTagName() {
    // Setup
    AnchorElement a1 = Document.get().createAnchorElement();
    AnchorElement a2 = Document.get().createAnchorElement();
    AnchorElement a3 = Document.get().createAnchorElement();
    DivElement d1 = Document.get().createDivElement();
    d.appendChild(a1);
    d.appendChild(a1);
    d.appendChild(a2);
    a2.appendChild(a3);
    d.appendChild(d1);

    // Test
    NodeList<Element> nodes = d.getElementsByTagName("a");

    // Assert
    Assert.assertEquals(3, nodes.getLength());
    Assert.assertEquals(a1, nodes.getItem(0));
    Assert.assertEquals(a2, nodes.getItem(1));
    Assert.assertEquals(a3, nodes.getItem(2));
  }
Esempio n. 22
0
  @Test
  public void html_withAnchor() {
    // Arrange
    HTML widget = new HTML("<a href=\"foo\" target=\"bar\">baz</a>");

    // Act
    NodeList<Element> nodeList = widget.getElement().getElementsByTagName("a");

    // Assert
    assertEquals(1, nodeList.getLength());
    AnchorElement anchor = nodeList.getItem(0).cast();
    assertEquals("foo", anchor.getHref());
    assertEquals("bar", anchor.getTarget());
  }
  @PatchMethod
  static void deleteRow(TableElement e, int index) {
    NodeList<TableRowElement> rows = e.getRows();

    if (rows.getLength() < 1) {
      return;
    }

    if (index == -1) {
      index = rows.getLength() - 1;
    }

    TableRowElement rowToDelete = rows.getItem(index);
    e.removeChild(rowToDelete);
  }
Esempio n. 24
0
  public void setAttributes(HashMap<String, String> map) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);
    attributesNode.removeAllChildren();

    Node last = null;

    for (String key : map.keySet()) {
      Element element = JSFunctions.createTextElement("attribute", "");
      element.setAttribute("name", key);
      element.setAttribute("value", map.get(key));
      last = attributesNode.insertAfter(element, last);
    }
  }
Esempio n. 25
0
  /**
   * Returns a mutable map which is not bound to the TaggedEntity; any changes made in the map will
   * not be reflected in the tagName.
   *
   * @return mutable unbound map
   */
  public HashMap<String, String> getAttributes() {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    HashMap<String, String> rvalue = new HashMap<>();
    for (int i = 0; i < attributesNode.getChildCount(); i++) {
      final Node node = attributesNode.getChild(i);
      JsArray<Node> attributeList = getAttributes((Element) node);
      String name = attributeList.get(0).getNodeValue();
      String value = attributeList.get(1).getNodeValue();
      rvalue.put(name, value);
    }

    return rvalue;
  }
Esempio n. 26
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);
  }
  /**
   * Specific function which does not inspect deep.
   *
   * @param tag
   * @return
   */
  private static NodeList<Element> getElementByTagName(TableElement e, String tagName) {

    NodeList<Node> childs = e.getChildNodes();
    List<Element> list = new ArrayList<Element>();

    for (int i = 0; i < childs.getLength(); i++) {
      Node n = childs.getItem(i);
      if (Element.is(n)) {
        Element childElement = n.cast();
        if (tagName.equalsIgnoreCase(childElement.getTagName())) {
          list.add(childElement);
        }
      }
    }

    return JavaScriptObjects.newNodeList(list);
  }
Esempio n. 28
0
  /** {@inheritDoc} */
  @Override
  public void showLocationDetails(
      final String name, final String htmlTitle, final String htmlContent) {
    final MQAPoi point = getMarker(name);
    if (point != null) {
      point.setInfoTitleHTML(htmlTitle);
      point.setInfoContentHTML(htmlContent);
      point.showInfoWindow();

      final NodeList<Element> elements = Document.get().getElementsByTagName("div");
      for (int i = 0; i < elements.getLength(); i++) {
        final Element e = elements.getItem(i);
        if (e.getClassName().equals("mqpoicontenttext")) {
          final Style s = e.getStyle();
          s.setOverflow(Overflow.HIDDEN);
          break;
        }
      }
    }
  }
Esempio n. 29
0
 /**
  * Returns an XPath expression which enables reaching the specified node from the root node
  *
  * @param node The node to reach
  * @param root The root node, or null to specify the document root
  * @return An XPath expression which enables reaching the specified node from the root node
  */
 public static String getXPath(Node node, Node root) {
   StringBuilder builder = new StringBuilder();
   Node parentNode;
   while ((node != root) && (parentNode = node.getParentNode()) != null) {
     NodeList<Node> siblings = parentNode.getChildNodes();
     int index = 0;
     for (int i = 0, length = siblings.getLength(); i < length; i++) {
       Node sibling = siblings.getItem(i);
       if (sibling.getNodeType() == Node.ELEMENT_NODE) {
         index++;
         if (node == sibling) {
           builder.insert(0, "/*[" + index + "]");
           break;
         }
       }
     }
     node = parentNode;
   }
   return builder.toString();
 }
Esempio n. 30
0
  public boolean moveSelectionDown() {
    if (selectedRows_.size() == 0) return false;

    sortSelectedRows();
    int bottom = selectedRows_.get(selectedRows_.size() - 1).getRowIndex();

    NodeList<TableRowElement> rows = table_.getRows();
    TableRowElement rowToSelect = null;
    while (++bottom < rows.getLength()) {
      TableRowElement row = rows.getItem(bottom);
      if (codec_.isValueRow(row)) {
        rowToSelect = row;
        break;
      }
    }
    if (rowToSelect == null) return false;

    clearSelection();
    setSelected(rowToSelect, true);
    return true;
  }