Example usage for com.google.gwt.query.client GQuery get

List of usage examples for com.google.gwt.query.client GQuery get

Introduction

In this page you can find the example usage for com.google.gwt.query.client GQuery get.

Prototype

public Element get(int i) 

Source Link

Document

Return the ith element matched.

Usage

From source file:cu.softel.integro.client.shared.tooltip.TooltipImpl.java

License:Apache License

private void doShowTooltip() {
    GQuery tooltip = getTip();

    OffsetInfo oi = OffsetInfo.from($element);
    long actualWidth = tooltip.get(0).getOffsetWidth();
    long actualHeight = tooltip.get(0).getOffsetHeight();
    long finalTop = -1;
    long finalLeft = -1;
    String placementClass = null;

    switch (getPlacement()) {
    case BOTTOM://  w w w. ja  v  a2 s  .c  om
        finalTop = oi.top + oi.height;
        finalLeft = oi.left + oi.width / 2 - actualWidth / 2;
        placementClass = style.bottom();
        break;
    case TOP:
        finalTop = oi.top - actualHeight;
        finalLeft = oi.left + oi.width / 2 - actualWidth / 2;
        placementClass = style.top();
        break;
    case LEFT:
        finalTop = oi.top + oi.height / 2 - actualHeight / 2;
        finalLeft = oi.left - actualWidth;
        placementClass = style.left();
        break;
    case RIGHT:
        finalTop = oi.top + oi.height / 2 - actualHeight / 2;
        finalLeft = oi.left + oi.width;
        placementClass = style.right();
        break;
    }

    Offset additionalOffset = getAdditionalOffset();
    if (additionalOffset != null) {
        finalTop += additionalOffset.top;
        finalLeft += additionalOffset.left;
    }

    tooltip.offset((int) finalTop, (int) finalLeft);
    tooltip.addClass(placementClass).addClass(style.in());

    if (options.getTrigger() == TooltipTrigger.CLICK && options.isAutoClose()) {
        $(document).delay(1, new Function() {
            @Override
            public void f() {
                $(document).click(autocloseFunction);
            }
        });
    }
}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

/**
 * convert a relative position to a absolute position and vice versa.
 *
 * @param absolute  if true the position is convert to an absolute position, if
 *                  false it is convert in a relative position
 * @param aPosition position to convert//  w  ww . j av  a 2s  .com
 * @return
 */
public Offset convertPositionTo(boolean absolute, Offset aPosition) {
    int mod = absolute ? 1 : -1;
    GQuery scroll = getScrollParent();
    boolean scrollIsRootNode = isRootNode(scroll.get(0));

    int top = aPosition.top + relativeOffset.top * mod + parentOffset.top * mod
            - ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
                    : scrollIsRootNode ? 0 : scroll.scrollTop()) * mod;

    int left = aPosition.left + relativeOffset.left * mod + parentOffset.left * mod
            - ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
                    : scrollIsRootNode ? 0 : scroll.scrollLeft()) * mod;

    return new Offset(left, top);

}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

private void calculateContainment() {
    String containmentAsString = options.getContainment();
    int[] containmentAsArray = options.getContainmentAsArray();
    GQuery $containement = options.getContainmentAsGQuery();

    if (containmentAsArray == null && containmentAsString == null && $containement == null) {
        containment = null;/* www .  j a v  a  2  s  .co  m*/
        return;
    }

    if (containmentAsArray != null) {
        containment = containmentAsArray;
        return;
    }

    if (containmentAsString != null) {
        if ("window".equals(containmentAsString)) {
            containment = new int[] { 0 /*- relativeOffset.left - parentOffset.left*/,
                    0 /*- relativeOffset.top - parentOffset.top*/,
                    Window.getClientWidth() - helperDimension.getWidth() - margin.left,
                    Window.getClientHeight() - helperDimension.getHeight() - margin.top };

            return;
        }

        if ("parent".equals(containmentAsString)) {
            $containement = $(helper.get(0).getParentElement());
        } else if ("document".equals(containmentAsString)) {
            $containement = $("body");
        } else {
            $containement = $(containmentAsString);
        }
    }

    Element ce = $containement.get(0);
    if (ce == null) {
        return;
    }

    containment = impl.calculateContainment(this, $containement.offset(), ce,
            (!"hidden".equals($containement.css("overflow"))));

}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

private Offset generatePosition(GqEvent e, boolean initPosition) {

    GQuery scroll = getScrollParent();
    boolean scrollIsRootNode = isRootNode(scroll.get(0));

    int pageX = e.pageX();
    int pageY = e.pageY();

    if (!initPosition) {
        if (containment != null && containment.length == 4) {
            if (e.pageX() - offsetClick.left < containment[0]) {
                pageX = containment[0] + offsetClick.left;
            }//w  ww .ja v a 2s . co m
            if (e.pageY() - offsetClick.top < containment[1]) {
                pageY = containment[1] + offsetClick.top;
            }
            if (e.pageX() - offsetClick.left > containment[2]) {
                pageX = containment[2] + offsetClick.left;
            }
            if (e.pageY() - offsetClick.top > containment[3]) {
                pageY = containment[3] + offsetClick.top;
            }
        }

        if (options.getGrid() != null) {
            int[] grid = options.getGrid();
            int roundedTop = originalEventPageY + Math.round((pageY - originalEventPageY) / grid[1]) * grid[1];
            int roundedLeft = originalEventPageX + Math.round((pageX - originalEventPageX) / grid[0]) * grid[0];

            if (containment != null && containment.length == 4) {
                boolean isOutOfContainment0 = roundedLeft - offsetClick.left < containment[0];
                boolean isOutOfContainment1 = roundedTop - offsetClick.top < containment[1];
                boolean isOutOfContainment2 = roundedLeft - offsetClick.left > containment[2];
                boolean isOutOfContainment3 = roundedTop - offsetClick.top > containment[3];

                pageY = !(isOutOfContainment1 || isOutOfContainment3) ? roundedTop
                        : (!isOutOfContainment1) ? roundedTop - grid[1] : roundedTop + grid[1];
                pageX = !(isOutOfContainment0 || isOutOfContainment2) ? roundedLeft
                        : (!isOutOfContainment0) ? roundedLeft - grid[0] : roundedLeft + grid[0];

            } else {
                pageY = roundedTop;
                pageX = roundedLeft;
            }

        }
    }

    int top = pageY - offsetClick.top - relativeOffset.top - parentOffset.top
            + ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
                    : scrollIsRootNode ? 0 : scroll.scrollTop());

    int left = pageX - offsetClick.left - relativeOffset.left - parentOffset.left
            + ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
                    : scrollIsRootNode ? 0 : scroll.scrollLeft());
    return new Offset(left, top);
}

From source file:gwtquery.plugins.draggable.client.impl.DraggableHandlerImpl.java

License:Apache License

public boolean resetParentOffsetPosition(GQuery helperOffsetParent) {
    return helperOffsetParent.get(0) == GQuery.body;
}

From source file:gwtquery.plugins.draggable.client.impl.DraggableHandlerImplIE.java

License:Apache License

@Override
public boolean resetParentOffsetPosition(GQuery helperOffsetParent) {
    return super.resetParentOffsetPosition(helperOffsetParent)
            || helperOffsetParent.get(0) == GQuery.document.cast();
}

From source file:gwtquery.plugins.draggable.client.impl.DraggableHandlerImplIE.java

License:Apache License

@Override
public void removeHelper(GQuery helper, HelperType helperType) {
    if (helperType == HelperType.CLONE) {
        // in IE, the clone helper has the same hashcode than the draggable
        // don't call remove method on it because all dragable's data will be cleared also.
        // TODO maybe add an issue in GQuery to discuss about this problem !
        //      problem comes maybe from GWT directly !
        Element helperElement = helper.get(0);
        helperElement.getParentNode().removeChild(helperElement);
    } else {//w  w w  .ja va2  s  .  c  om
        super.removeHelper(helper, helperType);
    }
}

From source file:gwtquery.plugins.draggable.client.plugins.ScrollPlugin.java

License:Apache License

public void onDrag(DraggableHandler handler, DragContext ctx, GqEvent e) {
    DraggableOptions options = handler.getOptions();
    Element draggableElement = ctx.getDraggable();
    GQuery scrollParent = handler.getHelperScrollParent();
    Element scrollParentElement = scrollParent.get(0);
    if (scrollParentElement == null) {
        return;//from  ww  w  . jav a 2  s .  com
    }

    AxisOption axis = options.getAxis();
    Offset overflowOffset = $(draggableElement).data(OVERFLOW_OFFSET_KEY, Offset.class);
    int scrollSensitivity = options.getScrollSensitivity();
    int scrollSpeed = options.getScrollSpeed();

    boolean scrolled = false;

    if (scrollParentElement != null && scrollParentElement != $(GQuery.document).get(0)
            && !"html".equalsIgnoreCase(scrollParentElement.getTagName())) {
        if (AxisOption.NONE == axis || AxisOption.Y_AXIS == axis) {
            // test if we have to scroll down...
            if ((overflowOffset.top + scrollParentElement.getOffsetHeight()) - e.pageY() < scrollSensitivity) {
                scrollParentElement.setScrollTop(scrollParentElement.getScrollTop() + scrollSpeed);
                scrolled = true;
                // test if we have to scroll up...
            } else if (e.pageY() - overflowOffset.top < scrollSensitivity) {
                scrollParentElement.setScrollTop(scrollParentElement.getScrollTop() - scrollSpeed);
                scrolled = true;
            }
        }

        if (AxisOption.NONE == axis || AxisOption.X_AXIS == axis) {
            // test if we have to scroll left...
            if ((overflowOffset.left + scrollParentElement.getOffsetWidth()) - e.pageX() < scrollSensitivity) {
                scrollParentElement.setScrollLeft(scrollParentElement.getScrollLeft() + scrollSpeed);
                scrolled = true;
                // test if we have to scroll right...
            } else if (e.pageX() - overflowOffset.left < scrollSensitivity) {
                scrollParentElement.setScrollLeft(scrollParentElement.getScrollLeft() - scrollSpeed);
                scrolled = true;
            }
        }

    } else {
        if (AxisOption.NONE == axis || AxisOption.Y_AXIS == axis) {
            if (e.pageY() - document.getScrollTop() < scrollSensitivity) {
                document.setScrollTop(document.getScrollTop() - scrollSpeed);
                scrolled = true;
            } else if (Window.getClientHeight() - (e.pageY() - document.getScrollTop()) < scrollSensitivity) {
                document.setScrollTop(document.getScrollTop() + scrollSpeed);
                scrolled = true;
            }
        }

        if (AxisOption.NONE == axis || AxisOption.X_AXIS == axis) {
            if (e.pageX() - document.getScrollLeft() < scrollSensitivity) {
                document.setScrollLeft(document.getScrollLeft() - scrollSpeed);
                scrolled = true;
            } else if (Window.getClientWidth() - (e.pageX() - document.getScrollLeft()) < scrollSensitivity) {
                document.setScrollLeft(document.getScrollLeft() + scrollSpeed);
                scrolled = true;
            }
        }

    }

    if (scrolled && DragAndDropManager.getInstance().isHandleDroppable(ctx)) {
        DragAndDropManager.getInstance().initialize(ctx, e);
    }

}

From source file:gwtquery.plugins.draggable.client.plugins.ScrollPlugin.java

License:Apache License

public void onStart(DraggableHandler handler, DragContext ctx, GqEvent e) {

    GQuery scrollParent = handler.getHelperScrollParent();
    Element scrollParentElement = scrollParent.get(0);
    if (scrollParentElement != null && scrollParentElement != $(GQuery.document).get(0)
            && !"html".equalsIgnoreCase(scrollParentElement.getTagName())) {
        Offset scrollParentOffset = scrollParent.offset();
        $(ctx.getDraggable()).data(OVERFLOW_OFFSET_KEY, scrollParentOffset);
    }//from ww  w .  ja  v  a2  s . co m
}

From source file:gwtquery.plugins.draggable.client.plugins.ZIndexPlugin.java

License:Apache License

public void onStart(DraggableHandler handler, DragContext ctx, GqEvent e) {
    GQuery $element = (handler.getOptions().getHelperType() == HelperType.ORIGINAL) ? $(ctx.getDraggable())
            : handler.getHelper();// w  w  w  .  ja  v  a 2s .  c o  m
    if ($element == null || $element.length() == 0) {
        return;
    }
    //String oldZIndex = $element.css(ZINDEX_CSS);
    String oldZIndex = getZIndex($element.get(0).getStyle());
    if (oldZIndex != null) {
        $element.data(OLD_ZINDEX_KEY, oldZIndex);
    }
    $element.css(ZINDEX_CSS, handler.getOptions().getZIndex().toString());

}