List of usage examples for com.vaadin.client Util findWidget
@Deprecated public static <T> T findWidget(Element element, Class<? extends Widget> class1)
From source file:annis.gui.widgets.gwt.client.ui.VGripDragComponent.java
License:Apache License
private boolean startDrag(NativeEvent event) { VTransferable transferable = new VTransferable(); transferable.setDragSource(ConnectorMap.get(client).getConnector(this)); Element targetElement = (Element) event.getEventTarget().cast(); Paintable paintable;//from w ww . j a v a2 s . co m Widget w = Util.findWidget(targetElement, null); if (!w.getStyleName().contains("drag-source-enabled")) { return false; } while (w != null && !(w instanceof Paintable)) { w = w.getParent(); } paintable = (Paintable) w; transferable.setData("component", paintable); VDragEvent dragEvent = VDragAndDropManager.get().startDrag(transferable, event, true); transferable.setData("clientX", event.getClientX()); transferable.setData("clientY", event.getClientY()); dragEvent.createDragImage(getElement(), true); return true; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java
License:Apache License
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * // www . ja v a 2s . co m * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { Element over = event.getElementOver(); if (placeHolderElement.isOrHasChild(over)) { // Dragging over the placeholder return; } Widget widget = (Widget) Util.findWidget(over, null); if (widget == null) { // Null check return; } int offset = 0; int index = -1; for (int i = 0; i < getElement().getChildCount(); i++) { Element child = getElement().getChild(i).cast(); if (child.isOrHasChild(placeHolderElement)) { offset--; } else if (child.isOrHasChild(widget.getElement())) { index = i + offset; break; } } event.getDropDetails().put(Constants.DROP_DETAIL_TO, index); /* * The horizontal position within the cell */ event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, getHorizontalDropLocation(widget, event)); /* * The vertical position within the cell */ event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, getVerticalDropLocation(widget, event)); // Add mouse event details MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement()); event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize()); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java
License:Apache License
public void updateDrag(VDragEvent drag) { if (placeHolderElement == null) { /*// ww w . j a va 2 s . c o m * Drag image might not have been detach due to lazy attaching in * the DragAndDropManager. Detach it again here if it has not been * detached. */ attachDragImageToLayout(drag); return; } if (drag.getElementOver().isOrHasChild(placeHolderElement)) { return; } if (placeHolderElement.hasParentElement()) { /* * Remove the placeholder from the DOM so we can reposition */ placeHolderElement.removeFromParent(); } Widget w = Util.findWidget(drag.getElementOver(), null); ComponentConnector draggedConnector = (ComponentConnector) drag.getTransferable() .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT); if (draggedConnector != null && w == draggedConnector.getWidget()) { /* * Dragging drag image over the placeholder should not have any * effect (except placeholder should be removed) */ return; } if (w != null && w != this) { HorizontalDropLocation hl = getHorizontalDropLocation(w, drag); VerticalDropLocation vl = getVerticalDropLocation(w, drag); if (hl == HorizontalDropLocation.LEFT || vl == VerticalDropLocation.TOP) { Element prev = w.getElement().getPreviousSibling().cast(); if (draggedConnector == null || prev == null || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) { w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement()); } } else if (hl == HorizontalDropLocation.RIGHT || vl == VerticalDropLocation.BOTTOM) { Element next = w.getElement().getNextSibling().cast(); if (draggedConnector == null || next == null || !draggedConnector.getWidget().getElement().isOrHasChild(next)) { w.getElement().getParentElement().insertAfter(placeHolderElement, w.getElement()); } } else { Element prev = w.getElement().getPreviousSibling().cast(); if (draggedConnector == null || prev == null || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) { w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement()); } } } else { /* * First child or hoovering outside of current components */ getElement().appendChild(placeHolderElement); } updatePlaceHolderStyleProperties(drag); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontalsplitpanel.VDDHorizontalSplitPanel.java
License:Apache License
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * /* w ww. ja va 2 s. c om*/ * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { Element over = event.getElementOver(); if (over == null) { return; } // Resolve where the drop was made HorizontalDropLocation location = null; Widget content = null; if (firstContainer.isOrHasChild(over)) { location = HorizontalDropLocation.LEFT; content = Util.findWidget(firstContainer, null); } else if (splitter.isOrHasChild(over)) { location = HorizontalDropLocation.CENTER; content = this; } else if (secondContainer.isOrHasChild(over)) { location = HorizontalDropLocation.RIGHT; content = Util.findWidget(secondContainer, null); } event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location); if (content != null) { 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()); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java
License:Apache License
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * //ww w.j av a 2s .co m * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { Element element = event.getElementOver(); if (element == null) return; if (tabBar.getElement().isOrHasChild(element)) { Widget w = Util.findWidget(element, null); if (w == tabBar) { // Ove3r the spacer // Add index event.getDropDetails().put(Constants.DROP_DETAIL_TO, tabBar.getWidgetCount() - 1); // Add drop location event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, HorizontalDropLocation.RIGHT); } else { // Add index event.getDropDetails().put(Constants.DROP_DETAIL_TO, getTabPosition(w)); // Add drop location HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio); event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location); } // Add mouse event details MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement()); event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize()); } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java
License:Apache License
/** * Emphasisizes a container element/*from w w w . j a v a 2s . c o m*/ * * @param element */ protected void emphasis(Element element, VDragEvent event) { boolean internalDrag = event.getTransferable().getDragSource() == this; if (tabBar.getElement().isOrHasChild(element)) { Widget w = Util.findWidget(element, null); if (w == tabBar && !internalDrag) { // Over spacer Element spacerContent = spacer.getChild(0).cast(); spacerContent.appendChild(newTab); currentlyEmphasised = element; } else if (w instanceof VCaption) { // Over a tab HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio); if (location == HorizontalDropLocation.LEFT) { int index = getTabPosition(w); if (index == 0) { currentlyEmphasised = tabBar.getWidget(0).getElement().getFirstChildElement().cast(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_LEFT); } else { Widget prevTab = tabBar.getWidget(index - 1); currentlyEmphasised = prevTab.getElement(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT); } } else if (location == HorizontalDropLocation.RIGHT) { int index = getTabPosition(w); currentlyEmphasised = tabBar.getWidget(index).getElement(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT); } else { int index = getTabPosition(w); currentlyEmphasised = tabBar.getWidget(index).getElement(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_CENTER); } } } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java
License:Apache License
/** * Removes any previous emphasis made by drag&drop */// ww w . java 2s. c om protected void deEmphasis() { if (currentlyEmphasised != null && tabBar.getElement().isOrHasChild(currentlyEmphasised)) { Widget w = Util.findWidget(currentlyEmphasised, null); currentlyEmphasised.removeClassName(CLASSNAME_NEW_TAB_LEFT); currentlyEmphasised.removeClassName(CLASSNAME_NEW_TAB_RIGHT); currentlyEmphasised.removeClassName(CLASSNAME_NEW_TAB_CENTER); if (w == tabBar) { // Over spacer Element spacerContent = spacer.getChild(0).cast(); spacerContent.removeChild(newTab); } currentlyEmphasised = null; } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.verticalsplitpanel.VDDVerticalSplitPanel.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 .jav a2s . co m*/ * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { Element over = event.getElementOver(); // Resolve where the drop was made VerticalDropLocation location = null; Widget content = null; if (firstContainer.isOrHasChild(over)) { location = VerticalDropLocation.TOP; content = Util.findWidget(firstContainer, null); } else if (splitter.isOrHasChild(over)) { location = VerticalDropLocation.MIDDLE; content = this; } else if (secondContainer.isOrHasChild(over)) { location = VerticalDropLocation.BOTTOM; content = Util.findWidget(secondContainer, null); } event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, location); if (content != null) { 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()); }
From source file:fi.jasoft.draganddrop.client.configurations.OrderedLayoutDragAndDropConfiguration.java
License:Apache License
protected Slot getSlot(DragAndDropEvent event) { Element e = Util.getElementUnderMouse(event.getEvent()); /*/*from w w w . j a v a 2 s. co m*/ * If we are hitting between slot search around the cursor for the * closest slot */ int nextDirection = 0; int width = 1; int pageX = Util.getTouchOrMouseClientX(event.getEvent()); int pageY = Util.getTouchOrMouseClientY(event.getEvent()); while (event.getTargetConnector().getWidget().getElement() == e) { if (nextDirection == 0) { pageY -= width; nextDirection++; } else if (nextDirection == 1) { pageX += width; nextDirection++; } else if (nextDirection == 2) { pageY += width; nextDirection++; } else if (nextDirection == 3) { pageX -= width; width++; nextDirection = 0; } e = Util.getElementFromPoint(pageX, pageY); } assert e != null : "Event target was null"; Widget w = Util.findWidget(e, null); assert w != null : "Widget was not found"; if (w != null) { while (!(w instanceof Slot) && w != null) { w = w.getParent(); } } assert w instanceof Slot; return (Slot) w; }
From source file:fi.jasoft.draganddrop.client.DragAndDropConnector.java
License:Apache License
protected void onMouseDown(NativeEvent event) { if (isDraggingDisabled()) { return;//from w w w . j ava2 s . c om } Element element = Element.as(event.getEventTarget()); Widget widget = Util.findWidget(element, null); ComponentConnector connector = Util.findConnectorFor(widget); if (connector == null) { return; } dragStartEvent = event; createDragImage(connector.getWidget().getElement(), true); attachDragElement(connector); updateDragImagePosition(event); currentDraggedComponent = connector; getLogger().warning("Started drag"); Event.setCapture(RootPanel.getBodyElement()); event.preventDefault(); event.stopPropagation(); }