Java Code Examples for com.google.gwt.user.client.ui.Widget#getParent()

The following examples show how to use com.google.gwt.user.client.ui.Widget#getParent() . 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
Source Project: cuba   File: VPopupButton.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
    hiding = false;

    //  ** Copied from PopupView **
    // Find the shortcut action handler that should handle keyboard
    // events from the popup. The events do not propagate automatically
    // because the popup is directly attached to the RootPanel.
    Widget widget = VPopupButton.this;
    while (shortcutActionHandler == null && widget != null) {
        if (widget instanceof ShortcutActionHandler.ShortcutActionHandlerOwner) {
            shortcutActionHandler = ((ShortcutActionHandler.ShortcutActionHandlerOwner) widget)
                    .getShortcutActionHandler();
        }
        widget = widget.getParent();
    }

    super.show();
}
 
Example 2
Source Project: consulo   File: GwtUIUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@SuppressWarnings("unchecked")
public static <T extends Widget> T getParentOf(Widget widget, Class<T> type) {
  Widget target = widget;

  do {
    if (target.getClass() == type) {
      return (T)target;
    }

    target = target.getParent();
  }
  while (target != null);

  return null;
}
 
Example 3
/**
 * Narrows an object to a widget, if it is a child of this panel. Otherwise,
 * throws an exception.
 *
 * @param o object to narrow
 * @return {@code o} as a widget
 * @throws IllegalArgumentException if {@code o} is not a child of this panel.
 */
public Widget narrowChild(Object o) {
  // Note: it is very important that this method can be implemented WITHOUT
  // casting.  This implementation uses casting as an optimization.  However,
  // a non-casting version is provided in comments. Anyone touching this
  // method must ensure that a non-casting possibility exists.
  //
  // for (Widget child : getChildren()) {
  //   if (child == o) {
  //     return child;
  //   }
  // }
  // return null;
  //
  Widget w = o instanceof Widget ? (Widget) o : null;
  if (w != null && w.getParent() == this) {
    return w;
  } else {
    throw new IllegalArgumentException("Not a child");
  }
}
 
Example 4
Source Project: cuba   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 5
/**
 * Initialize the instance.
 */
public void init() {
    if (initialized) {
        return;
    }
    Widget parent = inputWidget.getParent();
    while (parent != null && !parent.getClass().getName().equals("com.google.gwt.user.client.ui.Widget")) {
        helpBlock = findHelpBlock(inputWidget);
        if (helpBlock != null) {
            break;
        } else {
            parent = parent.getParent();
        }
    }
    initialized = true;
}
 
Example 6
Source Project: gantt   File: GanttWidget.java    License: Apache License 2.0 6 votes vote down vote up
public int removeAndReturnIndex(Widget w) {
    int index = -1;
    // Validate.
    if (w.getParent() != this) {
        return index;
    }
    // Orphan.
    try {
        orphan(w);
    } finally {
        index = getWidgetIndex(w);

        // Physical detach.
        Element elem = w.getElement();
        content.removeChild(elem);

        // Logical detach.
        getChildren().remove(w);
    }
    return index;
}
 
Example 7
protected int getContainerOffsetLeft() {
	// if (containerOffsetLeft < 0 || !sync) {
	// int scrollLeft = 0;
	// Element parent = DOM.getParent(widget.getElement());
	// while (parent != null) {
	// if(getScrollLeft(parent) > 0){
	// scrollLeft += getScrollLeft(parent);
	// GWT.log("Scroll left detected : " + scrollLeft);
	// }
	// if ("relative".equals(DOM.getStyleAttribute(parent, "position"))) {
	// containerOffsetLeft = DOM.getAbsoluteLeft(parent) - scrollLeft;
	// }
	// parent = DOM.getParent(parent);
	// }
	if (containerOffsetLeft < 0 || !sync) {
		int left = 0;
		Widget parent = widget.getParent();
		while (parent != null && left == 0) {
			parent = parent.getParent();
			if (parent != null)
				left = parent.getAbsoluteLeft();
		}
		containerOffsetLeft = left;
		//containerOffsetLeft = AdminPanel.get().getContent().getAbsoluteLeft();
	}
	return containerOffsetLeft;
}
 
Example 8
protected int getContainerOffsetTop() {
	// if (containerOffsetTop < 0 || !sync) {
	// int scrollTop = 0;
	// Element parent = DOM.getParent(widget.getElement());
	// while (parent != null) {
	// if (getScrollTop(parent) > 0) {
	// scrollTop += getScrollTop(parent);
	// GWT.log("Scroll Top detected : " + scrollTop);
	// }
	// if ("relative".equals(DOM.getStyleAttribute(parent, "position"))) {
	// containerOffsetTop = DOM.getAbsoluteTop(parent) - scrollTop;
	// }
	// parent = DOM.getParent(parent);
	// }
	// }
	if (containerOffsetTop < 0 || !sync) {
		int top = 0;
		Widget parent = widget.getParent();
		while (parent != null && top == 0) {
			parent = parent.getParent();
			if (parent != null)
				top = parent.getAbsoluteTop();
		}
		containerOffsetTop = top;

		//containerOffsetTop = AdminPanel.get().getContent().getAbsoluteTop();
	}
	return containerOffsetTop;
}
 
Example 9
Source Project: cuba   File: JQueryFileUploadOverlay.java    License: Apache License 2.0 5 votes vote down vote up
protected static Widget getWidgetTopParent(Widget widget) {
    Widget parent = widget.getParent();

    while (!(parent instanceof VWindow) &&
            !(parent instanceof VUI) &&
            !(parent instanceof VOverlay)) {
        parent = parent.getParent();
    }

    return parent;
}
 
Example 10
Source Project: cuba   File: CubaGridWidget.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean isWidgetOrParentFocusable(Widget widget) {
    boolean widgetFocusable = isWidgetFocusable(widget);
    if (!widgetFocusable) {
        Widget parent = widget.getParent();
        while (parent != null
                && !widgetFocusable
                && !isGridCell(parent)) {
            widgetFocusable = isWidgetFocusable(parent);
            parent = parent.getParent();
        }
    }
    return widgetFocusable;
}
 
Example 11
Source Project: cuba   File: CubaPopupButtonConnector.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean isLastChild(Element target) {
    Widget widget = WidgetUtil.findWidget(target, null);
    Widget widgetParent = widget.getParent();
    FlowPanel layout = (FlowPanel) widgetParent.getParent();
    int widgetIndex = layout.getWidgetIndex(widget);
    return widgetIndex == layout.getWidgetCount() - 1;
}
 
Example 12
Source Project: cuba   File: CubaTreeTableWidget.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Element getElementTdOrTr(Element eventTarget) {
    Widget widget = WidgetUtil.findWidget(eventTarget, null);
    Widget targetWidget = widget;

    if (widget != this) {
        /*
         * This is a workaround to make Labels, read only TextFields
         * and Embedded in a Table clickable (see #2688). It is
         * really not a fix as it does not work with a custom read
         * only components (not extending VLabel/VEmbedded).
         */
        while (widget != null && widget.getParent() != this) {
            widget = widget.getParent();
        }

        if (!(widget instanceof VLabel)
                && !(widget instanceof VEmbedded)
                && !(widget instanceof VTextField && ((VTextField) widget).isReadOnly())
                && !(targetWidget instanceof VLabel)
                && !(targetWidget instanceof Panel)
                && !(targetWidget instanceof VEmbedded)
                && !(widget instanceof CubaImageWidget)
                && !(targetWidget instanceof VTextField && ((VTextField) targetWidget).isReadOnly())) {
            return null;
        }
    }
    return getTdOrTr(eventTarget);
}
 
Example 13
Source Project: cuba   File: VGrabFilter.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean isCaptionForAccordion(Widget widget) {
    if (widget == null) {
        return false;
    }
    if (!(widget instanceof VCaption)) {
        return false;
    }
    Widget parent = widget.getParent();
    return parent instanceof VAccordion.StackItem;
}
 
Example 14
Source Project: cuba   File: VDragFilter.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isCaptionForAccordion(Widget widget) {
    if (widget == null) {
        return false;
    }
    if (!(widget instanceof VCaption)) {
        return false;
    }
    Widget parent = widget.getParent();
    return parent instanceof StackItem;
}
 
Example 15
private void maybeLogicalDetach(ContentElement element) {
  Widget w = getGwtWidget(element);
  LogicalPanel p = getLogicalPanel(element);
  if (p != null && w != null && w.getParent() != null) {
    p.doOrphan(w);
  }
}
 
Example 16
Source Project: cuba   File: CubaTreeGridWidget.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean isWidgetOrParentFocusable(Widget widget) {
    boolean widgetFocusable = isWidgetFocusable(widget);
    if (!widgetFocusable) {
        Widget parent = widget.getParent();
        while (parent != null
                && !widgetFocusable
                && !isGridCell(parent)) {
            widgetFocusable = isWidgetFocusable(parent);
            parent = parent.getParent();
        }
    }
    return widgetFocusable;
}
 
Example 17
private void maybeLogicalDetach(ContentElement element) {
  Widget w = getGwtWidget(element);
  LogicalPanel p = getLogicalPanel(element);
  if (p != null && w != null && w.getParent() != null) {
    p.doOrphan(w);
  }
}
 
Example 18
Source Project: cuba   File: VGrabFilter.java    License: Apache License 2.0 4 votes vote down vote up
protected ComponentConnector findConnectorForAccordionCaption(Widget widget) {
    VAccordion.StackItem parent = (VAccordion.StackItem) widget.getParent();
    return Util.findConnectorFor(parent.getChildWidget());
}
 
Example 19
Source Project: cuba   File: VDragFilter.java    License: Apache License 2.0 4 votes vote down vote up
private ComponentConnector findConnectorForAccordionCaption(Widget widget) {
    StackItem parent = (StackItem) widget.getParent();
    return Util.findConnectorFor(parent.getChildWidget());
}
 
Example 20
/**
 * Initiates the drag only on the first move event
 *
 * @param originalEvent
 *            the original Mouse Down event. Only events on elements are
 *            passed in here (Element.as() is safe without check here)
 */
protected void initiateDragOnMove(final NativeEvent originalEvent) {
    EventTarget eventTarget = originalEvent.getEventTarget();

    boolean stopEventPropagation = false;

    Element targetElement = Element.as(eventTarget);
    Widget target = WidgetUtil.findWidget(targetElement, null);
    Widget targetParent = target.getParent();

    // Stop event propagation and prevent default behaviour if
    // - target is *not* a VTabsheet.TabCaption or
    // - drag mode is caption mode and widget is caption
    boolean isTabCaption = WidgetUtil.findWidget(target.getElement(), TabCaption.class) != null;
    boolean isCaption = VDragDropUtil.isCaptionOrCaptionless(targetParent);

    if (dragMode == LayoutDragMode.CLONE && isTabCaption == false) {

        stopEventPropagation = true;

        // overwrite stopEventPropagation flag again if
        // - root implements VHasDragFilter but
        // - target is not part of its drag filter and
        // - target is not a GWT Label based widget
        if (root instanceof VHasDragFilter) {
            if (((VHasDragFilter) root).getDragFilter()
                    .isDraggable(target) == false &&
	(target instanceof LabelBase) == false) {
                    stopEventPropagation = false;
            }
        }

        if (root instanceof VHasGrabFilter) {
            VGrabFilter grabFilter = ((VHasGrabFilter) root).getGrabFilter();
            if (grabFilter != null && !grabFilter.canBeGrabbed(root, target)) {
                return;
            }
        }
    }

    if (dragMode == LayoutDragMode.CAPTION && isCaption) {
        stopEventPropagation = true;
    }

    if (isElementNotDraggable(targetElement)) {
        stopEventPropagation = false;
    }

    if (stopEventPropagation) {
        originalEvent.stopPropagation();
        originalEvent.preventDefault();

        // Manually focus as preventDefault() will also cancel focus
        targetElement.focus();
    }

    mouseDownHandlerReg = Event
            .addNativePreviewHandler(new NativePreviewHandler() {

                @Override
                public void onPreviewNativeEvent(NativePreviewEvent event) {
                    int type = event.getTypeInt();
                    if (type == Event.ONMOUSEUP
                            || type == Event.ONTOUCHCANCEL
                            || type == Event.ONTOUCHEND) {
                        mouseDownHandlerReg.removeHandler();
                        mouseDownHandlerReg = null;

                    } else if (type == Event.ONMOUSEMOVE
                            || type == Event.ONTOUCHMOVE) {
                        mouseDownHandlerReg.removeHandler();
                        mouseDownHandlerReg = null;
                        initiateDrag(originalEvent);
                    }
                }
            });
}