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:org.openxdata.sharedlib.client.view.FormRunnerView.java

private void setParentHeight(boolean increase, RuntimeWidgetWrapper rptWidget, int change) {
    Widget parent = rptWidget.getParent();
    while (parent != null) {
        if (parent instanceof RuntimeGroupWidget) {
            RuntimeWidgetWrapper wrapper = (RuntimeWidgetWrapper) ((RuntimeGroupWidget) parent).getParent()
                    .getParent();//ww w .  ja v a  2 s  .c  o  m
            int height = wrapper.getHeightInt();
            wrapper.setHeight((increase ? height + change : height - change) + OpenXdataConstants.UNITS);
        } else if (parent instanceof FormRunnerView)
            return;

        parent = parent.getParent();
    }
}

From source file:org.openxdata.sharedlib.client.view.FormRunnerView.java

private int getBottomYPos(RuntimeWidgetWrapper rptWidget) {
    int bottomYpos = rptWidget.getTopInt() + rptWidget.getHeightInt();

    Widget parent = rptWidget.getParent();
    while (parent != null) {
        if (parent instanceof RuntimeGroupWidget) {
            RuntimeWidgetWrapper wrapper = (RuntimeWidgetWrapper) ((RuntimeGroupWidget) parent).getParent()
                    .getParent();/*  w w  w .ja v  a2 s  . c o  m*/
            if (selectedPanel.getWidgetIndex(wrapper) != -1) {
                bottomYpos = wrapper.getTopInt() + wrapper.getHeightInt();
                break;
            }
        } else if (parent instanceof FormRunnerView)
            break;

        parent = parent.getParent();
    }

    return bottomYpos;
}

From source file:org.openxdata.sharedlib.client.widget.RuntimeGroupWidget.java

private void execute(Widget sender) {
    String binding = ((RuntimeWidgetWrapper) sender.getParent().getParent()).getBinding();

    if (binding.equalsIgnoreCase("search")) {
        RuntimeWidgetWrapper wrapper = getCurrentMultimediWrapper(sender);
        if (wrapper != null && wrapper.getExternalSource() != null)
            ;//FormUtil.searchExternal(wrapper.getExternalSource(),sender.getElement(),wrapper.getWrappedWidget().getElement(),null);
    } else if (binding.equalsIgnoreCase("submit"))
        ((FormRunnerView) getParent().getParent().getParent().getParent().getParent().getParent().getParent())
                .onSubmit();//from  ww w. j a  v  a 2  s .  co m
    else if (binding.equalsIgnoreCase("cancel"))
        ((FormRunnerView) getParent().getParent().getParent().getParent().getParent().getParent().getParent())
                .onCancel();
    else if (repeatQtnsDef != null) {
        if (binding.equalsIgnoreCase("addnew")) {
            RuntimeWidgetWrapper wrapper = (RuntimeWidgetWrapper) getParent().getParent();
            int y = getHeightInt();

            addNewRow(sender);

            editListener.onRowAdded(wrapper, getHeightInt() - y);
        } else if (binding.equalsIgnoreCase("remove")) {
            if (table.getRowCount() > 1) {//There should be atleast one row{
                RuntimeWidgetWrapper wrapper = (RuntimeWidgetWrapper) getParent().getParent();
                int y = getHeightInt();

                table.removeRow(table.getRowCount() - 1);
                Element node = dataNodes.get(dataNodes.size() - 1);
                node.getParentNode().removeChild(node);
                dataNodes.remove(node);
                if (btnAdd != null)
                    btnAdd.setEnabled(true);

                editListener.onRowRemoved(wrapper, y - getHeightInt());
            }

            RuntimeWidgetWrapper parent = (RuntimeWidgetWrapper) getParent().getParent();
            ValidationRule validationRule = parent.getValidationRule();
            if (validationRule != null)
                parent.getQuestionDef().setAnswer(table.getRowCount() + "");
        }
    } else {
        if (binding.equalsIgnoreCase("clear")) {
            RuntimeWidgetWrapper wrapper = getCurrentMultimediWrapper(sender);
            if (wrapper == null)
                return;

            if (wrapper.getWrappedWidget() instanceof Image
                    && (((Image) wrapper.getWrappedWidget()).getUrl() == null
                            || ((Image) wrapper.getWrappedWidget()).getUrl().trim().length() == 0))
                return;
            if (wrapper.getWrappedWidget() instanceof HTML && !wrapper.getWrappedWidget().isVisible())
                return;

            if (!Window.confirm(constants.deleteItemPrompt()))
                return;

            QuestionDef questionDef = wrapper.getQuestionDef();
            if (questionDef != null)
                questionDef.setAnswer(null);

            if (wrapper.getWrappedWidget() instanceof Image) {
                image = (Image) wrapper.getWrappedWidget();
                image.setUrl(null);
                html = null;
            } else if (wrapper.getWrappedWidget() instanceof Label)
                ((Label) wrapper.getWrappedWidget()).setText(constants.noSelection());
            else {
                html = (HTML) wrapper.getWrappedWidget();
                html.setHTML(constants.clickToPlay());
                html.setVisible(false);
                image = null;
            }
            return;
        } else if (binding.equalsIgnoreCase("browse")) {
            RuntimeWidgetWrapper wrapper = getCurrentMultimediWrapper(sender);
            if (wrapper == null)
                return;

            if (wrapper.getWrappedWidget() instanceof Image)
                image = (Image) wrapper.getWrappedWidget();
            else
                html = (HTML) wrapper.getWrappedWidget();

            String xpath = wrapper.getBinding();
            if (!xpath.startsWith(formDef.getBinding()))
                xpath = "/" + formDef.getBinding() + "/" + wrapper.getBinding();

            String contentType = "&contentType=video/3gpp";
            contentType += "&name=" + wrapper.getQuestionDef().getBinding() + ".3gp";

            //TODO What if the multimedia url suffix already has a ?
            String url = FormUtil.getMultimediaUrl() + "?formId=" + formDef.getId() + "&xpath=" + xpath
                    + contentType + "&time=" + new java.util.Date().getTime();
            OpenFileDialog dlg = new OpenFileDialog(this, url);
            dlg.center();
        }
    }
}

From source file:org.openxdata.sharedlib.client.widget.RuntimeGroupWidget.java

private RuntimeWidgetWrapper getCurrentMultimediWrapper(Widget sender) {
    RuntimeWidgetWrapper button = (RuntimeWidgetWrapper) sender.getParent().getParent();
    for (int index = 0; index < selectedPanel.getWidgetCount(); index++) {
        RuntimeWidgetWrapper widget = (RuntimeWidgetWrapper) selectedPanel.getWidget(index);
        Widget wrappedWidget = widget.getWrappedWidget();
        if (wrappedWidget instanceof Image
                || wrappedWidget instanceof HTML /*|| wrappedWidget instanceof Label*/) {
            String binding = widget.getBinding();
            if (binding != null && binding.equalsIgnoreCase(button.getParentBinding()))
                return widget;
        }//from w w w  .  j  av  a  2s. co  m
    }
    return null;
}

From source file:org.pentaho.gwt.widgets.client.tabs.AlwaysVisibleDeckPanel.java

License:Open Source License

protected void moveOffscreen(Widget w) {
    if (w.getElement() == null || w.getElement().getParentElement() == null) { // old active widget was removed.
        return;/*from  w ww .j a va2  s .c  o m*/
    }

    if (w.getParent().getOffsetWidth() > 0 && w.getParent().getOffsetHeight() > 0) {
        int width = w.getElement().getParentElement().getOffsetWidth();
        int height = w.getElement().getParentElement().getOffsetHeight();

        // don't let the switching between relative and absolute positioning modify our size.
        // force the size with inline styles, we'll set it back to 100% when we show it again
        w.getElement().getParentElement().getStyle().setProperty("width", width + "px");
        w.getElement().getParentElement().getStyle().setProperty("height", height + "px");
    }

    w.getElement().getParentElement().getStyle().setProperty("position", "absolute");
    w.getElement().getParentElement().getStyle().setProperty("left", "-5000px");
}

From source file:org.rebioma.client.TableWidget.java

License:Apache License

/**
 * /*from w  w w.  ja  v a  2 s  . c  o m*/
 * Gets the row that the column widget w is in. (Gets the index of its parent
 * in context of the grandparent)
 * 
 * @param w: is the Column widget in which the row it is in should be returned
 * @return the row of w. Returns -1 if an invalid call is made to getRowIndex.
 */
public int getRowIndex(Widget w) {
    Widget rowParent = w.getParent();
    if (rowParent != null) {
        Widget tempGrandParent = rowParent.getParent();
        return table.getWidgetIndex(tempGrandParent);
    } else {
        return -1;
    }
}

From source file:org.rest.client.ui.desktop.MenuItemViewImpl.java

License:Apache License

private void maybeRemoveItemFromParent(Widget item) {
    if (item instanceof MenuItemView) {
        MenuItemView _item = (MenuItemView) item;
        if (_item.getParentItem() != null) {
            _item.remove();//w ww .j  a va 2 s .  co  m
        }
    } else {
        if (item.getParent() != null) {
            item.removeFromParent();
        }
    }
}

From source file:org.rstudio.core.client.widget.ToolbarButton.java

License:Open Source License

protected Toolbar getParentToolbar() {
    Widget parent = getParent();
    while (parent != null) {
        if (parent instanceof Toolbar)
            return (Toolbar) parent;
        parent = parent.getParent();
    }/*from   www.j  a  v a 2  s  .  c om*/

    return null;
}

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  . ja v a 2  s.co  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

private VExtendedVerticalLayout findOuterArea(Widget w) {
    if (w instanceof VExtendedVerticalLayout) {
        //VConsole.log("VExtendedVerticalLayout finded in parent hierarchy");
        VExtendedVerticalLayout bl = (VExtendedVerticalLayout) w;
        final String type = bl.getVariableValue(E4_ELEMENT_TYPE);
        if (type != null && ("area".equals(type) || "perspective".equals(type) || "window".equals(type))) {
            //VConsole.log("VExtendedVerticalLayout finded in parent hierarchy with type = " + type);
            return bl;
        }/*from w  w w  .  j a va2 s .c o m*/
    }

    if (w.getParent() != null)
        return findOuterArea(w.getParent());
    else
        return null;
}