Example usage for com.vaadin.client Util findWidget

List of usage examples for com.vaadin.client Util findWidget

Introduction

In this page you can find the example usage for com.vaadin.client Util findWidget.

Prototype

@Deprecated
public static <T> T findWidget(Element element, Class<? extends Widget> class1) 

Source Link

Document

Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.

Usage

From source file:info.magnolia.ui.vaadin.gwt.client.applauncher.widget.AppLauncherUtil.java

License:Open Source License

public static AppLauncherView getView() {
    return Util.findWidget(JQueryWrapper.select(".v-app-launcher").get(0), AppLauncherViewImpl.class);
}

From source file:info.magnolia.ui.vaadin.gwt.client.form.widget.FormViewImpl.java

License:Open Source License

@Override
public void setContent(Widget contentWidget) {
    if (contentWidget instanceof MagnoliaTabSheetView) {
        if (tabSheet != null) {
            remove(tabSheet);//  w  ww  .  j a v a 2  s .  c o m
        }

        this.tabSheet = (MagnoliaTabSheetView) contentWidget;
        tabSheet.addTabSetChangedHandler(new TabSetChangedEvent.Handler() {
            @Override
            public void onTabSetChanged(TabSetChangedEvent event) {
                final List<MagnoliaTabWidget> tabs = event.getTabSheet().getTabs();
                formTabs.clear();
                for (final MagnoliaTabWidget tab : tabs) {
                    if (tab instanceof FormTabWidget) {
                        formTabs.add((FormTabWidget) tab);
                    }
                }
            }
        });

        tabSheet.addActiveTabChangedHandler(new ActiveTabChangedEvent.Handler() {
            @Override
            public void onActiveTabChanged(ActiveTabChangedEvent event) {
                // Focus the first field on the form of the current tab.
                if (!hasErrors) {
                    if (!event.isShowingAllTabs()) {
                        focusFirstFieldInTab((FormTabWidget) event.getTab());
                    } else {
                        focusFirstFieldInTab(formTabs.get(0));
                    }
                }

                // Keep track of last focused field by adding focus handlers to every field.
                lastFocused = null;
                if (!event.isShowingAllTabs()) {
                    setFieldFocusHandler((FormTabWidget) event.getTab());
                } else {
                    for (FormTabWidget tab : formTabs) {
                        setFieldFocusHandler(tab);
                    }
                }
            }

            private void focusFirstFieldInTab(FormTabWidget tab) {
                FormFieldWrapper firstField = tab.getFields().get(0);
                firstField.focusField();
            }

            private void setFieldFocusHandler(FormTabWidget tab) {
                final List<FormFieldWrapper> fields = tab.getFields();
                for (final FormFieldWrapper field : fields) {
                    field.addFocusHandler(new FocusHandler() {
                        @Override
                        public void onFocus(FocusEvent event) {
                            final Element target = event.getRelativeElement().cast();
                            lastFocused = Util.findWidget(target, FormFieldWrapper.class);
                        }
                    });
                }
            }
        });
        add(tabSheet.asWidget(), contentEl);
    }
}

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;
    }//ww w .  j  ava 2  s.c  om

    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.
  * /*from   w  w w  .j a  va 2 s .  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());
}