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

The following examples show how to use com.google.gwt.user.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 check out the related API usage on the sidebar.
Example 1
public static void setFavicon(GUIInfo info) {
	try {
		Element link = DOM.getElementById("favicon");
		Element parent = DOM.getParent(link);
		DOM.removeChild(parent, link);

		link = DOM.createElement("link");
		link.setId("favicon");
		link.setAttribute("rel", "shortcut icon");
		link.setAttribute("type", "image/png");
		link.setAttribute("href", info.getBranding().getFaviconSrc());

		DOM.appendChild(parent, link);
	} catch (Throwable t) {

	}
}
 
Example 2
Source Project: gwtmockito   Source File: MyWidgetTestWithoutRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  GwtMockito.initMocks(this);
  widget = new MyWidget() {
    @Override
    protected void initWidget(Widget widget) {
      // initWidget must be disarmed when testing widget to avoid
      // UnsatisfiedLinkErrors
    }

    @Override
    Element doStuffInJavaScript() {
      // JSNI methods  must be explicitly overridden or factored out to avoid
      // UnsatisfiedLinkErrors
      return null;
    }
  };
}
 
Example 3
Source Project: appinventor-extensions   Source File: MockComponentsUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the preferred size of the specified DOM element in an array of the
 * form {@code [width, height]}.
 *
 * @see #getPreferredSizeOfDetachedWidget(Widget)
 * @param element the DOM element to compute the size for
 * @return the natural width and height of the element
 */
public static int[] getPreferredSizeOfElement(Element element) {
  Element root = RootPanel.get().getElement();
  root.appendChild(element);

  String[] style = clearSizeStyle(element);
  int width = element.getOffsetWidth() + 4;
  int height = element.getOffsetHeight() + 6;
  if (height < 26) {
    height = 26;
  }
  restoreSizeStyle(element, style);

  root.removeChild(element);
  return new int[] { width, height };
}
 
Example 4
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	Element td = getEventTargetCell(event);
	if (td == null)
		return;
	Element tr = DOM.getParent(td);

	switch (DOM.eventGetType(event)) {
		case Event.ONMOUSEOVER:
			tr.addClassName(ROW_STYLE_NAME + "-mouseover");
			break;

		case Event.ONMOUSEOUT: {
			tr.removeClassName(ROW_STYLE_NAME + "-mouseover");
			break;
		}
	}
}
 
Example 5
Source Project: SensorWebClient   Source File: DiagramTab.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void initTooltips() {

        Element mousePointerElement = getMousePointerLineElement();
        DOM.setStyleAttribute(mousePointerElement, "backgroundColor", "blue");
        DOM.setStyleAttribute(mousePointerElement, "width", "0px");
        DOM.setStyleAttribute(mousePointerElement, "height", "0px");
        DOM.setStyleAttribute(mousePointerElement, "visibility", "hidden");
        DOM.setStyleAttribute(mousePointerElement, "marginTop", "6px");
        this.mainChartViewport.add(this.verticalMousePointerLine);

        this.tooltipPresenter = new TooltipPresenter(this.mainChartEventBus);

        this.tooltipPresenter.configureHoverMatch(true, false, false);
        this.tooltipPresenter.setTooltipZIndex(Constants.Z_INDEX_ON_TOP);

        GenericWidgetViewImpl widget = new GenericWidgetViewImpl(this.verticalMousePointerLine);
        MousePointerPresenter mpp = new MousePointerPresenter(this.mainChartEventBus, widget);
        mpp.configure(true, false);
    }
 
Example 6
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 7
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 8
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 9
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 10
Source Project: core   Source File: StackedBar.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void setRatio(double total, double actual)
{
    Element inner = panel.getElementById(innerId);
    double percentage = percentage(total, actual);
    if(percentage>0)
    {
        inner.setAttribute("style", "width:" + percentage + "%");
        inner.setAttribute("cssText", "width:" + percentage + "%");
    }
    else
    {
        inner.setAttribute("style", "background:none");
        inner.setAttribute("cssText", "background:none");
    }
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    html.appendHtmlConstant("<span style='padding-right:5px;'>").appendEscaped(percentage + "%").appendHtmlConstant("</span>");
    inner.setInnerHTML(html.toSafeHtml().asString());
}
 
Example 11
/**
 * Download files exported as zip
 *
 * @author danilo
 */
@Deprecated
public static void downloadFiles(List<String> path, String params) {
	if (!params.equals("")) {
		params = "&" + params;
	}

	final Element downloadIframe = RootPanel.get("__download").getElement();
	String url = RPCService.DownloadServlet + "?export" + params;

	for (String p : path) {
		url += "&pathList=" + URL.encodeQueryString(p);
	}

	DOM.setElementAttribute(downloadIframe, "src", url);
}
 
Example 12
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 13
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 14
Source Project: cuba   Source File: VDDAccordion.java    License: Apache License 2.0 6 votes vote down vote up
private void insertSpacer(Widget spacer,
        com.google.gwt.dom.client.Element container, int beforeIndex) {
    // Validate index; adjust if the widget is already a child of this
    // panel.
    beforeIndex = adjustIndex(spacer, beforeIndex);

    // Detach new child.
    spacer.removeFromParent();

    // We don't add the spacer to the children otherwise we mess the
    // accordion logic.

    // Physical attach.
    DOM.insertChild(container, spacer.getElement(), beforeIndex);

    // Adopt.
    adopt(spacer);
}
 
Example 15
Source Project: cuba   Source File: VDDAccordion.java    License: Apache License 2.0 6 votes vote down vote up
private boolean removeSpacer(Widget spacer) {
    // Validate.
    if (spacer.getParent() != this) {
        return false;
    }
    // Orphan.
    try {
        orphan(spacer);
    } finally {
        // Physical detach.
        Element elem = spacer.getElement();
        DOM.getParent(elem).removeChild(elem);

        // We don't remove the spacer from the children otherwise we mess
        // the accordion logic.
    }
    return true;
}
 
Example 16
private void resetInner() {
	if (this.elementExists()) {
		Element element = this.getElement();
		element.removeAllChildren();
		boolean rendervalue = Boolean.TRUE.equals(this.getValue());
		if (this.outputType != RenderType.TEXT) {
			Icon icon = rendervalue ? this.trueIcon : this.falseIcon;
			if (icon != null) {
				element.appendChild(icon.getElement());
			}
		}
		if (this.outputType != RenderType.ICON) {
			Text textElem = Document.get().createTextNode(rendervalue ? this.trueLabel : this.falseLabel);
			element.appendChild(textElem);
		}
	}
}
 
Example 17
Source Project: SensorWebClient   Source File: DiagramTab.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void onSetDomainBounds(SetDomainBoundsEvent event) {
    if ( !TimeseriesDataStore.getTimeSeriesDataStore().getDataItems().isEmpty()) {
        String[] widthHeight = getBoundValues(event);

        Element mousePointerElement = DiagramTab.this.getMousePointerLineElement();
        DOM.setStyleAttribute(mousePointerElement, "width", widthHeight[0]);
        DOM.setStyleAttribute(mousePointerElement, "height", widthHeight[1]);

        setTooltipsOnTop(event);
    }
}
 
Example 18
Source Project: core   Source File: TreeTable.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setImage(AbstractImagePrototype image) {
  Element child = DOM.getFirstChild(this.image);
  if (child == null) {
    DOM.appendChild(this.image, image.createElement().<Element> cast());
  } else {
    image.applyTo(child.<AbstractImagePrototype.ImagePrototypeElement> cast());
  }
}
 
Example 19
Source Project: dashbuilder   Source File: MapEditorView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MapEditor.View clearError() {
    final Element element = errorLabel.getElement();
    element.setInnerText("");
    element.getStyle().setDisplay(Style.Display.NONE);
    element.getStyle().setBorderWidth(0, Style.Unit.PX);
    errorLabel.setVisible(false);
    return this;
}
 
Example 20
Source Project: appinventor-extensions   Source File: DragSourceSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Configures the specified drag-widget (that will be returned by
 * {@link DragSource#createDragWidget(int, int)}) so that the cursor's hot spot
 * will appear at the point (x,y) in the widget's coordinate system.
 */
public static void configureDragWidgetToAppearWithCursorAt(Widget w, int x, int y) {
  Element e = w.getElement();
  DOM.setStyleAttribute(e, "position", "absolute");
  DOM.setStyleAttribute(e, "left", -x + "px");
  DOM.setStyleAttribute(e, "top", -y + "px");
}
 
Example 21
Source Project: appinventor-extensions   Source File: DragSourceSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Call the equivalent mouse event handler for each touch event
 */
@Override
public void onTouchStart(TouchStartEvent event) {
  event.preventDefault();
  Widget src = (Widget) event.getSource();
  Touch touch = event.getTargetTouches().get(0);
  com.google.gwt.dom.client.Element target = com.google.gwt.dom.client.Element.as(touch.getTarget());
  int x = touch.getRelativeX(target);
  int y = touch.getRelativeY(target);
  onMouseDown(src, x, y);
}
 
Example 22
Source Project: appinventor-extensions   Source File: DragSourceSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onTouchMove(TouchMoveEvent event) {
  Widget src = (Widget) event.getSource();
  Touch touch = event.getTargetTouches().get(0);
  com.google.gwt.dom.client.Element target = com.google.gwt.dom.client.Element.as(touch.getTarget());
  int x = touch.getRelativeX(target);
  int y = touch.getRelativeY(target);
  onMouseMove(src, x, y);
}
 
Example 23
Source Project: appinventor-extensions   Source File: Wizard.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEventPreview(Event event) {
  // Always allow event if capturing is enabled
  if (DOM.getCaptureElement() != null) {
    return true;
  }

  // If this is a modal wizard then only allow it if the target element is a child of this wizard
  if (modal) {
    Element target = DOM.eventGetTarget(event);
    return (target != null && DOM.isOrHasChild(getElement(), target));
  } else {
    return super.onEventPreview(event);
  }
}
 
Example 24
Source Project: appinventor-extensions   Source File: MockComponentsUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Clears the background color of a widget to its default by CSS rules.
 *
 * @param widget  widget to remove the background color for
 */
static void resetWidgetBackgroundColor(Widget widget) {
  Element el = widget.getElement();
  if (el != null) {
    el.getStyle().clearBackgroundColor();
  }
}
 
Example 25
Source Project: appinventor-extensions   Source File: MockComponentsUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Clears the text color of a widget to its default by CSS rules
 *
 * @param widget  widget to remove the text color for
 */
static void resetWidgetTextColor(Widget widget) {
  Element el = widget.getElement();
  if (el != null) {
    el.getStyle().clearColor();
  }
}
 
Example 26
Source Project: appinventor-extensions   Source File: MockComponentsUtil.java    License: Apache License 2.0 5 votes vote down vote up
static String[] clearSizeStyle(Element element) {
  String widthStyle = DOM.getStyleAttribute(element, "width");
  String heightStyle = DOM.getStyleAttribute(element, "height");
  String lineHeightStyle = DOM.getStyleAttribute(element, "lineHeight");
  if (widthStyle != null) {
    DOM.setStyleAttribute(element, "width", null);
  }
  if (heightStyle != null) {
    DOM.setStyleAttribute(element, "height", null);
  }
  if (lineHeightStyle != null) {
    DOM.setStyleAttribute(element, "lineHeight", "initial");
  }
  return new String[] { widthStyle, heightStyle, lineHeightStyle };
}
 
Example 27
Source Project: cuba   Source File: CubaNotificationConnector.java    License: Apache License 2.0 5 votes vote down vote up
protected void showModalityCurtain(Element overlayContainer, Element element, boolean isShowing, int index) {
    getModalityCurtain().getStyle().setZIndex(index + VNotification.Z_INDEX_BASE);

    if (isShowing) {
        overlayContainer.insertBefore(getModalityCurtain(), element);
    } else {
        overlayContainer.appendChild(getModalityCurtain());
    }
}
 
Example 28
Source Project: consulo   Source File: ListPopupPanel2.java    License: Apache License 2.0 5 votes vote down vote up
/** See class docs */
@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent nativePreviewEvent) {
  if (nativePreviewEvent.getTypeInt() != Event.ONCLICK) {
    return;
  }

  Element source = (Element) Element.as(nativePreviewEvent.getNativeEvent().getEventTarget());
  if (!DOM.isOrHasChild(getElement(), source)
      && !DOM.isOrHasChild(getComboBox().getElement(), source)) {
    hide();
    getComboBox().getChoiceButton().setDown(false);
  }
}
 
Example 29
/**
 * Download file by path
 */
@Deprecated
public static void downloadFile(String path, String params) {
	if (!params.equals("") && !params.endsWith("&")) {
		params += "&";
	}

	final Element downloadIframe = RootPanel.get("__download").getElement();
	String url = RPCService.DownloadServlet + "?" + params + "path=" + URL.encodeQueryString(path);
	DOM.setElementAttribute(downloadIframe, "src", url);
}
 
Example 30
/**
 * downloadFilesByUUID
 */
public static void downloadFilesByUUID(List<String> uuidList, String params) {
	if (!params.equals("")) {
		params = "&" + params;
	}

	final Element downloadIframe = RootPanel.get("__download").getElement();
	String url = RPCService.DownloadServlet + "?export" + params;

	for (String uuid : uuidList) {
		url += "&uuidList=" + URL.encodeQueryString(uuid);
	}

	DOM.setElementAttribute(downloadIframe, "src", url);
}