List of usage examples for com.google.gwt.user.client.ui Widget getParent
public Widget getParent()
From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.JQueryFileUploadOverlay.java
License:Apache License
protected static Widget getWidgetTopParent(Widget widget) { Widget parent = widget.getParent(); while (!(parent instanceof VWindow) && !(parent instanceof VUI) && !(parent instanceof VOverlay)) { parent = parent.getParent();/*from www . j a va 2 s. com*/ } return parent; }
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();//www. j a v a 2 s . 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.Tools.java
License:Apache License
protected static VOverlay createContextMenu() { return new TableOverlay() { @Override/* w ww.j av a 2 s . co m*/ 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.widgets.client.addons.dragdroplayouts.ui.accordion.VDDAccordion.java
License:Apache License
private boolean removeSpacer(Widget spacer) { // Validate.//w ww.ja v a 2s. c om 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; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java
License:Apache License
@Override public int getTabPosition(Widget tab) { if (tab instanceof TabCaption) { tab = tab.getParent(); }/*w ww . j a va 2 s . c o m*/ return tabBar.getWidgetIndex(tab); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.VDragDropUtil.java
License:Apache License
public static Widget getTransferableWidget(Widget w) { if (isCaption(w)) { // Dragging caption means dragging component the caption belongs to Widget owner = null;/*from w w w .j a v a 2 s .c o m*/ if (w instanceof TabCaption) { TabCaption caption = (TabCaption) w; owner = caption.getTab().getTabsheet(); } if (w instanceof VCaption) { ComponentConnector ownerConnector = ((VCaption) w).getOwner(); owner = ownerConnector == null ? null : ownerConnector.getWidget(); } else if (w instanceof VFormLayout.Caption) { ComponentConnector ownerConnector = ((VFormLayout.Caption) w).getOwner(); owner = ownerConnector == null ? null : ownerConnector.getWidget(); } if (owner != null) { w = owner; } } else { // Ensure we are dealing with a Vaadin component ComponentConnector connector = Util.findConnectorFor(w); while (connector == null) { w = w.getParent(); connector = Util.findConnectorFor(w); } } return w; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.VLayoutDragDropMouseHandler.java
License:Apache License
/** * Initiates the drag only on the first move event * * @param originalEvent/*from w ww . ja v a 2 s . c om*/ * 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 = targetParent instanceof VTabsheet.TabCaption; 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); } } }); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.VDragFilter.java
License:Apache License
private ComponentConnector findConnectorForAccordionCaption(Widget widget) { StackItem parent = (StackItem) widget.getParent(); return Util.findConnectorFor(parent.getChildWidget()); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.VDragFilter.java
License:Apache License
private boolean isCaptionForAccordion(Widget widget) { if (widget == null) { return false; }/*from www. j a v a 2 s . c o m*/ if (!(widget instanceof VCaption)) { return false; } Widget parent = widget.getParent(); return parent instanceof StackItem; }