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

The following examples show how to use com.google.gwt.dom.client.Element. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: swellrt   Source File: ParticipantController.java    License: 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 2
Source Project: swellrt   Source File: CenterPopupPositioner.java    License: 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 3
Source Project: consulo   Source File: CellTreeNodeView.java    License: 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 Project: swellrt   Source File: ParagraphRenderer.java    License: 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 5
Source Project: cuba   Source File: SuggestionsContainer.java    License: 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 6
Source Project: swellrt   Source File: FullStructure.java    License: 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 7
Source Project: incubator-retired-wave   Source File: NodeManager.java    License: 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 8
Source Project: incubator-retired-wave   Source File: FullStructure.java    License: 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 9
Source Project: dashbuilder   Source File: MetricView.java    License: 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);
}
 
Example 10
Source Project: gwt-material-addins   Source File: MaterialTreeItem.java    License: 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 11
Source Project: swellrt   Source File: EditorWebDriverUtil.java    License: 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 12
Source Project: incubator-retired-wave   Source File: DomHelper.java    License: 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 13
Source Project: djvu-html5   Source File: UIHider.java    License: 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 14
Source Project: swellrt   Source File: SearchPanelWidget.java    License: 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 15
Source Project: gantt   Source File: GanttWidget.java    License: 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 16
Source Project: swellrt   Source File: ParagraphNiceHtmlRenderer.java    License: 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 17
Source Project: gwt-traction   Source File: ColorDemo.java    License: 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 18
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 19
Source Project: gwt-material-addins   Source File: MaterialOverlay.java    License: 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 20
Source Project: gwt-material   Source File: MaterialWidget.java    License: 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 21
Source Project: core   Source File: Header.java    License: 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 22
Source Project: gantt   Source File: GanttWidget.java    License: 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 23
Source Project: incubator-retired-wave   Source File: StrippingHtmlView.java    License: 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 24
Source Project: swellrt   Source File: HtmlSelectionHelperImpl.java    License: 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 25
Source Project: gantt   Source File: GanttWidget.java    License: 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 26
Source Project: swellrt   Source File: HtmlDomRenderer.java    License: 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 27
Source Project: swellrt   Source File: DomViewHelper.java    License: 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 28
Source Project: gwt-material-addins   Source File: MaterialDnd.java    License: 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 29
/**
 * @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 30
Source Project: cuba   Source File: CubaTooltip.java    License: 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();
    }
}