com.google.gwt.dom.client.Element Java Examples

The following examples show how to use com.google.gwt.dom.client.Element. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SuggestionsContainer.java    From cuba with Apache License 2.0 6 votes vote down vote up
public SuggestionsContainer(CubaSuggestionFieldWidget suggestionFieldWidget) {
    this.suggestionFieldWidget = suggestionFieldWidget;
    container = DOM.createDiv();

    final Element outer = FocusImpl.getFocusImplForPanel().createFocusable();
    DOM.appendChild(outer, container);
    setElement(outer);

    sinkEvents(Event.ONCLICK
            | Event.ONMOUSEDOWN
            | Event.ONMOUSEOVER
            | Event.ONMOUSEOUT
            | Event.ONFOCUS
            | Event.ONKEYDOWN);

    addDomHandler(event ->
            selectItem(null), BlurEvent.getType());

    setStylePrimaryName(STYLENAME);
}
 
Example #2
Source File: FullStructure.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public AbstractConversationViewImpl<?, ?> asConversation(Element e) {
  if (e == null) {
    return null;
  } else {
    View.Type type = typeOf(e);
    switch (type) {
      case ROOT_CONVERSATION:
        return asTopConversationUnchecked(e);
      case INLINE_CONVERSATION:
        return asInlineConversationUnchecked(e);
      default:
        throw new IllegalArgumentException("Element has a non-conversation type: " + type);
    }
  }
}
 
Example #3
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void replaceChildren(List<C> values, int start, SelectionModel<? super C> selectionModel, boolean stealFocus) {
  // Render the children.
  SafeHtmlBuilder sb = new SafeHtmlBuilder();
  render(sb, values, 0, selectionModel);

  Map<Object, CellTreeNodeView<?>> savedViews = saveChildState(values, start);

  nodeView.tree.isRefreshing = true;
  SafeHtml html = sb.toSafeHtml();
  Element newChildren = AbstractHasData.convertToElements(nodeView.tree, getTmpElem(), html);
  AbstractHasData.replaceChildren(nodeView.tree, childContainer, newChildren, start, html);
  nodeView.tree.isRefreshing = false;

  loadChildState(values, start, savedViews);
}
 
Example #4
Source File: NodeManager.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given point to a parent-nodeAfter point, splitting a
 * text node if necessary.
 *
 * @param point
 * @return a point at the same location, between node boundaries
 */
public static Point.El<Node> forceElementPoint(Point<Node> point) {
  Point.El<Node> elementPoint = point.asElementPoint();
  if (elementPoint != null) {
    return elementPoint;
  }
  Element parent;
  Node nodeAfter;
  Text text = point.getContainer().cast();
  parent = text.getParentElement();
  int offset = point.getTextOffset();
  if (offset == 0) {
    nodeAfter = text;
  } else if (offset == text.getLength()) {
    nodeAfter = text.getNextSibling();
  } else {
    nodeAfter = text.splitText(offset);
  }
  return Point.inElement(parent, nodeAfter);
}
 
Example #5
Source File: ParagraphRenderer.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
  *
  * Set/unset an event handler in the paragraph's DOM element
  *
  * @param element
  * @param paragraphType
  */
 private void updateEventHandler(final ContentElement element, ParagraphBehaviour paragraphType) {

   if (!GWT.isClient()) return;

   Element implNodelet = element.getImplNodelet();

   final EventHandler handler = paragraphType == null ? null
       : Paragraph.eventHandlerRegistry.get(paragraphType);

   if (handler != null) {
     DOM.sinkEvents(DomHelper.castToOld(implNodelet), LISTENER_EVENTS);
     DOM.setEventListener(DomHelper.castToOld(implNodelet), new EventListener() {
       @Override
       public void onBrowserEvent(Event event) {
         handler.onEvent(element, event);
       }
     });
   } else {
     DOM.setEventListener(implNodelet, null);
     DOM.sinkEvents(implNodelet, DOM.getEventsSunk(implNodelet) & ~LISTENER_EVENTS);
   }

}
 
Example #6
Source File: CenterPopupPositioner.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setPopupPositionAndMakeVisible(Element relative, final Element p) {
  ScheduleCommand.addCommand(new Scheduler.Task() {
    @Override
    public void execute() {
      p.getStyle().setLeft((RootPanel.get().getOffsetWidth() - p.getOffsetWidth()) / 2, Unit.PX);
      int height = PositionUtil.boundHeightToScreen(p.getOffsetHeight());
      int top = (RootPanel.get().getOffsetHeight() - height) / 2;
      // Prevent negative top position.
      p.getStyle().setTop(Math.max(top, MIN_OFFSET_HEIGHT_DEFAULT), Unit.PX);
      p.getStyle().setHeight(height, Unit.PX);
      p.getStyle().setVisibility(Visibility.VISIBLE);
    }
  });
}
 
Example #7
Source File: FullStructure.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public AbstractConversationViewImpl<?, ?> asConversation(Element e) {
  if (e == null) {
    return null;
  } else {
    View.Type type = typeOf(e);
    switch (type) {
      case ROOT_CONVERSATION:
        return asTopConversationUnchecked(e);
      case INLINE_CONVERSATION:
        return asInlineConversationUnchecked(e);
      default:
        throw new IllegalArgumentException("Element has a non-conversation type: " + type);
    }
  }
}
 
Example #8
Source File: ParticipantController.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Shows an add-participant popup.
 */
private void handleAddButtonClicked(Element context) {
  String addressString = Window.prompt("Add a participant(s) (separate with comma ','): ", "");
  if (addressString == null) {
    return;
  }

  ParticipantId[] participants;

  try {
    participants = buildParticipantList(localDomain, addressString);
  } catch (InvalidParticipantAddress e) {
    Window.alert(e.getMessage());
    return;
  }

  ParticipantsView participantsUi = views.fromAddButton(context);
  Conversation conversation = models.getParticipants(participantsUi);
  for (ParticipantId participant : participants) {
    conversation.addParticipant(participant);
  }
}
 
Example #9
Source File: SearchPanelWidget.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@UiHandler("self")
void handleClick(ClickEvent e) {
  Element target = e.getNativeEvent().getEventTarget().cast();
  Element top = self.getElement();
  while (!top.equals(target)) {
    if ("digest".equals(target.getAttribute(BuilderHelper.KIND_ATTRIBUTE))) {
      handleClick(byId.get(target.getAttribute(DigestDomImpl.DIGEST_ID_ATTRIBUTE)));
      e.stopPropagation();
      return;
    } else if (showMore.equals(target)) {
      handleShowMoreClicked();
    }
    target = target.getParentElement();
  }
}
 
Example #10
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void onTouchOrMouseDown(NativeEvent event) {
    if (targetBarElement != null && isMoveOrResizingInProgress()) {
        // discard previous 'operation'.
        resetBarPosition(targetBarElement);
        stopDrag(event);
        return;
    }
    Element bar = getBar(event);
    if (bar == null) {
        return;
    }

    targetBarElement = bar;
    capturePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event));
    movePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event));

    capturePointLeftPercentage = bar.getStyle().getProperty("left");
    capturePointWidthPercentage = bar.getStyle().getProperty("width");
    capturePointLeftPx = bar.getOffsetLeft();
    capturePointTopPx = bar.getOffsetTop();
    capturePointAbsTopPx = bar.getAbsoluteTop();
    capturePointWidthPx = bar.getClientWidth();
    capturePointBgColor = bar.getStyle().getBackgroundColor();

    if (detectResizing(bar)) {
        resizing = true;
        resizingFromLeft = isResizingLeft(bar);
    } else {
        resizing = false;
    }

    disallowClickTimer.schedule(CLICK_INTERVAL);
    insideDoubleClickDetectionInterval = true;
    doubleClickDetectionMaxTimer.schedule(DOUBLECLICK_DETECTION_INTERVAL);

    event.stopPropagation();
}
 
Example #11
Source File: HtmlDomRenderer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/** Turns a UiBuilder rendering into a DOM element. */
private Element parseHtml(UiBuilder ui) {
  if (ui == null) {
    return null;
  }
  SafeHtmlBuilder html = new SafeHtmlBuilder();
  ui.outputHtml(html);
  Element div = com.google.gwt.dom.client.Document.get().createDivElement();
  div.setInnerHTML(html.toSafeHtml().asString());
  Element ret = div.getFirstChildElement();
  // Detach, in order that this element looks free-floating (required by some
  // preconditions).
  ret.removeFromParent();
  return ret;
}
 
Example #12
Source File: UIHider.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isUIFocused() {
	Element focusedElement = getFocusedElement();
	while (focusedElement != null) {
		for (UIElement element : uiElements) {
			if (element.widget.getElement() == focusedElement)
				return true;
		}
		focusedElement = focusedElement.getParentElement();
	}
	return false;
}
 
Example #13
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Swaps out the old element for the new element.
 * The old element's children are added to the new element
 *
 * @param oldElement
 * @param newElement
 */
public static void replaceElement(Element oldElement, Element newElement) {

  // TODO(danilatos): Profile this to see if it is faster to move the nodes first,
  // and then remove, or the other way round. Profile and optimise some of these
  // other methods too. Take dom mutation event handlers being registered into account.

  if (oldElement.hasParentElement()) {
    oldElement.getParentElement().insertBefore(newElement, oldElement);
    oldElement.removeFromParent();
  }

  DomHelper.moveNodes(newElement, oldElement.getFirstChild(), null, null);
}
 
Example #14
Source File: StrippingHtmlView.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the given node (leaving its children in the dom) if
 * it does not correspond to a wrapper ContentNode
 * @param node
 * @return true if the node was removed, false if not.
 */
private boolean maybeStrip(Node node) {
  if (node == null || DomHelper.isTextNode(node)) return false;

  Element element = node.cast();
  if (!NodeManager.hasBackReference(element)) {
    Node n;
    while ((n = element.getFirstChild()) != null) {
      element.getParentNode().insertBefore(n, element);
    }
    element.removeFromParent();
    return true;
  }
  return false;
}
 
Example #15
Source File: DomViewHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static Element load(String baseId, Component c) {
  Element e = Document.get().getElementById(c.getDomId(baseId));
  if (e == null) {
    throw new RuntimeException("Component not found: " + c);
  }
  return e;
}
 
Example #16
Source File: EditorWebDriverUtil.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * @param editorDiv
 * @return local content of editor owning doc div
 */
public static String webdriverEditorGetLocalContent(Element editorDiv) {
  Editor editor = getByEditorDiv(editorDiv);
  if (editor != null) {
    // This must not be called synchronously in the same key event before
    // the dom is modified.
    EditorTestingUtil.forceFlush(editor);
    return XmlStringBuilder.innerXml(editor.getContent().getFullContentView()).toString();
  } else {
    return "Error in webdriverEditorGetLocalContent";
  }
}
 
Example #17
Source File: CubaTooltip.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    Element element = event.getNativeEvent().getEventTarget().cast();
    if (isTooltipElement(element)) {
        closeNow();
        handleShowHide(event, false);
    } else {
        hideTooltip();
    }
}
 
Example #18
Source File: BgGridSvgElement.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Element element) {
    if (element == null) {
        return false;
    }
    return svgElement.equals(element);
}
 
Example #19
Source File: MaterialTreeItem.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
@Override
protected void insert(Widget child, com.google.gwt.user.client.Element container, int beforeIndex, boolean domInsert) {
    super.insert(child, container, beforeIndex, domInsert);
    if (child instanceof MaterialTreeItem) {
        ((MaterialTreeItem) child).setTree(getTree());
    }
}
 
Example #20
Source File: MaterialDnd.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
public void ignoreFrom(Element... elements) {
    this.ignoreFrom = elements;

    String ignoredClass = getIgnoreFromClassName();
    for (Element element : elements) {
        element.addClassName(ignoredClass);
    }

    ignoreFrom("." + ignoredClass);
}
 
Example #21
Source File: ParagraphNiceHtmlRenderer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private ContentNode renderAndAppendParagraph(
    ReadableDocumentView<ContentNode, ContentElement, ContentTextNode> contentView,
    Element dest, ContentNode child, SelectionMatcher selectionMatcher) {
  PasteFormatRenderer.renderChildren(contentView, dest, child,
      selectionMatcher);

  Element br = Document.get().createBRElement();
  dest.appendChild(br);

  selectionMatcher.maybeNoteHtml(child, br);
  return child;
}
 
Example #22
Source File: ColorDemo.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
   public void onModuleLoad() {

Panel controls = RootPanel.get("controls");

startColor = createTextBox("rgba(255,255,0,1)");
endColor = createTextBox("rgba(255,0,255,0)");
duration = createTextBox("5000");

addTextBox(controls, "Start Color", startColor);
addTextBox(controls, "End Color", endColor);
addTextBox(controls, "Duration", duration);

Button start = new Button("Start");
start.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
        ColorAnimation animation = new ColorAnimation(new Element[] {
							      Document.get().getElementById("box1"),
							      Document.get().getElementById("box2"),
							      Document.get().getElementById("box3")
							  },
							  "backgroundColor",
							  RgbaColor.from(startColor.getText()),
							  RgbaColor.from(endColor.getText()));
        animation.run(Integer.parseInt(duration.getText()));
    }
});

controls.add(start);
   }
 
Example #23
Source File: HtmlSelectionHelperImpl.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private boolean isInChildEditor(Point<Node> point) {
  // The editable doc is marked by an attribute EDITABLE_DOC_MARKER, if
  // an element is found with that attribute, and is not the element of this
  // editor's doc element, then it must be a child's doc element.
  Node n = point.getContainer();
  Element e = DomHelper.isTextNode(n) ? n.getParentElement() : (Element) n;
  while (e != null && e != doc) {
    if (e.hasAttribute(EditorImpl.EDITABLE_DOC_MARKER)) {
      return true;
    }
    e = e.getParentElement();
  }
  return false;
}
 
Example #24
Source File: MaterialWidget.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a CSS3 Transition property to this widget.
 */
public void setTransition(TransitionConfig property) {
    Element target = getElement();
    if (property.getTarget() != null) {
        target = property.getTarget();
    }
    target.getStyle().setProperty("WebkitTransition", property.getProperty() + " " + property.getDuration() + "ms " + property.getTimingFunction() + property.getDelay() + "ms");
    target.getStyle().setProperty("transition", property.getProperty() + " " + property.getDuration() + "ms " + property.getTimingFunction() + property.getDelay() + "ms");
}
 
Example #25
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to find Step element by given starting point and y-position
 * and delta-y. Starting point is there to optimize performance a bit as
 * there's no need to iterate through every single step element.
 *
 * @param startFromBar
 *            Starting point element
 * @param newY
 *            target y-axis position
 * @param deltay
 *            delta-y relative to starting point element.
 * @return Step element at y-axis position. May be same element as given
 *         startFromBar element.
 */
protected Element findStepElement(Element startFromBar, int startTopY, int startBottomY, int newY, double deltay) {
    boolean subStep = isSubBar(startFromBar);
    if (subStep) {
        startFromBar = startFromBar.getParentElement();
    }

    if (isBetween(newY, startTopY, startBottomY)) {
        GWT.log("findStepElement returns same: Y " + newY + " between " + startTopY + "-" + startBottomY);
        return startFromBar;
    }
    int startIndex = getChildIndex(content, startFromBar);
    Element barCanditate;
    int i = startIndex;
    if (deltay > 0) {
        i++;
        for (; i < content.getChildCount(); i++) {
            barCanditate = Element.as(content.getChild(i));
            if (isBetween(newY, barCanditate.getAbsoluteTop(), barCanditate.getAbsoluteBottom())) {
                if (!subStep && i == (startIndex + 1)) {
                    // moving directly over the following step will be
                    // ignored (if not sub-step).
                    return startFromBar;
                }
                return barCanditate;
            }
        }
    } else if (deltay < 0) {
        i--;
        for (; i >= getAdditonalContentElementCount(); i--) {
            barCanditate = Element.as(content.getChild(i));
            if (isBetween(newY, barCanditate.getAbsoluteTop(), barCanditate.getAbsoluteBottom())) {
                return barCanditate;
            }
        }
    }
    return startFromBar;
}
 
Example #26
Source File: Header.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void highlight(String name)
{
    toggleSubnavigation(name);

    com.google.gwt.user.client.Element target = linksPane.getElementById("header-links-ref");
    if(target!=null) // TODO: i think this cannot happen, does it?
    {
        NodeList<Node> childNodes = target.getChildNodes();
        for(int i=0; i<childNodes.getLength(); i++)
        {
            Node n = childNodes.getItem(i);
            if(Node.ELEMENT_NODE == n.getNodeType())
            {
                Element element = (Element) n;
                if(element.getId().equals("header-"+name))
                {
                    element.addClassName("header-link-selected");
                    element.setAttribute("aria-selected", "true");
                }
                else {
                    element.removeClassName("header-link-selected");
                    element.setAttribute("aria-selected", "false");
                }
            }
        }
    }
}
 
Example #27
Source File: StyleUtils.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static <S extends CssStyle> void removeStyle(Element e, S style) {
	if (e == null) {
		return;
	}
	if (style instanceof Enum) {
		StyleUtils.cleanEnumStyle(e, style.getClass());
	}
	String styleName = StyleUtils.getStyle(style);
	String currentClassName = e.getClassName();
	if (styleName != null && currentClassName != null && e.hasClassName(styleName)) {
		e.removeClassName(styleName);
	}
}
 
Example #28
Source File: MaterialOverlay.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Open the Overlay Panel with Path Animator applied
 */
public void open(Element sourceElement) {
    this.sourceElement = sourceElement;
    $("body").attr("style", "overflow: hidden !important");
    animator.setSourceElement(sourceElement);
    animator.setTargetElement(getElement());
    animator.setCompletedCallback(() -> OpenEvent.fire(MaterialOverlay.this, MaterialOverlay.this));
    animator.animate();
}
 
Example #29
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected Element getBar(NativeEvent event) {
    Element element = event.getEventTarget().cast();
    if (element == null || isSvg(element)) {
        return null;
    }
    Element parent = element;
    while (parent.getParentElement() != null && parent.getParentElement() != content && !isBar(parent)) {
        parent = parent.getParentElement();
    }
    if (isBar(parent)) {
        return parent;
    }
    return null;
}
 
Example #30
Source File: MetricView.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
@Override
public void eval(String js) {
    Scheduler.get().scheduleFixedDelay(() -> {
        Element el = Document.get().getElementById(uniqueId);
        if (el != null) {
            ScriptInjector.fromString(js).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(true).inject();
            return false;
        }
        return true;
    }, 100);
}