List of usage examples for com.vaadin.client WidgetUtil findWidget
@SuppressWarnings("unchecked") public static <T> T findWidget(Element element, Class<? extends Widget> class1)
From source file:com.haulmont.cuba.web.toolkit.ui.client.suggestionfield.CubaSuggestionFieldWidget.java
License:Apache License
protected void handleOnBlur(BlurEvent event) { removeStyleName(MODIFIED_STYLENAME); if (BrowserInfo.get().isIE()) { if (iePreventBlur) { textField.setFocus(true);//from ww w . ja v a 2 s. co m 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(); } } } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.table.CubaScrollTableConnector.java
License:Apache License
@Override public TooltipInfo getTooltipInfo(Element element) { if (getState().columnDescriptions != null) { Element targetHeaderElement = findCurrentOrParentTd(element); if (targetHeaderElement != null && targetHeaderElement.hasClassName("v-table-header-cell")) { // if column has description int childIndex = DOM.getChildIndex(targetHeaderElement.getParentElement(), targetHeaderElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnDescription = getState().columnDescriptions.get(columnKey); if (columnDescription != null && !columnDescription.isEmpty()) { return new TooltipInfo(columnDescription); }//www.j a va 2 s .com } } } if (getState().aggregationDescriptions != null) { Element targetAggregatedElement = findCurrentOrParentTd(element); if (targetAggregatedElement != null && (targetAggregatedElement.hasClassName("v-table-aggregation-cell") || targetAggregatedElement.getFirstChildElement().hasClassName("v-table-footer-container"))) { int childIndex = DOM.getChildIndex(targetAggregatedElement.getParentElement(), targetAggregatedElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnTooltip = getState().aggregationDescriptions.get(columnKey); if (columnTooltip != null && !columnTooltip.isEmpty()) { return new TooltipInfo(columnTooltip); } } } } if (element != getWidget().getElement()) { Object node = WidgetUtil.findWidget(element, CubaScrollTableWidget.CubaScrollTableBody.CubaScrollTableRow.class); if (node != null) { CubaScrollTableWidget.CubaScrollTableBody.CubaScrollTableRow row = (CubaScrollTableWidget.CubaScrollTableBody.CubaScrollTableRow) node; return row.getTooltip(element); } } return super.getTooltipInfo(element); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.Tools.java
License:Apache License
protected static VOverlay createContextMenu() { return new TableOverlay() { @Override//from w w w . j a va 2 s . com protected void onDetach() { super.onDetach(); } @Override protected void onPreviewNativeEvent(Event.NativePreviewEvent event) { super.onPreviewNativeEvent(event); NativeEvent nativeEvent = event.getNativeEvent(); Element target = Element.as(nativeEvent.getEventTarget()); if (Event.ONKEYDOWN == event.getTypeInt()) { if (KeyCodes.KEY_ESCAPE == event.getNativeEvent().getKeyCode()) { event.cancel(); event.getNativeEvent().stopPropagation(); event.getNativeEvent().preventDefault(); hide(); } else { VAbstractOrderedLayout verticalLayout = ((VVerticalLayout) getWidget()); Widget widget = WidgetUtil.findWidget(target, null); if (isLayoutChild(verticalLayout, widget)) { Widget widgetParent = widget.getParent(); 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) { VButton button = (VButton) focusWidget; focusSelectedItem(widgetParent.getParent(), button); button.setFocus(true); } } } } else if (Event.ONMOUSEOVER == event.getTypeInt()) { VAbstractOrderedLayout verticalLayout = ((VAbstractOrderedLayout) getWidget()); Widget widget = WidgetUtil.findWidget(target, null); if (isLayoutChild(verticalLayout, widget)) { if (widget instanceof VButton) { VButton button = (VButton) widget; Widget widgetParent = button.getParent(); if (!button.getStyleName().contains(SELECTED_ITEM_STYLE)) { focusSelectedItem(widgetParent.getParent(), button); button.setFocus(true); } } } } } }; }
From source file:com.haulmont.cuba.web.toolkit.ui.client.treetable.CubaTreeTableConnector.java
License:Apache License
@Override public TooltipInfo getTooltipInfo(Element element) { if (getState().columnDescriptions != null) { Element targetHeaderElement = findCurrentOrParentTd(element); if (targetHeaderElement != null) { // if column has description int childIndex = DOM.getChildIndex(targetHeaderElement.getParentElement(), targetHeaderElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnDescription = getState().columnDescriptions.get(columnKey); if (columnDescription != null && !columnDescription.isEmpty()) { return new TooltipInfo(columnDescription); }//from www . j a va 2 s .c o m } } } if (getState().aggregationDescriptions != null) { Element targetAggregatedElement = findCurrentOrParentTd(element); if (targetAggregatedElement != null && (targetAggregatedElement.hasClassName("v-table-aggregation-cell") || targetAggregatedElement.hasClassName("v-table-footer-container"))) { int childIndex = DOM.getChildIndex(targetAggregatedElement.getParentElement(), targetAggregatedElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnTooltip = getState().aggregationDescriptions.get(columnKey); if (columnTooltip != null && !columnTooltip.isEmpty()) { return new TooltipInfo(columnTooltip); } } } } if (element != getWidget().getElement()) { Object node = WidgetUtil.findWidget(element, CubaTreeTableWidget.CubaTreeTableBody.CubaTreeTableRow.class); if (node != null) { CubaTreeTableWidget.CubaTreeTableBody.CubaTreeTableRow row = (CubaTreeTableWidget.CubaTreeTableBody.CubaTreeTableRow) node; return row.getTooltip(element); } } return super.getTooltipInfo(element); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.verticalmenu.CubaSideMenuWidget.java
License:Apache License
@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); }//w w w . j av a2 s . c om break; case Event.ONMOUSEOUT: if (!focused) { setFocusedItem(null); } break; } } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.verticalmenu.CubaSideMenuWidget.java
License:Apache License
public String getTooltip(Element element) { Object widget = WidgetUtil.findWidget(element, null); if (widget instanceof MenuItemWidget) { return ((MenuItemWidget) widget).getDescription(); }//w w w .j av a 2 s.c o m return null; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.accordion.VDDAccordion.java
License:Apache License
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * /*from w w w . ja v a2s . c o m*/ * @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()); } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.accordion.VDDAccordion.java
License:Apache License
/** * Emphasisizes a container element/*from w w w . j a v a2 s .c o m*/ * * @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; } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.accordion.VDDAccordion.java
License:Apache License
@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; }/* w w w.ja v a2s .c om*/ i++; } } return -1; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayoutDropHandler.java
License:Apache License
@Override protected Slot getSlot(Element e, NativeEvent event) { Slot slot = null;// w w w .j ava 2 s . c o m 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; }