Java Code Examples for com.vaadin.client.WidgetUtil#findWidget()

The following examples show how to use com.vaadin.client.WidgetUtil#findWidget() . 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: CalendarWeekDropHandler.java    From calendar-component with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the location is a valid drop location
 *
 * @param elementOver
 *            The element to check
 * @return
 */
private boolean isLocationValid(Element elementOver) {
    Element weekGridElement = calendarConnector.getWidget().getWeekGrid()
            .getElement();
    Element timeBarElement = calendarConnector.getWidget().getWeekGrid()
            .getTimeBar().getElement();

    Element todayBarElement = null;
    if (calendarConnector.getWidget().getWeekGrid().hasToday()) {
        todayBarElement = calendarConnector.getWidget().getWeekGrid()
                .getDateCellOfToday().getTodaybarElement();
    }

    // drops are not allowed in:
    // - weekday header
    // - allday event list
    // - todaybar
    // - timebar
    // - items
    return DOM.isOrHasChild(weekGridElement, elementOver)
            && !DOM.isOrHasChild(timeBarElement, elementOver)
            && todayBarElement != elementOver
            && (WidgetUtil.findWidget(elementOver,
                    DateCellDayItem.class) == null);
}
 
Example 2
Source File: VDDAccordion.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * 
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    if (event.getElementOver() == null) {
        return;
    }

    StackItem tab = WidgetUtil.findWidget(event.getElementOver(),
            StackItem.class);

    if (tab != null && getElement().isOrHasChild(tab.getElement())) {
        Map<String, Object> dropDetails = event.getDropDetails();

        int index = getTabPosition(tab);
        dropDetails.put(Constants.DROP_DETAIL_TO, index);

        VerticalDropLocation location = getDropLocation(tab, event);
        dropDetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION,
                location);

        MouseEventDetails details = MouseEventDetailsBuilder
                .buildMouseEventDetails(event.getCurrentGwtEvent(),
                        getElement());
        dropDetails.put(Constants.DROP_DETAIL_MOUSE_EVENT,
                details.serialize());
    }
}
 
Example 3
Source File: VDDVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected Slot getSlot(Element e, NativeEvent event) {
    Slot slot = null;
    if (getLayout().getElement() == e) {
        // Most likely between components, use the closest one in that case
        slot = findSlotVertically(12, event);
    } else {
        slot = WidgetUtil.findWidget(e, Slot.class);
        if (slot == null) {
            return null;
        }
        VAbstractOrderedLayout layout = VDragDropUtil.getSlotLayout(slot);
        while (layout != getLayout() && getLayout().getElement()
                .isOrHasChild(e.getParentElement())) {
            e = e.getParentElement();
            slot = WidgetUtil.findWidget(e, Slot.class);
            if (slot == null) {
                return null;
            }
            layout = VDragDropUtil.getSlotLayout(slot);
        }
    }
    return slot;
}
 
Example 4
Source File: VDDHorizontalLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected Slot getSlot(Element e, NativeEvent event) {
    Slot slot = null;
    if (getLayout().getElement() == e) {
        // Most likely between components, use the closes one in that case
        slot = findSlotHorizontally(12, event);
    } else {
        slot = WidgetUtil.findWidget(e, Slot.class);
        if (slot == null) {
            return null;
        }
        VAbstractOrderedLayout layout = VDragDropUtil.getSlotLayout(slot);
        while (layout != getLayout() && getLayout().getElement()
                .isOrHasChild(e.getParentElement())) {
            e = e.getParentElement();
            slot = WidgetUtil.findWidget(e, Slot.class);
            if (slot == null) {
                return null;
            }
            layout = VDragDropUtil.getSlotLayout(slot);
        }
    }

    return slot;
}
 
Example 5
Source File: VDDPanel.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * 
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();

    Widget content = WidgetUtil.findWidget(over, null);

    if (content != null && content != this) {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS,
                content.getClass().getName());
    } else {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS,
                this.getClass().getName());
    }

    // Add mouse event details
    MouseEventDetails details = MouseEventDetailsBuilder
            .buildMouseEventDetails(event.getCurrentGwtEvent(),
                    getElement());
    event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT,
            details.serialize());
}
 
Example 6
Source File: VDDVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected Slot getSlot(Element e, NativeEvent event) {
    Slot slot = null;
    if (getLayout().getElement() == e) {
        // Most likely between components, use the closest one in that case
        slot = findSlotVertically(12, event);
    } else {
        slot = WidgetUtil.findWidget(e, Slot.class);
        if (slot == null) {
            return null;
        }
        VAbstractOrderedLayout layout = VDragDropUtil.getSlotLayout(slot);
        while (layout != getLayout() && getLayout().getElement()
                .isOrHasChild(e.getParentElement())) {
            e = e.getParentElement();
            slot = WidgetUtil.findWidget(e, Slot.class);
            if (slot == null) {
                return null;
            }
            layout = VDragDropUtil.getSlotLayout(slot);
        }
    }
    return slot;
}
 
Example 7
Source File: CubaSideMenuWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    if (isEnabled()) {
        switch (DOM.eventGetType(event)) {
            case Event.ONMOUSEOVER:
                Element targetElement = DOM.eventGetTarget(event);
                Object targetWidget = WidgetUtil.findWidget(targetElement, null);
                if (targetWidget instanceof MenuItemWidget) {
                    setFocusedItem((MenuItemWidget) targetWidget);
                }
                break;
            case Event.ONMOUSEOUT:
                if (!focused) {
                    setFocusedItem(null);
                }
                break;
        }
    }
}
 
Example 8
Source File: CubaSimpleDayCell.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    // if not click event or some other event was fired
    if (event.getTypeInt() != Event.ONCLICK) {
        return;
    }

    // if day cell has expanded events
    if (getElement().getClassName().contains("scrollable")) {
        return;
    }

    Element target = Element.as(event.getEventTarget());
    Widget widget = WidgetUtil.findWidget(target);
    if ((widget instanceof CubaSimpleDayCell) || target.getClassName().contains("spacer")) {
        CubaCalendarWidget cubaCalendar = (CubaCalendarWidget) calendar;
        if (cubaCalendar.getDayClickListener() != null) {
            cubaCalendar.getDayClickListener().accept(getDate());
        }
    }
}
 
Example 9
Source File: CubaPopupButtonConnector.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void handleMouseOver(@SuppressWarnings("unused") Event.NativePreviewEvent event, Element target) {
    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);
            }
        }
    }
}
 
Example 10
Source File: CubaSuggestionFieldWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void handleOnBlur(BlurEvent event) {
    removeStyleName(MODIFIED_STYLENAME);

    if (BrowserInfo.get().isIE()) {
        if (iePreventBlur) {
            textField.setFocus(true);
            iePreventBlur = false;
        } else {
            resetComponentState();
        }
    } else {
        if (!suggestionsPopup.isShowing()) {
            resetComponentState();
            return;
        }

        EventTarget eventTarget = event.getNativeEvent().getRelatedEventTarget();
        if (eventTarget == null) {
            resetComponentState();
            return;
        }

        if (Element.is(eventTarget)) {
            Widget widget = WidgetUtil.findWidget(Element.as(eventTarget), null);
            if (widget != suggestionsContainer) {
                resetComponentState();
            }
        }
    }
}
 
Example 11
Source File: CubaPopupButtonConnector.java    From cuba with 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 File: CubaTreeGridWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isWidgetAllowsClickHandling(Element targetElement, NativeEvent nativeEvent) {
    // By default, clicking on widget renderer prevents row selection.
    // We want to allow row selection. Every time selection is changed,
    // all renderers render their content, as the result, components rendered by
    // ComponentRenderer lose focus because they are replaced with new instances,
    // so we prevent click handling for Focus widgets.
    Widget widget = WidgetUtil.findWidget(targetElement, null);
    return !isWidgetOrParentFocusable(widget);
}
 
Example 13
Source File: VDDAccordion.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public int getTabPosition(Widget tabWidget) {
    StackItem tab = WidgetUtil.findWidget(tabWidget.getElement(),
            StackItem.class);
    if (tab != null && getElement().isOrHasChild(tab.getElement())) {
        int i = 0;
        for (StackItem itm : getStackItems()) {
            if (tab == itm) {
                return i;
            }
            i++;
        }
    }
    return -1;
}
 
Example 14
Source File: CubaTreeGridWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isEventHandlerShouldHandleEvent(Element targetElement, GridEvent<JsonObject> event) {
    if (!event.getDomEvent().getType().equals(Event.MOUSEDOWN)
            && !event.getDomEvent().getType().equals(Event.CLICK)) {
        return super.isEventHandlerShouldHandleEvent(targetElement, event);
    }

    // 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 !(isWidgetOrParentFocusable(widget))
            || isClickThroughEnabled(targetElement);
}
 
Example 15
Source File: CubaGridWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isEventHandlerShouldHandleEvent(Element targetElement, GridEvent<JsonObject> event) {
    if (!event.getDomEvent().getType().equals(Event.MOUSEDOWN)
            && !event.getDomEvent().getType().equals(Event.CLICK)) {
        return super.isEventHandlerShouldHandleEvent(targetElement, event);
    }

    // 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 !(isWidgetOrParentFocusable(widget))
            || isClickThroughEnabled(targetElement);
}
 
Example 16
Source File: CalendarMonthDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
protected void dragAccepted(VDragEvent drag) {
    deEmphasis();
    currentTargetElement = drag.getElementOver();
    currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
            SimpleDayCell.class);
    emphasis();
}
 
Example 17
Source File: CalendarWeekDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
protected void dragAccepted(VDragEvent drag) {
    deEmphasis();
    currentTargetElement = drag.getElementOver();
    currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
            DateCell.class);
    emphasis();
}
 
Example 18
Source File: VDDAccordion.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Emphasisizes a container element
 * 
 * @param element
 */
protected void emphasis(Element element, VDragEvent event) {

    // Find the tab
    StackItem tab = WidgetUtil.findWidget(element, StackItem.class);
    if (tab != null && getElement().isOrHasChild(tab.getElement())
            && currentlyEmphasised != tab) {
        VerticalDropLocation location = getDropLocation(tab, event);

        if (location == VerticalDropLocation.MIDDLE) {
            if (tab.isOpen()) {
                tab.addStyleName(CLASSNAME_OVER);
            } else {
                tab.getWidget(0).addStyleName(CLASSNAME_OVER);
            }
        } else if (!spacer.isAttached()) {
            if (location == VerticalDropLocation.TOP) {
                insertSpacer(spacer, getElement(), getWidgetIndex(tab));
                tab.setHeight(
                        (tab.getOffsetHeight() - spacer.getOffsetHeight())
                                + "px");
            } else if (location == VerticalDropLocation.BOTTOM) {
                insertSpacer(spacer, getElement(), getWidgetIndex(tab) + 1);
                int newHeight = tab.getOffsetHeight()
                        - spacer.getOffsetHeight();
                if (getWidgetIndex(spacer) == getWidgetCount() - 1) {
                    newHeight -= spacer.getOffsetHeight();
                }
                if (newHeight >= 0) {
                    tab.setHeight(newHeight + "px");
                }
            }
        }
        currentlyEmphasised = tab;
    }
}
 
Example 19
Source File: CubaGridWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected boolean isClickThroughEnabled(Element e) {
    Widget widget = WidgetUtil.findWidget(e, null);
    return widget instanceof HasClickSettings &&
            ((HasClickSettings) widget).isClickThroughEnabled();
}
 
Example 20
Source File: CubaTreeGridWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected boolean isClickThroughEnabled(Element e) {
    Widget widget = WidgetUtil.findWidget(e, null);
    return widget instanceof HasClickSettings &&
            ((HasClickSettings) widget).isClickThroughEnabled();
}