コード例 #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());
   }
 }
コード例 #2
0
  /**
   * Called when an event occurs in a rendered instance of this Cell. The parent element refers to
   * the element that contains the rendered cell, NOT to the outermost element that the Cell
   * rendered.
   */
  @Override
  public void onBrowserEvent(
      final Context context,
      final Element parent,
      final List<FlashCardDto> flashCardList,
      final NativeEvent event,
      final ValueUpdater<List<FlashCardDto>> valueUpdater) {
    // Let AbstractCell handle the keydown event.
    super.onBrowserEvent(context, parent, flashCardList, event, valueUpdater);

    // Handle the click event.
    if ("click".equals(event.getType())) {
      // Ignore clicks that occur outside of the outermost element.
      EventTarget eventTarget = event.getEventTarget();

      if (parent.isOrHasChild(Element.as(eventTarget))) {
        // use this to get the selected element!!
        Element el = Element.as(eventTarget);

        // check if we really click on the image
        if (el.getParentElement().getNodeName().equalsIgnoreCase("DIV")) {
          doAction(el.getParentElement().getAttribute("name"), valueUpdater);
        }
      }
    }
  }
コード例 #3
0
  private int getTargetItemIndex(Element target) {
    assert !target.equals(this.getElement()); // The markup is now broken

    while (!target.getParentElement().equals(this.getElement())) {
      target = target.getParentElement();
    }
    return DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) target);
  }
コード例 #4
0
 @Override
 public void onPreviewNativeEvent(NativePreviewEvent event) {
   if (event.getTypeInt() == Event.ONCLICK) {
     Element target = event.getNativeEvent().getEventTarget().cast();
     while (target.getParentElement() != null) {
       if (target.getId().equals("silverpeas-navmenu-panel") || target.getId().equals("menu")) {
         return;
       }
       target = target.getParentElement();
     }
     SpMobil.mainPage.closeMenu();
   }
 }
コード例 #5
0
 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;
 }
コード例 #6
0
  /**
   * Tunes splitter. Makes it wider and adds double border to seem rich.
   *
   * @param el element to tune
   */
  private void tuneSplitter(Element el) {
    /** Add Z-Index to move the splitter on the top and make content visible */
    el.getParentElement().getStyle().setProperty("zIndex", "1000");
    el.getParentElement().getStyle().setProperty("overflow", "visible");

    /** Tune splitter catch panel */
    el.getStyle().setProperty("boxSizing", "border-box");
    el.getStyle().setProperty("width", "5px");
    el.getStyle().setProperty("overflow", "hidden");
    el.getStyle().setProperty("marginLeft", "-3px");
    el.getStyle().setProperty("backgroundColor", "transparent");

    /** Add small border */
    DivElement smallBorder = Document.get().createDivElement();
    smallBorder.getStyle().setProperty("position", "absolute");
    smallBorder.getStyle().setProperty("width", "1px");
    smallBorder.getStyle().setProperty("height", "100%");
    smallBorder.getStyle().setProperty("left", "3px");
    smallBorder.getStyle().setProperty("top", "0px");
    smallBorder.getStyle().setProperty("backgroundColor", Style.getSplitterSmallBorderColor());
    el.appendChild(smallBorder);

    /** Add large border */
    DivElement largeBorder = Document.get().createDivElement();
    largeBorder.getStyle().setProperty("position", "absolute");
    largeBorder.getStyle().setProperty("width", "2px");
    largeBorder.getStyle().setProperty("height", "100%");
    largeBorder.getStyle().setProperty("left", "1px");
    largeBorder.getStyle().setProperty("top", "0px");
    largeBorder.getStyle().setProperty("opacity", "0.4");
    largeBorder.getStyle().setProperty("backgroundColor", Style.getSplitterLargeBorderColor());
    el.appendChild(largeBorder);
  }
コード例 #7
0
 private void show(Widget widget, boolean isShow) {
   Element divParent = widget.getElement().getParentElement();
   if (divParent.hasClassName("select-wrapper")) {
     divParent = divParent.getParentElement();
   }
   show(divParent, isShow);
 }
コード例 #8
0
 private void show(boolean applyToParent, UIObject... objs) {
   for (UIObject obj : objs) {
     Element ele = obj.getElement();
     if (applyToParent) {
       ele = ele.getParentElement();
     }
     ele.getStyle().clearDisplay();
   }
 }
コード例 #9
0
 private void hide(boolean applyToParent, UIObject... objs) {
   for (UIObject obj : objs) {
     Element ele = obj.getElement();
     if (applyToParent) {
       ele = ele.getParentElement();
     }
     ele.getStyle().setDisplay(Display.NONE);
   }
 }
コード例 #10
0
 /**
  * remove gwt positioning and overflow from extra divs, and hope for the best about xbrowser
  * compatibility..
  */
 private Element __fixPositioningAndOverflow(final Element element) {
   if ("body".equalsIgnoreCase(element.getTagName())) {
     return element;
   } else {
     element.setAttribute("style", "");
     element.removeAttribute("style"); // does not work on chrome
     element.setId("extradiv_" + index++);
     return __fixPositioningAndOverflow(element.getParentElement());
   }
 }
コード例 #11
0
ファイル: TableUtils.java プロジェクト: alns/as7-console
 private static TableCellElement findNearestParentCell(Element elem) {
   while ((elem != null)) {
     String tagName = elem.getTagName();
     if ("td".equalsIgnoreCase(tagName) || "th".equalsIgnoreCase(tagName)) {
       return elem.cast();
     }
     elem = elem.getParentElement();
   }
   return null;
 }
コード例 #12
0
 /**
  * Attempts to find a component.
  *
  * @param target the element or inner element of the component
  * @param clazz the class the component should have
  * @return the matching component or null if no match
  */
 @SuppressWarnings("unchecked")
 public <X extends Component> X find(Element target, Class<X> clazz) {
   while (target != null) {
     Component c = map.get(target.getId());
     if (c != null && (clazz == null || c.getClass().equals(clazz))) {
       return (X) c;
     } else {
       target = (Element) target.getParentElement();
     }
   }
   return null;
 }
コード例 #13
0
  protected void showShell() {
    final Element loading = Document.get().getElementById("loading");
    loading.getParentElement().removeChild(loading);

    /* And show the user the shell */
    RootLayoutPanel.get().add(shell);

    // remove gwt positioning and overflow from extra divs, and hope for the best about xbrowser
    // compatibility..
    shell.getElement().setId("shell");
    __fixPositioningAndOverflow(Document.get().getElementById("shell"));
  }
コード例 #14
0
 /**
  * Creates a new editor attached to an existing document. {@link Editor#reset() Resetting} this
  * editor will preserve the document to which it is attached.
  *
  * @return New Editor instance
  */
 public static Editor attachTo(ContentDocument doc) {
   Element e = doc.getFullContentView().getDocumentElement().getImplNodelet();
   Preconditions.checkArgument(e != null);
   e = e.getParentElement();
   Preconditions.checkArgument(e != null);
   EditorImpl editor =
       UserAgent.isMobileWebkit()
           ? new EditorImplWebkitMobile(false, e)
           : new EditorImpl(false, e);
   editor.setContent(doc);
   return editor;
 }
コード例 #15
0
  /**
   * Called when an event occurs in a rendered instance of this Cell. The parent element refers to
   * the element that contains the rendered cell, NOT to the outermost element that the Cell
   * rendered.
   */
  @Override
  public void onBrowserEvent(
      com.google.gwt.cell.client.Cell.Context context,
      Element parent,
      String value,
      NativeEvent event,
      com.google.gwt.cell.client.ValueUpdater<String> valueUpdater) {

    // Let AbstractCell handle the keydown event.
    super.onBrowserEvent(context, parent, value, event, valueUpdater);

    // Handle the click event.
    if ("click".equals(event.getType())) {

      // Ignore clicks that occur outside of the outermost element.
      EventTarget eventTarget = event.getEventTarget();

      if (parent.isOrHasChild(Element.as(eventTarget))) {
        // if (parent.getFirstChildElement().isOrHasChild(
        // Element.as(eventTarget))) {

        // use this to get the selected element!!
        Element el = Element.as(eventTarget);

        // check if we really click on the image
        if (callback != null && el.getNodeName().equalsIgnoreCase("IMG")) {
          final String s = el.getParentElement().getAttribute("name");
          final KieContainer container = containersProvider.getContainer(value);
          final boolean isUp = SharedUtils.getContainerStatus(container);
          final boolean isKieApp =
              container.getType() != null
                  && KieImageCategory.KIEAPP.equals(container.getType().getCategory());
          if (ContainerActionsCell.PLAY.equals(s) && !isUp) {
            callback.onStart(container);
          } else if (ContainerActionsCell.STOP.equals(s) && isUp) {
            callback.onStop(container);
          } else if (ContainerActionsCell.RELOAD.equals(s) && isUp) {
            callback.onRestart(container);
          } else if (ContainerActionsCell.REMOVE.equals(s)) {
            callback.onRemove(container);
          } else if (ContainerActionsCell.VIEW_LOGS.equals(s)) {
            callback.onViewLogs(container);
          } else if (ContainerActionsCell.VIEW_DETAILS.equals(s) && isUp && isKieApp) {
            callback.onViewDetails(container);
          } else if (ContainerActionsCell.NAVIGATE.equals(s) && isUp && isKieApp) {
            callback.onNavigate(container);
          }
        }
      }
    }
  };
  @Override
  protected Slot getSlot(Element e, NativeEvent event) {
    Slot slot = null;
    if (getLayout().getElement() == e) {
      // Most likely between components, use the closes one in that case
      slot = findSlotHorizontally(12, event);
    } else {
      slot = WidgetUtil.findWidget(e, Slot.class);
      if (slot == null) {
        return null;
      }
      VAbstractOrderedLayout layout = VDragDropUtil.getSlotLayout(slot);
      while (layout != getLayout() && getLayout().getElement().isOrHasChild(e.getParentElement())) {
        e = e.getParentElement();
        slot = WidgetUtil.findWidget(e, Slot.class);
        if (slot == null) {
          return null;
        }
        layout = VDragDropUtil.getSlotLayout(slot);
      }
    }

    return slot;
  }
コード例 #17
0
  @Override
  public void run() {
    isMobile = true;

    /* Add handlers, setup activities */
    init();

    /* Hide the loading message */
    Element loading = Document.get().getElementById("loading");
    loading.getParentElement().removeChild(loading);

    /* And show the user the shell */
    // TODO (jlabanca): Use RootLayoutPanel when we switch to DockLayoutPanel.
    RootPanel.get().add(shell);
  }
コード例 #18
0
  public void onMouseUp(MouseUpEvent event) {
    if (mouseMoveCanceled) {
      return;
    }

    Event.releaseCapture(getElement());
    setFocus(false);
    if (moveRegistration != null) {
      moveRegistration.removeHandler();
      moveRegistration = null;
    }
    int endX = event.getClientX();
    int endY = event.getClientY();
    int xDiff = startX - endX;
    int yDiff = startY - endY;
    startX = -1;
    startY = -1;
    mouseMoveStarted = false;
    Style s = getElement().getStyle();
    s.setZIndex(1);
    if (!clickTargetsResize()) {
      // check if mouse has moved over threshold of 3 pixels
      boolean mouseMoved = (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3);

      if (!weekGrid.getCalendar().isDisabledOrReadOnly() && mouseMoved) {
        // Event Move:
        // - calendar must be enabled
        // - calendar must not be in read-only mode
        weekGrid.eventMoved(this);
      } else if (!weekGrid.getCalendar().isDisabled()) {
        // Event Click:
        // - calendar must be enabled (read-only is allowed)
        EventTarget et = event.getNativeEvent().getEventTarget();
        Element e = Element.as(et);
        if (e == caption || e == eventContent || e.getParentElement() == caption) {
          if (weekGrid.getCalendar().getEventClickListener() != null) {
            weekGrid.getCalendar().getEventClickListener().eventClick(calendarEvent);
          }
        }
      }

    } else { // click targeted resize bar
      removeGlobalResizeStyle();
      if (weekGrid.getCalendar().getEventResizeListener() != null) {
        weekGrid.getCalendar().getEventResizeListener().eventResized(calendarEvent);
      }
    }
  }
コード例 #19
0
 protected static void hideBlackMask(Element mainPageElem) {
   if (mainPageElem == null) {
     return;
   }
   Element menuElem = mainPageElem.getParentElement();
   if (menuElem == null) {
     return;
   }
   for (int it = 0; it < menuElem.getChildCount(); it++) {
     Element menuChildElem = menuElem.getChild(it).cast();
     String color = menuChildElem.getStyle().getBackgroundColor();
     if ("black".equalsIgnoreCase(color)) {
       menuChildElem.getStyle().setBackgroundColor("transparent");
     }
   }
 }
コード例 #20
0
  /**
   * Sets the overflow of the tab layout content's parent to visible.
   *
   * <p>
   */
  protected void setOverflowVisibleToContent() {

    Element tabRoot = m_tabPanel.getElement();
    // set an additional css class for the parent element of the .gwt-TabLayoutPanelTabs element
    List<Element> tabContentDivs =
        CmsDomUtil.getElementsByClass(
            I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanelContent(),
            CmsDomUtil.Tag.div,
            tabRoot);
    tabContentDivs.addAll(
        CmsDomUtil.getElementsByClass(
            "gwt-TabLayoutPanelContentContainer", CmsDomUtil.Tag.div, tabRoot));
    for (Element e : tabContentDivs) {
      e.getParentElement().getStyle().setOverflow(Overflow.VISIBLE);
    }
  }
 @Override
 public void onAttachOrDetach(AttachEvent event) {
   if (event.isAttached()) {
     textField
         .getElement()
         .getParentElement()
         .insertAfter(resetButtonElement, textField.getElement());
     updateResetButtonVisibility();
     addResetButtonClickListener(resetButtonElement);
   } else {
     Element parentElement = resetButtonElement.getParentElement();
     if (parentElement != null) {
       parentElement.removeChild(resetButtonElement);
     }
     removeResetButtonClickListener(resetButtonElement);
   }
 }
コード例 #22
0
  public void ensureSelectedTabIsVisible(boolean animate) {
    if (currentAnimation_ != null) {
      currentAnimation_.cancel();
      currentAnimation_ = null;
    }

    Element selectedTab =
        (Element)
            DomUtils.findNode(
                getElement(),
                true,
                false,
                new NodePredicate() {
                  public boolean test(Node n) {
                    if (n.getNodeType() != Node.ELEMENT_NODE) return false;
                    return ((Element) n).getClassName().contains("gwt-TabLayoutPanelTab-selected");
                  }
                });
    if (selectedTab == null) {
      return;
    }
    selectedTab = selectedTab.getFirstChildElement().getFirstChildElement();

    Element tabBar = getTabBarElement();

    if (!isVisible() || !isAttached() || tabBar.getOffsetWidth() == 0) return; // not yet loaded

    final Element tabBarParent = tabBar.getParentElement();

    final int start = tabBarParent.getScrollLeft();
    int end =
        DomUtils.ensureVisibleHoriz(
            tabBarParent, selectedTab, padding_, padding_ + rightMargin_, true);

    // When tabs are closed, the overall width shrinks, and this can lead
    // to cases where there's too much empty space on the screen
    Node lastTab = getLastChildElement(tabBar);
    if (lastTab == null || lastTab.getNodeType() != Node.ELEMENT_NODE) return;
    int edge =
        DomUtils.getRelativePosition(tabBarParent, Element.as(lastTab)).x
            + Element.as(lastTab).getOffsetWidth();
    end = Math.min(end, Math.max(0, edge - (tabBarParent.getOffsetWidth() - rightMargin_)));

    if (edge <= tabBarParent.getOffsetWidth() - rightMargin_) end = 0;

    if (start != end) {
      if (!animate) {
        tabBarParent.setScrollLeft(end);
      } else {
        final int finalEnd = end;
        currentAnimation_ =
            new Animation() {
              @Override
              protected void onUpdate(double progress) {
                double delta = (finalEnd - start) * progress;
                tabBarParent.setScrollLeft((int) (start + delta));
              }

              @Override
              protected void onComplete() {
                if (this == currentAnimation_) {
                  tabBarParent.setScrollLeft(finalEnd);
                  currentAnimation_ = null;
                }
              }
            };
        currentAnimation_.run(Math.max(200, Math.min(1500, Math.abs(end - start) * 2)));
      }
    }
  }
コード例 #23
0
    @Override
    public void onBrowserEvent(Event event) {
      if (event.getType() == "dragenter") {
        if (dropPoint_ != null
            && event.getClientX() == dropPoint_.getX()
            && event.getClientY() == dropPoint_.getY()) {
          // Very occasionally (~5%?), dropping a tab will generate a
          // superfluous "dragenter" event immediately after the drop event
          // at exactly the same coordinates. We want to ignore this since
          // it will send us into dragging state; to do so, we cache the
          // coordinates when a tab is dropped and suppress entering drag
          // mode from those coordinates very briefly (note that this won't
          // keep the user from immediately dragging the tab around since
          // you need to move the cursor in some way to initiate a drag,
          // invalidating the coordinates.)
          dropPoint_ = null;
          return;
        }

        if (curState_ == STATE_EXTERNAL) {
          // element that was being dragged around outside boundaries
          // has come back in; clear it and treat like a new drag
          dragElement_.getStyle().clearOpacity();
          dragElement_ = null;
          curState_ = STATE_NONE;
        }
        if (curState_ == STATE_NONE) {
          beginDrag(event);
        }
        event.preventDefault();
      } else if (event.getType() == "dragover") {
        if (curState_ == STATE_DRAGGING) drag(event);
        event.preventDefault();
      } else if (event.getType() == "drop") {
        endDrag(event, ACTION_COMMIT);
        event.preventDefault();

        // cache the drop point for 250ms (see comments in event handler for
        // dragenter)
        dropPoint_ = new Point(event.getClientX(), event.getClientY());
        Scheduler.get()
            .scheduleFixedDelay(
                new Scheduler.RepeatingCommand() {
                  @Override
                  public boolean execute() {
                    dropPoint_ = null;
                    return false;
                  }
                },
                250);
      } else if (event.getType() == "dragend") {
        if (curState_ != STATE_NONE) {
          endDrag(event, ACTION_CANCEL);
        }
        event.preventDefault();
      } else if (event.getType() == "dragleave") {
        if (curState_ == STATE_NONE) return;

        // when a drag leaves the window entirely, we get a dragleave event
        // at 0, 0 (which we always want to treat as a cancel)
        if (!(event.getClientX() == 0 && event.getClientY() == 0)) {
          // look at where the cursor is now--if it's inside the tab panel,
          // do nothing, but if it's outside the tab panel, treat that as
          // a cancel
          Element ele = DomUtils.elementFromPoint(event.getClientX(), event.getClientY());
          while (ele != null && ele != Document.get().getBody()) {
            if (ele.getClassName().contains("gwt-TabLayoutPanelTabs")) {
              return;
            }
            ele = ele.getParentElement();
          }
        }

        if (dragElement_ != null) {
          // dim the element being drag to hint that it'll be moved
          endDrag(event, ACTION_EXTERNAL);
        } else {
          // if this wasn't our element, we can cancel the drag entirely
          endDrag(event, ACTION_CANCEL);
        }
      }
    }
コード例 #24
0
  @PatchMethod
  static Element getOffsetParent(Element element) {
    if (element == null) return null;

    return element.getParentElement();
  }
コード例 #25
0
ファイル: TaggedEntity.java プロジェクト: Thaerious/NERVE
 /**
  * Remove all 'TaggedElement' tags from the rootElement. Note this could potentially invalidate
  * other TaggedEntities that share an rootElement.
  */
 public void unwrap() {
   Main.out.println("TaggedEntity.unwrap() : " + getText());
   Element parentElement = rootElement.getParentElement();
   Node textNode = JSFunctions.createTextNode(getText());
   parentElement.replaceChild(textNode, rootElement);
 }