Example usage for com.google.gwt.user.client.ui Widget getParent

List of usage examples for com.google.gwt.user.client.ui Widget getParent

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget getParent.

Prototype

public Widget getParent() 

Source Link

Document

Gets this widget's parent panel.

Usage

From source file:com.vaadin.client.ComponentLocator.java

License:Apache License

/**
 * Finds the first widget in the hierarchy (moving upwards) that implements
 * SubPartAware. Returns the SubPartAware implementor or null if none is
 * found./* w  ww. j  a  va2s .  co  m*/
 * 
 * @param w
 *            The widget to start from. This is returned if it implements
 *            SubPartAware.
 * @return The first widget (upwards in hierarchy) that implements
 *         SubPartAware or null
 */
private Widget findSubPartAwareParentWidget(Widget w) {

    while (w != null) {
        if (w instanceof SubPartAware) {
            return w;
        }
        w = w.getParent();
    }
    return null;
}

From source file:com.vaadin.client.renderers.HierarchyRenderer.java

License:Apache License

/**
 * Decides whether the element was rendered by {@link HierarchyRenderer}
 *//*  ww w.  jav  a  2s. c  o m*/
public static boolean isElementInHierarchyWidget(Element element) {
    Widget w = WidgetUtil.findWidget(element, null);

    while (w != null) {
        if (w instanceof HierarchyItem) {
            return true;
        }
        w = w.getParent();
    }

    return false;
}

From source file:com.vaadin.client.ui.dd.VaaclipseDragAndDropManager.java

License:Apache License

public VDropHandler findDragTarget(com.google.gwt.dom.client.Element element) {

    try {/*from w  w w . j a v a2 s .  c  o  m*/
        Widget w = Util.findWidget((com.google.gwt.user.client.Element) element, null);
        if (w == null) {
            return null;
        }

        ComponentConnector dragSource = currentDrag.getTransferable().getDragSource();

        if (dragSource != null && dragSource.getWidget() instanceof VDDTabSheet) {
            while (!(w instanceof VDDTabSheet)) {
                w = w.getParent();
                if (w == null) {
                    break;
                }
            }
        } else {
            while (!(w instanceof VHasDropHandler)) {
                w = w.getParent();
                if (w == null) {
                    break;
                }
            }
        }

        if (w == null) {
            return null;
        } else {
            VDropHandler dh = ((VHasDropHandler) w).getDropHandler();
            return dh;
        }
    } catch (Exception e) {
        return null;
    }

}

From source file:com.vaadin.client.ui.dd.VDragAndDropManager.java

License:Apache License

/**
 * First seeks the widget from this element, then iterates widgets until one
 * implement HasDropHandler. Returns DropHandler from that.
 * //  www  .ja v  a 2  s .c o m
 * @param element
 * @return
 */
protected VDropHandler findDragTarget(Element element) {
    try {
        Widget w = WidgetUtil.findWidget(element, null);
        if (w == null) {
            return null;
        }
        while (!(w instanceof VHasDropHandler) || !isDropEnabled((VHasDropHandler) w)) {
            w = w.getParent();
            if (w == null) {
                break;
            }
        }
        if (w == null) {
            return null;
        } else {
            VDropHandler dh = ((VHasDropHandler) w).getDropHandler();
            return dh;
        }

    } catch (Exception e) {
        // ApplicationConnection.getConsole().log(
        // "FIXME: Exception when detecting drop handler");
        // e.printStackTrace();
        return null;
    }

}

From source file:com.vaadin.client.ui.dd.VTargetInSubtree.java

License:Apache License

@Override
protected boolean accept(VDragEvent drag, UIDL configuration) {

    VTree tree = (VTree) VDragAndDropManager.get().getCurrentDropHandler().getConnector().getWidget();
    TreeNode treeNode = tree.getNodeByKey((String) drag.getDropDetails().get("itemIdOver"));
    if (treeNode != null) {
        Widget parent2 = treeNode;
        int depth = configuration.getIntAttribute("depth");
        if (depth < 0) {
            depth = Integer.MAX_VALUE;
        }//from w w w .j ava2  s. c o m
        final String searchedKey = configuration.getStringAttribute("key");
        for (int i = 0; i <= depth && parent2 instanceof TreeNode; i++) {
            if (searchedKey.equals(((TreeNode) parent2).key)) {
                return true;
            }
            // panel -> next level node
            parent2 = parent2.getParent().getParent();
        }
    }

    return false;
}

From source file:com.vaadin.client.ui.VCssLayout.java

License:Apache License

/**
 * For internal use only. May be removed or replaced in the future.
 *///  w  w  w .  jav  a  2  s  . c o  m
public void addOrMove(Widget child, int index) {
    Profiler.enter("VCssLayout.addOrMove");
    if (child.getParent() == this) {
        Profiler.enter("VCssLayout.addOrMove getWidgetIndex");
        int currentIndex = getWidgetIndex(child);
        Profiler.leave("VCssLayout.addOrMove getWidgetIndex");
        if (index == currentIndex) {
            Profiler.leave("VCssLayout.addOrMove");
            return;
        }
    } else if (index == getWidgetCount()) {
        // optimized path for appending components - faster especially for
        // initial rendering
        Profiler.enter("VCssLayout.addOrMove add");
        add(child);
        Profiler.leave("VCssLayout.addOrMove add");
        Profiler.leave("VCssLayout.addOrMove");
        return;
    }
    Profiler.enter("VCssLayout.addOrMove insert");
    insert(child, index);
    Profiler.leave("VCssLayout.addOrMove insert");
    Profiler.leave("VCssLayout.addOrMove");
}

From source file:com.vaadin.client.ui.VCustomLayout.java

License:Apache License

/** Update caption for given widget */
public void updateCaption(ComponentConnector paintable) {
    Widget widget = paintable.getWidget();
    if (widget.getParent() != this) {
        // Widget has not been added because the location was not found
        return;//  w  ww  .j a v a2  s. com
    }
    VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget);
    if (VCaption.isNeeded(paintable.getState())) {
        if (wrapper == null) {
            // Add a wrapper between the layout and the child widget
            final String loc = getLocation(widget);
            super.remove(widget);
            wrapper = new VCaptionWrapper(paintable, client);
            super.add(wrapper, locationToElement.get(loc));
            childWidgetToCaptionWrapper.put(widget, wrapper);
        }
        wrapper.updateCaption();
    } else {
        if (wrapper != null) {
            // Remove the wrapper and add the widget directly to the layout
            final String loc = getLocation(widget);
            super.remove(wrapper);
            super.add(widget, locationToElement.get(loc));
            childWidgetToCaptionWrapper.remove(widget);
        }
    }
}

From source file:com.vaadin.client.ui.VRichTextArea.java

License:Apache License

private ShortcutActionHandlerOwner getShortcutHandlerOwner() {
    if (hasShortcutActionHandler == null) {
        Widget parent = getParent();
        while (parent != null) {
            if (parent instanceof ShortcutActionHandlerOwner) {
                break;
            }// w ww.j ava2s  . co  m
            parent = parent.getParent();
        }
        hasShortcutActionHandler = (ShortcutActionHandlerOwner) parent;
    }
    return hasShortcutActionHandler;
}

From source file:com.vaadin.client.ui.VWindow.java

License:Apache License

@Override
public boolean onEventPreview(Event event) {
    if (dragging) {
        onDragEvent(event);//from   ww  w.  j  a v  a 2s .c  om
        return false;
    } else if (resizing) {
        onResizeEvent(event);
        return false;
    }

    // TODO This is probably completely unnecessary as the modality curtain
    // prevents events from reaching other windows and any security check
    // must be done on the server side and not here.
    // The code here is also run many times as each VWindow has an event
    // preview but we cannot check only the current VWindow here (e.g.
    // if(isTopMost) {...}) because PopupPanel will cause all events that
    // are not cancelled here and target this window to be consume():d
    // meaning the event won't be sent to the rest of the preview handlers.

    if (getTopmostWindow() != null && getTopmostWindow().vaadinModality) {
        // Topmost window is modal. Cancel the event if it targets something
        // outside that window (except debug console...)
        if (DOM.getCaptureElement() != null) {
            // Allow events when capture is set
            return true;
        }

        final Element target = event.getEventTarget().cast();
        if (!DOM.isOrHasChild(getTopmostWindow().getElement(), target)) {
            // not within the modal window, but let's see if it's in the
            // debug window
            Widget w = WidgetUtil.findWidget(target, null);
            while (w != null) {
                if (w instanceof VDebugWindow) {
                    return true; // allow debug-window clicks
                } else if (ConnectorMap.get(client).isConnector(w)) {
                    return false;
                }
                w = w.getParent();
            }
            return false;
        }
    }
    return true;
}

From source file:com.vaadin.client.Util.java

License:Apache License

/**
 * Helper method to find the nearest parent paintable instance by traversing
 * the DOM upwards from given element.//from   w w  w.  j  a  v a  2  s. c o  m
 * 
 * @param element
 *            the element to start from
 */
public static ComponentConnector findPaintable(ApplicationConnection client, Element element) {
    Widget widget = Util.findWidget(element, null);
    ConnectorMap vPaintableMap = ConnectorMap.get(client);
    while (widget != null && !vPaintableMap.isConnector(widget)) {
        widget = widget.getParent();
    }
    return vPaintableMap.getConnector(widget);

}