Example usage for com.vaadin.client WidgetUtil findWidget

List of usage examples for com.vaadin.client WidgetUtil findWidget

Introduction

In this page you can find the example usage for com.vaadin.client WidgetUtil findWidget.

Prototype

@SuppressWarnings("unchecked")
public static <T> T findWidget(Element element, Class<? extends Widget> class1) 

Source Link

Document

Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.

Usage

From source file:com.example.test.client.VMultiSelectCalendarWidget.java

License:Apache License

@Override
public String getSubPartName(com.google.gwt.user.client.Element subElement) {
    if (contains(daysTable, subElement)) {
        // Day, find out which dayOfMonth and use that as the identifier
        DayWidget day = WidgetUtil.findWidget(subElement, DayWidget.class);
        if (day != null) {
            Date date = day.getDate();
            int id = date.getDate();
            // Zero or negative ids map to days of the preceding month,
            // past-the-end-of-month ids to days of the following month
            if (date.getMonth() < displayedMonth.getMonth()) {
                id -= DateTimeService.getNumberOfDaysInMonth(date);
            } else if (date.getMonth() > displayedMonth.getMonth()) {
                id += DateTimeService.getNumberOfDaysInMonth(displayedMonth);
            }//from   w ww  . jav a  2  s .c o  m
            return SUBPART_DAY + id;
        }
    } else if (getCellFormatter().getElement(0, 2).isOrHasChild(subElement)) {
        return SUBPART_MONTH_YEAR_HEADER;
    }

    return null;
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.grid.CubaGridWidget.java

License:Apache License

@Override
protected boolean isEventHandlerShouldHandleEvent(Element targetElement) {
    // by default, clicking on widget renderer prevents cell focus changing
    // for some widget renderers we want to allow focus changing
    Widget widget = WidgetUtil.findWidget(targetElement, null);
    return !(widget instanceof com.vaadin.client.Focusable
            || widget instanceof com.google.gwt.user.client.ui.Focusable)
            || isClickThroughEnabled(targetElement);
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.grid.CubaGridWidget.java

License:Apache License

protected boolean isClickThroughEnabled(Element e) {
    Widget widget = WidgetUtil.findWidget(e, null);
    return widget instanceof HasClickSettings && ((HasClickSettings) widget).isClickThroughEnabled();
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.grid.events.CubaGridClickEvent.java

License:Apache License

@Override
public Grid<?> getGrid() {
    EventTarget target = getNativeEvent().getEventTarget();
    if (!Element.is(target)) {
        return null;
    }/* w  w w  .  j  a  v  a 2  s  .c  om*/
    return WidgetUtil.findWidget(Element.as(target), CubaGridWidget.class);
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.grouptable.CubaGroupTableConnector.java

License:Apache License

@Override
public TooltipInfo getTooltipInfo(Element element) {
    if (element != getWidget().getElement()) {
        Object node = WidgetUtil.findWidget(element,
                CubaGroupTableWidget.CubaGroupTableBody.CubaGroupTableRow.class);

        if (node != null) {
            CubaGroupTableWidget.CubaGroupTableBody.CubaGroupTableRow row = (CubaGroupTableWidget.CubaGroupTableBody.CubaGroupTableRow) node;
            return row.getTooltip(element);
        }/*from w  w w.j  a  va  2s.com*/

        node = WidgetUtil.findWidget(element,
                CubaGroupTableWidget.CubaGroupTableBody.CubaGroupTableGroupRow.class);

        if (node != null) {
            CubaGroupTableWidget.CubaGroupTableBody.CubaGroupTableGroupRow row = (CubaGroupTableWidget.CubaGroupTableBody.CubaGroupTableGroupRow) node;
            return row.getTooltip(element);
        }
    }

    return super.getTooltipInfo(element);
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.JQueryFileUploadOverlay.java

License:Apache License

protected static boolean isUnderOverlay(Element dropZoneElement) {
    Widget dropZoneWidget = WidgetUtil.findWidget(dropZoneElement, null);
    if (dropZoneWidget == null)
        return false;

    ComponentConnector dropZoneConnector = Util.findConnectorFor(dropZoneWidget);
    if (dropZoneConnector == null)
        return false;

    ApplicationConnection ac = dropZoneConnector.getConnection();
    List<WindowConnector> windowConnectors = ac.getUIConnector().getSubWindows();
    if (windowConnectors == null || windowConnectors.size() == 0)
        return false;

    List<VWindow> windows = windowConnectors.stream().map(WindowConnector::getWidget)
            .collect(Collectors.toList());

    Widget dropZoneTopParent = getWidgetTopParent(dropZoneWidget);
    if (dropZoneTopParent instanceof VWindow) {
        return modalWindowIsUnderOverlay((VWindow) dropZoneTopParent, windows);
    } else if (dropZoneTopParent instanceof VUI) {
        return containsModalWindow(windows);
    } else {//  ww w  .  j  a v a2s  .c  o  m
        Widget topParentOwner = ((VOverlay) dropZoneTopParent).getOwner();
        Widget ownerParent = getWidgetTopParent(topParentOwner);

        if (ownerParent instanceof VWindow) {
            return modalWindowIsUnderOverlay((VWindow) ownerParent, windows);
        } else {
            return containsModalWindow(windows);
        }
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.popupbutton.CubaPopupButtonConnector.java

License:Apache License

@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if (getWidget().getPopup().isVisible()) {
        Element target = Element.as(nativeEvent.getEventTarget());
        if (getWidget().popupHasChild(target)) {
            if (event.getTypeInt() == Event.ONKEYDOWN
                    && (nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE
                            || nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && isLastChild(target))
                    && !nativeEvent.getAltKey() && !nativeEvent.getCtrlKey() && !nativeEvent.getShiftKey()
                    && !nativeEvent.getMetaKey()) {
                event.cancel();/*from   ww  w. j ava2s  .c o  m*/
                event.getNativeEvent().stopPropagation();
                event.getNativeEvent().preventDefault();
                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                    @Override
                    public void execute() {
                        getWidget().hidePopup();

                        rpc.setPopupVisible(false);
                        getWidget().setFocus(true);
                    }
                });

                return;
            }
        }
    }

    super.onPreviewNativeEvent(event);

    if (isEnabled()) {
        Element target = Element.as(nativeEvent.getEventTarget());
        switch (event.getTypeInt()) {
        case Event.ONCLICK:
            if (getState().autoClose && getWidget().popupHasChild(target)) {
                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                    @Override
                    public void execute() {
                        getWidget().hidePopup();

                        // update state on server
                        rpc.setPopupVisible(false);
                    }
                });
            }
            break;

        case Event.ONKEYDOWN:
            if (!getState().customLayout && getWidget().popupHasChild(target)) {
                Widget widget = WidgetUtil.findWidget(target, null);
                if (widget instanceof VButton || widget instanceof VUpload
                        || widget instanceof CubaFileUploadWidget) {
                    Widget widgetParent = widget.getParent();
                    if (widgetParent.getParent() instanceof VUpload) {
                        VUpload upload = (VUpload) widgetParent.getParent();
                        widgetParent = upload.getParent(); //upload parent is Slot
                    } else if (widgetParent.getParent() instanceof CubaFileUploadWidget) {
                        CubaFileUploadWidget upload = (CubaFileUploadWidget) widgetParent.getParent();
                        widgetParent = upload.getParent(); //upload parent is Slot
                    }

                    VAbstractOrderedLayout layout = (VAbstractOrderedLayout) widgetParent.getParent();
                    Widget focusWidget = null;

                    int widgetIndex = layout.getWidgetIndex(widgetParent);
                    if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN) {
                        focusWidget = Tools.findNextWidget(layout, widgetIndex);
                    } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_UP) {
                        focusWidget = Tools.findPrevWidget(layout, widgetIndex);
                    }

                    if (focusWidget instanceof VButton || focusWidget instanceof CubaFileUploadWidget
                            || focusWidget instanceof VUpload) {
                        VButton button;
                        if (focusWidget instanceof VButton) {
                            button = (VButton) focusWidget;
                        } else if (focusWidget instanceof CubaFileUploadWidget) {
                            button = ((CubaFileUploadWidget) focusWidget).getSubmitButton();
                        } else {
                            button = ((VUpload) focusWidget).submitButton;
                        }
                        getWidget().childWidgetFocused(button);
                        button.setFocus(true);
                    }
                }
            }
            break;

        case Event.ONMOUSEOVER:
            if (!getState().customLayout && getWidget().popupHasChild(target)) {
                Widget widget = WidgetUtil.findWidget(target, null);
                if ((widget instanceof VButton || widget instanceof VUpload
                        || widget instanceof CubaFileUploadWidget)) {

                    VButton button;
                    if (widget instanceof VButton) {
                        button = (VButton) widget;
                    } else if (widget instanceof CubaFileUploadWidget) {
                        button = ((CubaFileUploadWidget) widget).getSubmitButton();
                    } else {
                        button = ((VUpload) widget).submitButton;
                    }
                    if (!button.getStyleName().contains(SELECTED_ITEM_STYLE)) {
                        getWidget().childWidgetFocused(button);
                        button.setFocus(true);
                    }
                }
            }
            break;
        }
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.popupbutton.CubaPopupButtonConnector.java

License:Apache License

private boolean isLastChild(Element target) {
    Widget widget = WidgetUtil.findWidget(target, null);
    Widget widgetParent = widget.getParent();
    VAbstractOrderedLayout layout = (VAbstractOrderedLayout) widgetParent.getParent();
    int widgetIndex = layout.getWidgetIndex(widgetParent);
    return widgetIndex == layout.getWidgetCount() - 1;
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.renderers.componentrenderer.componentcellkey.EscKeyDownHandler.java

License:Apache License

@Override
public void onKeyDown(KeyDownEvent keyDownEvent) {

    if (keyDownEvent.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {

        SimplePanel panel = WidgetUtil.findWidget(WidgetUtil.getFocusedElement(), SimplePanel.class);

        if (panel != null) {
            WidgetUtil.focus(panel.getParent().getElement());

            // prevent further bubbling of the event as it has only
            // navigational purpose if thrown at this depth. A subsequent
            // press of ESC is not stopped, so ESC abort actions of the
            // application should work as soon as the focus is in
            // "navigational mode" on a grid-cell
            keyDownEvent.preventDefault();
            keyDownEvent.stopPropagation();
        }/*from   w w  w  . j av a2 s .com*/
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.renderers.componentrenderer.focuspreserve.FocusPreservingRefreshClientRpcImpl.java

License:Apache License

@Override
public void saveFocus() {
    SimplePanel panel = WidgetUtil.findWidget(WidgetUtil.getFocusedElement(), SimplePanel.class);

    if (panel != null) {
        focus = panel.getParent().getElement();
    }//from  ww w. j  a v  a  2 s .c  o  m
}