Example usage for com.vaadin.client ComponentConnector getLayoutManager

List of usage examples for com.vaadin.client ComponentConnector getLayoutManager

Introduction

In this page you can find the example usage for com.vaadin.client ComponentConnector getLayoutManager.

Prototype

public LayoutManager getLayoutManager();

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.tableshared.TableWidgetDelegate.java

License:Apache License

public void scheduleLayoutForChildWidgets() {
    if (table.scrollBody != null) {
        // Fix for #VAADIN-12970, relayout cell widgets
        // Haulmont API
        ComponentConnector connector = Util.findConnectorFor(table);
        // may be null if we switch tabs fast
        if (connector != null) {
            LayoutManager lm = connector.getLayoutManager();

            for (Widget w : table.scrollBody) {
                HasWidgets row = (HasWidgets) w;
                for (Widget child : row) {
                    ComponentConnector childConnector = Util.findConnectorFor(child);
                    if (childConnector != null && childConnector.getConnectorId() != null) {
                        if (childConnector instanceof ManagedLayout
                                || childConnector instanceof AbstractLayoutConnector) {
                            lm.setNeedsMeasure(childConnector);
                        }/*from ww  w.j  a v a 2s.c o  m*/
                    }
                }
            }
        }
    }
}

From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.connector.ViewportConnector.java

License:Open Source License

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
    final ViewportWidget viewport = getWidget();
    final List<ComponentConnector> children = getChildComponents();
    final List<ComponentConnector> oldChildren = event.getOldChildren();
    int index = 0;
    for (final ComponentConnector cc : children) {
        final Widget w = cc.getWidget();
        if (w.getParent() != viewport) {
            viewport.insert(w, index);/*  ww w .j a v  a2  s. c o  m*/
            getLayoutManager().addElementResizeListener(w.getElement(), childCenterer);
            w.getElement().getStyle().setOpacity(0d);
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                @Override
                public void execute() {
                    if (getWidget().getVisibleChild() != cc.getWidget()) {
                        w.getElement().getStyle().setDisplay(Display.NONE);
                    }
                    w.getElement().getStyle().clearOpacity();
                }
            });

        }
        ++index;
    }

    oldChildren.removeAll(children);
    for (final ComponentConnector cc : oldChildren) {
        cc.getLayoutManager().removeElementResizeListener(cc.getWidget().getElement(), childCenterer);
        getWidget().removeChild(cc.getWidget());
    }
}

From source file:info.magnolia.ui.vaadin.gwt.client.richtext.TextAreaStretcherConnector.java

License:Open Source License

private void registerSizeChangeListeners() {
    final LayoutManager lm = getParent().getLayoutManager();
    final UIConnector ui = getConnection().getUIConnector();
    getParent().addStateChangeHandler(textAreaSizeHandler);
    lm.addElementResizeListener(ui.getWidget().getElement(), windowResizeListener);

    final ComponentConnector formConnector = Util.findConnectorFor(this.form);
    if (formConnector != null) {
        formConnector.getLayoutManager().addElementResizeListener(this.form.getElement(), formResizeListener);
    }/*  www  .  j a  va  2  s.c  o m*/
}

From source file:info.magnolia.ui.vaadin.gwt.client.richtext.TextAreaStretcherConnector.java

License:Open Source License

private void unregisterSizeChangeListeners() {
    final LayoutManager lm = getParent().getLayoutManager();
    final UIConnector ui = getConnection().getUIConnector();
    if (ui != null) {
        getParent().removeStateChangeHandler(textAreaSizeHandler);
        lm.removeElementResizeListener(ui.getWidget().getElement(), windowResizeListener);
    }/*from w  w  w .ja  v  a  2  s. c  om*/

    final ComponentConnector formConnector = Util.findConnectorFor(this.form);
    if (formConnector != null) {
        formConnector.getLayoutManager().removeElementResizeListener(this.form.getElement(),
                formResizeListener);
    }
}

From source file:org.vaadin.addons.portallayout.gwt.client.portal.connection.PortalLayoutConnector.java

License:Apache License

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
    final List<ComponentConnector> children = getChildComponents();
    final List<ComponentConnector> oldChildren = event.getOldChildren();
    oldChildren.removeAll(children);/*from  w  ww .  j  a  v a 2 s .  c  om*/
    headerConnectors.clear();
    for (final ComponentConnector cc : oldChildren) {
        final PortletConnector pc = PortalLayoutUtil.getPortletConnectorForContent(cc);
        if (pc != null) {
            view.removePortlet(pc.getPortletChrome());
        }
    }

    final Iterator<ComponentConnector> it = children.iterator();
    while (it.hasNext()) {
        final ComponentConnector cc = it.next();
        if (getState().contentToPortlet.get(cc) != null) {
            final PortletConnector pc = (PortletConnector) getState().contentToPortlet.get(cc);
            final PortletChrome portletWidget = pc.getPortletChrome();
            cc.getLayoutManager().addElementResizeListener(portletWidget.getAssociatedSlot().getElement(),
                    slotResizeListener);
            getView().addPortlet(pc.getPortletChrome());
        } else {
            headerConnectors.add(cc);
        }
    }
}

From source file:org.vaadin.addons.portallayout.gwt.client.portal.strategy.StackHeightRedistributionStrategy.java

License:Apache License

@Override
public void redistributeHeights(PortalLayoutConnector portalConnector) {
    Profiler.enter("PLC.recalcHeight");
    Iterator<ComponentConnector> it = portalConnector.getCurrentChildren().iterator();
    List<ComponentConnector> relativeHeightPortlets = new ArrayList<ComponentConnector>();
    double totalPercentage = 0;
    int totalFixedHeightConsumption = 0;
    while (it.hasNext()) {
        ComponentConnector cc = it.next();
        PortletConnector portletConnector = PortalLayoutUtil.getPortletConnectorForContent(cc);
        if (portletConnector != null) {
            if (portletConnector.hasRelativeHeight()) {
                totalPercentage += Util.parseRelativeSize(portletConnector.getState().height);
                relativeHeightPortlets.add(cc);
            } else {
                PortletChrome portletWidget = portletConnector.getPortletChrome();
                totalFixedHeightConsumption += cc.getLayoutManager()
                        .getOuterHeight(portletWidget.getAssociatedSlot().getElement());
            }//from  www .  j a v a 2s.c o m
        }
    }
    if (totalPercentage > 0) {
        totalPercentage = Math.max(totalPercentage, 100);
        int totalPortalHeight = portalConnector.getLayoutManager()
                .getInnerHeight(portalConnector.getWidget().getElement());
        boolean isSpacing = portalConnector.getState().spacing;
        int spacingConsumption = 0;
        if (isSpacing && portalConnector.getView().getWidgetCount() > 0) {
            Element spacingEl = portalConnector.getWidget().getElement().getChild(0).cast();
            spacingConsumption += new ComputedStyle(spacingEl).getIntProperty("height")
                    * portalConnector.getView().getWidgetCount() - 1;
        }
        int reservedForRelativeSize = totalPortalHeight - totalFixedHeightConsumption - spacingConsumption;
        double ratio = reservedForRelativeSize / (double) totalPortalHeight * 100d;
        for (ComponentConnector cc : relativeHeightPortlets) {
            PortletConnector portletConnector = PortalLayoutUtil.getPortletConnectorForContent(cc);
            if (!portletConnector.isCollapsed()) {
                float percentageHeight = Util.parseRelativeSize(portletConnector.getState().height);
                double slotHeight = (percentageHeight / totalPercentage * ratio);
                int headerHeight = portletConnector.getPortletChrome().getHeader().getOffsetHeight();
                double headerHeightPercentage = (double) headerHeight / totalPortalHeight * 100d;
                String slotHeightStr = Math.max(slotHeight, headerHeightPercentage) + "%";
                portletConnector.getPortletChrome().getAssociatedSlot().setHeight(slotHeightStr);
            }
        }
    }
    Profiler.leave("PLC.recalcHeight");
}

From source file:org.vaadin.addons.portallayout.gwt.client.portlet.PortletConnector.java

License:Apache License

@Override
protected void extend(ServerConnector target) {
    ComponentConnector cc = (ComponentConnector) target;
    Widget w = cc.getWidget();/*w w w.  jav a 2 s .com*/
    portletChrome.setContentWidget(w);

    addStateChangeHandler("height", new HeightStateChangeListener());
    addStateChangeHandler("width", new WidthStateChangeHandler());

    PortletSlot slot = portletChrome.getAssociatedSlot();
    layoutManager = cc.getLayoutManager();
    layoutManager.addElementResizeListener(slot.getElement(), new SlotSizeChangeListener());
    layoutManager.addElementResizeListener(portletChrome.getElement(), new UndefinedHeightResizeListener());
    portletChrome.getHeader().setLayoutManager(layoutManager);
}