Example usage for com.vaadin.client MouseEventDetailsBuilder buildMouseEventDetails

List of usage examples for com.vaadin.client MouseEventDetailsBuilder buildMouseEventDetails

Introduction

In this page you can find the example usage for com.vaadin.client MouseEventDetailsBuilder buildMouseEventDetails.

Prototype

public static MouseEventDetails buildMouseEventDetails(NativeEvent evt, Element relativeToElement) 

Source Link

Document

Construct a MouseEventDetails object from the given event.

Usage

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.
 * //w w w .  j a v  a  2s  .c  o 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.verticallayout.VDDVerticalLayout.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * //w w  w .j  ava2s  .  c o m
 * @param widget
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void updateDragDetails(Widget widget, VDragEvent event) {
    if (widget == null) {
        return;
    }

    /*
     * The horizontal position within the cell{
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION,
            getVerticalDropLocation(widget, event));

    /*
     * The index over which the drag is. Can be used by a client side
     * criteria to verify that a drag is over a certain index.
     */
    int index = -1;
    if (widget instanceof Slot) {
        WidgetCollection captionsAndSlots = getChildren();
        index = VDragDropUtil.findSlotIndex(captionsAndSlots, (Slot) widget);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_TO, index);

    // 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.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.
 * // w ww  .  j  a va  2s.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:com.peter.vaadin.components.others.mycomponent.client.MyComponentConnector.java

License:Apache License

public MyComponentConnector() {
    registerRpc(MyComponentClientRpc.class, new MyComponentClientRpc() {
        private static final long serialVersionUID = -1056192951789062628L;

        public void alert(String message) {
            // TODO Do something useful
            Window.alert(message);
        }/*from   w  w  w  . j  a  v a 2  s  .  co m*/
    });

    // TODO ServerRpc usage example, do something useful instead
    getWidget().addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final MouseEventDetails mouseDetails = MouseEventDetailsBuilder
                    .buildMouseEventDetails(event.getNativeEvent(), getWidget().getElement());
            MyComponentServerRpc rpc = getRpcProxy(MyComponentServerRpc.class);
            rpc.clicked(mouseDetails.getButtonName());
        }
    });

}

From source file:fi.semantum.strategia.widgetset.client.pdfbutton.PDFButtonConnector.java

License:Open Source License

@Override
public void onClick(ClickEvent event) {
    if (getState().disableOnClick) {
        // Simulate getting disabled from the server without waiting for the
        // round trip. The server-side RPC handler takes care of updating
        // the server-side state in a similar way to ensure subsequent
        // changes are properly propagated. Changing state on client is not
        // generally supported.
        getState().enabled = false;/*w  ww .j a v a  2  s .co  m*/
        super.updateEnabledState(false);
        getRpcProxy(PDFButtonServerRpc.class).disableOnClick();
    }

    // Add mouse details
    MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getNativeEvent(),
            getWidget().getElement());

    String text = extractSVG1();

    getRpcProxy(PDFButtonServerRpc.class).setSVG(text);
    getRpcProxy(PDFButtonServerRpc.class).click(details);

}

From source file:org.opennms.features.topology.app.internal.gwt.client.VTopologyComponent.java

License:Open Source License

private Handler<GWTVertex> vertexClickHandler() {
    return new D3Events.Handler<GWTVertex>() {

        @Override/*from  www .  j a v a2s.  c  o m*/
        public void call(GWTVertex vertex, int index) {
            if (D3.eventDefaultPrevented()) {
                return;
            }
            NativeEvent event = D3.getEvent();
            SVGGElement vertexElement = event.getCurrentEventTarget().cast();
            vertexElement.getParentElement().appendChild(vertexElement);

            event.preventDefault();
            event.stopPropagation();

            final MouseEventDetails mouseDetails = MouseEventDetailsBuilder.buildMouseEventDetails(event,
                    getElement());
            m_serverRpc.vertexClicked(vertex.getId(), mouseDetails, Navigator.getPlatform());

        }
    };
}

From source file:org.opennms.features.topology.app.internal.gwt.client.VTopologyComponent.java

License:Open Source License

@Override
public void setVertexSelection(List<String> vertIds) {
    final MouseEventDetails mouseDetails = MouseEventDetailsBuilder.buildMouseEventDetails(D3.getEvent(),
            getElement());// ww w.  ja  va2  s  . c  o m
    m_serverRpc.marqueeSelection(vertIds.toArray(new String[] {}), mouseDetails);
}

From source file:org.semanticsoft.vaaclipse.widgets.client.ui.stackwidget.VStackWidget.java

License:Open Source License

public boolean updateRegion(VDragEvent event) {
    //VConsole.log("updateDropDetails: start");
    Element element = event.getElementOver();
    Widget targetWidget = Util.findWidget(element, null);

    if (targetWidget == null) {
        //VConsole.log("updateDropDetails: targetWidget is null. return.");
        return false;
    }/* w  w w.jav  a  2 s . c  o  m*/

    if (targetWidget != this) {
        //VConsole.log("updateDropDetails: targetWidget != this");
        Widget parent = targetWidget.getParent();
        while (parent != null && parent != this) {
            parent = parent.getParent();
        }

        if (parent == null) {
            //VConsole.log("updateDropDetails: parent not finded");
            return false;
        }
        targetWidget = parent;
        //VConsole.log("updateDropDetails: parent finded");
    }

    MouseEventDetails details1 = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(),
            getElement());

    int mouseX = details1.getClientX();
    int mouseY = details1.getClientY();

    int barLeft = tabBar.getAbsoluteLeft();
    int barTop = tabBar.getAbsoluteTop();
    int barWidth = tabBar.getOffsetWidth();
    int barHeight = tabBar.getOffsetHeight();

    boolean overBar = mouseX > barLeft && mouseX < barLeft + barWidth && mouseY > barTop
            && mouseY < barTop + barHeight;

    if (overBar) {
        //VConsole.log("updateDropDetails: over bar");
        removeDockZone();

        event.getDropDetails().put("targetWidgetClassName", targetWidget.getClass().getName());
        event.getDropDetails().put("dropType", "DropToTabsheetBar");
        event.getDropDetails().put("targetWidgetAbsoluteLeft", targetWidget.getAbsoluteLeft());
        event.getDropDetails().put("targetWidgetAbsoluteTop", targetWidget.getAbsoluteTop());
        event.getDropDetails().put("targetWidgetOffsetWidth", targetWidget.getOffsetWidth());
        event.getDropDetails().put("targetWidgetOffsetHeight", targetWidget.getOffsetHeight());
    } else {
        //VConsole.log("updateDropDetails: not over bar");
        Object sourceWidget = event.getTransferable().getDragSource();
        if (!(sourceWidget instanceof VStackWidget) && !(sourceWidget instanceof StackWidgetConnector)) {
            //VConsole.log("updateDropDetails: return, because the sourceWidget is " + sourceWidget.getClass().getName());
            return false;
        }

        if (sourceWidget instanceof StackWidgetConnector)
            sourceWidget = ((StackWidgetConnector) sourceWidget).getWidget();

        //VConsole.log("updateDropDetails: sourceWidget is VStackWidget or StackWidgetConnector");

        VStackWidget targetTabSheet = this;

        if (targetTabSheet == sourceWidget && targetTabSheet.getTabCount() <= 1) {
            //VConsole.log("updateDropDetails: return, because target is match to source and has only one (current draggable) tab");
            return false;
        }

        VExtendedVerticalLayout outerArea = findOuterArea(targetTabSheet);

        Widget boundingWidget = null;

        if (outerArea != null) {
            //VConsole.log("updateDropDetails: outer area is finded");
            if ("area".equals(outerArea.getVariableValue(E4_ELEMENT_TYPE)))
                boundingWidget = outerArea;
        } else {
            boundingWidget = targetTabSheet;
            //VConsole.log("updateDropDetails: outer area not finded, boundingWidget = targetTabSheet");
        }

        if (boundingWidget == null) {
            //VConsole.log("updateDropDetails: return, because boundingWidget not founded");
            return false;
        }

        event.getDropDetails().put("targetWidgetClassName", boundingWidget.getClass().getName());
        event.getDropDetails().put("dropType", "DropToTabsheetBody");
        event.getDropDetails().put("targetWidgetAbsoluteLeft", boundingWidget.getAbsoluteLeft());
        event.getDropDetails().put("targetWidgetAbsoluteTop", boundingWidget.getAbsoluteTop());
        event.getDropDetails().put("targetWidgetOffsetWidth", boundingWidget.getOffsetWidth());
        event.getDropDetails().put("targetWidgetOffsetHeight", boundingWidget.getOffsetHeight());

        int x0 = boundingWidget.getAbsoluteLeft();
        int y0 = boundingWidget.getAbsoluteTop();
        int dx = boundingWidget.getOffsetWidth();
        int dy = boundingWidget.getOffsetHeight();

        int docPrcnt = 30;
        double docX = dx * docPrcnt / 100;
        double docY = dy * docPrcnt / 100;
        double d = 1;

        Vector mousePos = Vector.valueOf(mouseX, mouseY);

        Integer side = GeomUtils.findDockSide(x0, y0, dx, dy, docX, docY, mousePos);
        //VConsole.log("updateDropDetails: finded dock side = " + side + ", old dock side = " + dockSide);
        if (side != null) {
            double _x = 0, _y = 0, _w = 0, _h = 0;

            if (side == Side.LEFT) {
                _x = d;
                _y = d;
                _w = docX - d;
                _h = dy - 2 * d;
            } else if (side == Side.TOP) {
                _x = d;
                _y = d;
                _w = dx - 2 * d;
                _h = docY - d;
            } else if (side == Side.RIGHT) {
                _x = dx - docX;
                _y = d;
                _w = docX - d;
                _h = dy - 2 * d;
            } else if (side == Side.BOTTOM) {
                _x = d;
                _y = dy - docY;
                _w = dx - 2 * d;
                _h = docY - d;
            } else if (side == Side.CENTER) {
                _x = d;
                _y = d;
                _w = dx - 2 * d;
                _h = dy - 2 * d;
            } else
                return false;

            _x = x0 + _x;
            _y = y0 + _y;

            if (dockZone1 == null) {
                dockZone1 = DOM.createDiv();
                dockZone2 = DOM.createDiv();
                dockZone3 = DOM.createDiv();
                dockZone4 = DOM.createDiv();
            }

            //VConsole.log("updateDropDetails: x=" + _x + "; y=" + _y + "; w=" + _w + "; h=" + _h);

            if (side != dockSide) {
                //VConsole.log("updateDropDetails: dock side will be updated");
                int l = 3;
                String style1 = "position: absolute; left: " + _x + "px; top: " + _y + "px; width: " + _w
                        + "px; height: " + l + "px; background-image: url(" + baseURL
                        + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;";
                dockZone1.setAttribute("style", style1);

                String style2 = "position: absolute; left: " + _x + "px; top: " + (_y + _h - l) + "px; width: "
                        + _w + "px; height: " + l + "px; background-image: url(" + baseURL
                        + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;";
                dockZone2.setAttribute("style", style2);

                String style3 = "position: absolute; left: " + _x + "px; top: " + _y + "px; width: " + l
                        + "px; height: " + _h + "px; background-image: url(" + baseURL
                        + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;";
                dockZone3.setAttribute("style", style3);

                String style4 = "position: absolute; left: " + (_x + _w - l) + "px; top: " + _y + "px; width: "
                        + l + "px; height: " + _h + "px; background-image: url(" + baseURL
                        + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;";
                dockZone4.setAttribute("style", style4);

                //setStyleName(dockZone, "v-etot-sukin-syn");
                //dockZoneContainer = boundingWidget.getElement();
                dockZoneContainer = RootPanel.get().getElement();
                DOM.appendChild(dockZoneContainer, dockZone1);
                DOM.appendChild(dockZoneContainer, dockZone2);
                DOM.appendChild(dockZoneContainer, dockZone3);
                DOM.appendChild(dockZoneContainer, dockZone4);

                dockSide = side;
            }
        }
    }

    return true;
}

From source file:org.semanticsoft.vaaclipse.widgets.client.ui.stackwidget.VStackWidget.java

License:Open Source License

/**
  * Updates the drop details while dragging. This is needed to ensure client
  * side criterias can validate the drop location.
  * /*ww w.  j av  a2s  .  c o m*/
  * @param widget
  *            The container which we are hovering over
  * @param event
  *            The drag event
  */
@Override
public void updateDropDetails(VDragEvent event) {
    if (!updateRegion(event))
        return;

    Element element = event.getElementOver();
    Widget targetWidget = Util.findWidget(element, null);

    //--
    if (tabBar.getElement().isOrHasChild(element)) {

        if (targetWidget == 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(targetWidget));

            // Add drop location
            HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(element,
                    Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), getTabLeftRightDropRatio());
            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:org.vaadin.addon.leaflet.client.LeafletMapConnector.java

License:Apache License

@Override
public void onStateChanged(final StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);
    if (map == null) {
        updateChildren = new ArrayList<ServerConnector>(getChildren());
        if (getState().customMapOptionsJson != null) {
            options = JSONParser.parseStrict(getState().customMapOptionsJson).isObject().getJavaScriptObject()
                    .cast();//www . ja  v a2s . c om
        } else {
            options = MapOptions.create();
        }
        if (getState().maxBounds != null) {
            options.setMaxBounds(toLeafletBounds(getState().maxBounds));
        }
        if (getState().center != null) {
            options.setCenter(getCenterFromState());
        } else {
            options.setCenter(LatLng.create(0, 0));
        }

        /*
         * See if CRS set. Maintain backwards compatability so that EPSG:3857
         * used if nothing specified.
         */
        if (getState().crsName != null) {
            options.setCrs(Crs.byName(getState().crsName));
        }

        if (getState().attributionPrefix == null) {
            options.setAttributionControl(false);
        }

        if (getState().minZoom != null) {
            options.setMinZoom(getState().minZoom);
        }
        if (getState().maxZoom != null) {
            options.setMaxZoom(getState().maxZoom);
        }

        double zoom = 15;
        if (getState().zoomLevel != null) {
            zoom = getState().zoomLevel;
        }
        options.setZoom(zoom);
        map = Map.create(getWidget().getElement().getFirstChildElement(), options);
        if (getState().attributionPrefix != null) {
            map.getAttributionControl().setPrefix(getState().attributionPrefix);
        }

        if (getState().zoomToExtent != null) {
            Bounds b = getState().zoomToExtent;
            LatLng northEast = LatLng.create(b.getNorthEastLat(), b.getNorthEastLon());
            LatLng southWest = LatLng.create(b.getSouthWestLat(), b.getSouthWestLon());
            map.fitBounds(LatLngBounds.create(southWest, northEast));
        }

        map.addClickListener(new ClickListener() {
            public void onClick(MouseEvent event) {
                if (hasEventListener("click")) {

                    // Add mouse details
                    MouseEventDetails details = MouseEventDetailsBuilder
                            .buildMouseEventDetails(event.getNativeEvent(), getWidget().getElement());

                    rpc.onClick(new Point(event.getLatLng().getLatitude(), event.getLatLng().getLongitude()),
                            details);
                }
            }
        });

        map.addContextMenuListener(new ContextMenuListener() {
            @Override
            public void onContextMenu(MouseEvent event) {
                if (hasEventListener("contextmenu")) {
                    // Add mouse details
                    MouseEventDetails details = MouseEventDetailsBuilder
                            .buildMouseEventDetails(event.getNativeEvent(), getWidget().getElement());

                    rpc.onContextMenu(
                            new Point(event.getLatLng().getLatitude(), event.getLatLng().getLongitude()),
                            details);
                }
            }
        });

        MoveEndListener moveEndListener = new MoveEndListener() {

            @Override
            public void onMoveEnd(Event event) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        reportViewPortToServer();
                    }
                });
            }
        };

        map.addMoveEndListener(moveEndListener);

        if (getState().width != null && !getState().width.contains("%")) {
            // fixed size for the leaflet map, report size manually to the 
            // server
            reportViewPortToServer();
        }

    } else {
        // extent, zoom etc, must not be updated here, see client rpc...
    }

    updateChildrens();

}