Esempio n. 1
0
 protected void runTest(final Method m) {
   final String id = m.getName() + m.getDeclaringClass().hashCode();
   final com.google.gwt.dom.client.Element el = Document.get().getElementById(id);
   el.setInnerHTML("");
   final Map<Method, Boolean> results = testResults.get(m.getDeclaringClass());
   try {
     JUnit4Executor.runTest(tests.get(m), m);
     results.put(m, true);
     debug(el, "<div style='color:green'>" + m.getName() + " passes!</div>", null);
   } catch (Throwable e) {
     results.put(m, false);
     final String error = m.getDeclaringClass().getName() + "." + m.getName() + " failed";
     while (e.getClass() == RuntimeException.class && e.getCause() != null) {
       e = e.getCause();
     }
     debug(el, error, e);
     try {
       // Move the element up to the top of the results list.
       final com.google.gwt.dom.client.Element result = el.getParentElement();
       final com.google.gwt.dom.client.Element parent = result.getParentElement();
       parent.insertAfter(result, parent.getChild(2));
     } catch (final Exception ignored) {
     }
     if (e instanceof Error) {
       throw (Error) e;
     }
     if (e instanceof RuntimeException) {
       throw (Error) e;
     }
     throw new AssertionError(error);
   } finally {
     updateTestClass(m.getDeclaringClass());
   }
 }
Esempio n. 2
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. 3
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. 4
0
  public void moveTab(int index, int delta) {
    // do no work if we haven't been asked to move anywhere
    if (delta == 0) return;

    Element tabHost = getTabBarElement();

    // ignore moving left if the tab is already the leftmost tab (same for
    // right)
    int dest = index + delta;
    if (dest < 0 || dest >= tabHost.getChildCount()) return;

    // rearrange the DOM
    Element tab = Element.as(tabHost.getChild(index));
    Element prev = Element.as(tabHost.getChild(dest));
    tabHost.removeChild(tab);
    if (delta > 0) tabHost.insertAfter(tab, prev);
    else tabHost.insertBefore(tab, prev);

    // fire the tab reorder event (this syncs the editor state)
    TabReorderEvent event = new TabReorderEvent(index, dest);
    fireEvent(event);
  }