Example usage for com.google.gwt.user.client Window addResizeHandler

List of usage examples for com.google.gwt.user.client Window addResizeHandler

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window addResizeHandler.

Prototype

public static HandlerRegistration addResizeHandler(ResizeHandler handler) 

Source Link

Usage

From source file:com.vaadin.client.debug.internal.VDebugWindow.java

License:Apache License

/**
 * Called when the window is initialized.
 *//*from   ww  w  . j  av a  2 s  . com*/
public void init() {

    show();

    /*
     * Finalize initialization when all entry points have had the chance to
     * e.g. register new sections.
     */
    Scheduler.get().scheduleFinally(new ScheduledCommand() {
        @Override
        public void execute() {
            readStoredState();

            Window.addResizeHandler(new com.google.gwt.event.logical.shared.ResizeHandler() {

                Timer t = new Timer() {
                    @Override
                    public void run() {
                        applyPositionAndSize();
                    }
                };

                @Override
                public void onResize(ResizeEvent event) {
                    t.cancel();
                    // TODO less
                    t.schedule(1000);
                }
            });
        }
    });
}

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

License:Apache License

@Override
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
    getWidget().id = getConnectorId();/*  w ww  . ja  va  2 s.com*/
    boolean firstPaint = getWidget().connection == null;
    getWidget().connection = client;

    getWidget().immediate = getState().immediate;
    getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY);
    // this also implicitly removes old styles
    String styles = "";
    styles += getWidget().getStylePrimaryName() + " ";
    if (ComponentStateUtil.hasStyles(getState())) {
        for (String style : getState().styles) {
            styles += style + " ";
        }
    }
    if (!client.getConfiguration().isStandalone()) {
        styles += getWidget().getStylePrimaryName() + "-embedded";
    }
    getWidget().setStyleName(styles.trim());

    getWidget().makeScrollable();

    clickEventHandler.handleEventHandlerRegistration();

    // Process children
    int childIndex = 0;

    // Open URL:s
    boolean isClosed = false; // was this window closed?
    while (childIndex < uidl.getChildCount() && "open".equals(uidl.getChildUIDL(childIndex).getTag())) {
        final UIDL open = uidl.getChildUIDL(childIndex);
        final String url = client.translateVaadinUri(open.getStringAttribute("src"));
        final String target = open.getStringAttribute("name");
        if (target == null) {
            // source will be opened to this browser window, but we may have
            // to finish rendering this window in case this is a download
            // (and window stays open).
            Scheduler.get().scheduleDeferred(new Command() {
                @Override
                public void execute() {
                    VUI.goTo(url);
                }
            });
        } else if ("_self".equals(target)) {
            // This window is closing (for sure). Only other opens are
            // relevant in this change. See #3558, #2144
            isClosed = true;
            VUI.goTo(url);
        } else {
            String options;
            boolean alwaysAsPopup = true;
            if (open.hasAttribute("popup")) {
                alwaysAsPopup = open.getBooleanAttribute("popup");
            }
            if (alwaysAsPopup) {
                if (open.hasAttribute("border")) {
                    if (open.getStringAttribute("border").equals("minimal")) {
                        options = "menubar=yes,location=no,status=no";
                    } else {
                        options = "menubar=no,location=no,status=no";
                    }

                } else {
                    options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes";
                }

                if (open.hasAttribute("width")) {
                    int w = open.getIntAttribute("width");
                    options += ",width=" + w;
                }
                if (open.hasAttribute("height")) {
                    int h = open.getIntAttribute("height");
                    options += ",height=" + h;
                }

                Window.open(url, target, options);
            } else {
                open(url, target);
            }
        }
        childIndex++;
    }
    if (isClosed) {
        // We're navigating away, so stop the application.
        client.setApplicationRunning(false);
        return;
    }

    // Handle other UIDL children
    UIDL childUidl;
    while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) {
        String tag = childUidl.getTag().intern();
        if (tag == "actions") {
            if (getWidget().actionHandler == null) {
                getWidget().actionHandler = new ShortcutActionHandler(getWidget().id, client);
            }
            getWidget().actionHandler.updateActionMap(childUidl);
        } else if (tag == "notifications") {
            for (final Iterator<?> it = childUidl.getChildIterator(); it.hasNext();) {
                final UIDL notification = (UIDL) it.next();
                VNotification.showNotification(client, notification);
            }
        } else if (tag == "css-injections") {
            injectCSS(childUidl);
        }
    }

    if (uidl.hasAttribute("focused")) {
        // set focused component when render phase is finished
        Scheduler.get().scheduleDeferred(new Command() {
            @Override
            public void execute() {
                ComponentConnector connector = (ComponentConnector) uidl.getPaintableAttribute("focused",
                        getConnection());

                if (connector == null) {
                    // Do not try to focus invisible components which not
                    // present in UIDL
                    return;
                }

                final Widget toBeFocused = connector.getWidget();
                /*
                 * Two types of Widgets can be focused, either implementing
                 * GWT Focusable of a thinner Vaadin specific Focusable
                 * interface.
                 */
                if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) {
                    final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused;
                    toBeFocusedWidget.setFocus(true);
                } else if (toBeFocused instanceof Focusable) {
                    ((Focusable) toBeFocused).focus();
                } else {
                    getLogger().severe("Server is trying to set focus to the widget of connector "
                            + Util.getConnectorString(connector)
                            + " but it is not focusable. The widget should implement either "
                            + com.google.gwt.user.client.ui.Focusable.class.getName() + " or "
                            + Focusable.class.getName());
                }
            }
        });
    }

    // Add window listeners on first paint, to prevent premature
    // variablechanges
    if (firstPaint) {
        Window.addWindowClosingHandler(getWidget());
        Window.addResizeHandler(getWidget());
    }

    if (uidl.hasAttribute("scrollTo")) {
        final ComponentConnector connector = (ComponentConnector) uidl.getPaintableAttribute("scrollTo",
                getConnection());
        scrollIntoView(connector);
    }

    if (uidl.hasAttribute(UIConstants.LOCATION_VARIABLE)) {
        String location = uidl.getStringAttribute(UIConstants.LOCATION_VARIABLE);
        String newFragment;

        int fragmentIndex = location.indexOf('#');
        if (fragmentIndex >= 0) {
            // Decode fragment to avoid double encoding (#10769)
            newFragment = URL.decodePathSegment(location.substring(fragmentIndex + 1));

            if (newFragment.isEmpty() && Location.getHref().indexOf('#') == -1) {
                // Ensure there is a trailing # even though History and
                // Location.getHash() treat null and "" the same way.
                Location.assign(Location.getHref() + "#");
            }
        } else {
            // No fragment in server-side location, but can't completely
            // remove the browser fragment since that would reload the page
            newFragment = "";
        }

        getWidget().currentFragment = newFragment;

        if (!newFragment.equals(History.getToken())) {
            History.newItem(newFragment, true);
        }
    }

    if (firstPaint) {
        // Queue the initial window size to be sent with the following
        // request.
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
            @Override
            public void execute() {
                getWidget().sendClientResized();
            }
        });
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VView.java

License:Open Source License

public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
    rendering = true;/*from   w  w w .j  a v  a2  s.c o m*/

    id = uidl.getId();
    boolean firstPaint = connection == null;
    connection = client;

    immediate = uidl.hasAttribute("immediate");
    resizeLazy = uidl.hasAttribute(RESIZE_LAZY);
    String newTheme = uidl.getStringAttribute("theme");
    if (theme != null && !newTheme.equals(theme)) {
        // Complete page refresh is needed due css can affect layout
        // calculations etc
        reloadHostPage();
    } else {
        theme = newTheme;
    }
    if (uidl.hasAttribute("style")) {
        setStyleName(getStylePrimaryName() + " " + uidl.getStringAttribute("style"));
    }

    clickEventHandler.handleEventHandlerRegistration(client);

    if (!isEmbedded() && uidl.hasAttribute("caption")) {
        // only change window title if we're in charge of the whole page
        com.google.gwt.user.client.Window.setTitle(uidl.getStringAttribute("caption"));
    }

    // Process children
    int childIndex = 0;

    // Open URL:s
    boolean isClosed = false; // was this window closed?
    while (childIndex < uidl.getChildCount() && "open".equals(uidl.getChildUIDL(childIndex).getTag())) {
        final UIDL open = uidl.getChildUIDL(childIndex);
        final String url = client.translateVaadinUri(open.getStringAttribute("src"));
        final String target = open.getStringAttribute("name");
        if (target == null) {
            // source will be opened to this browser window, but we may have
            // to finish rendering this window in case this is a download
            // (and window stays open).
            Scheduler.get().scheduleDeferred(new Command() {
                public void execute() {
                    goTo(url);
                }
            });
        } else if ("_self".equals(target)) {
            // This window is closing (for sure). Only other opens are
            // relevant in this change. See #3558, #2144
            isClosed = true;
            goTo(url);
        } else {
            String options;
            if (open.hasAttribute("border")) {
                if (open.getStringAttribute("border").equals("minimal")) {
                    options = "menubar=yes,location=no,status=no";
                } else {
                    options = "menubar=no,location=no,status=no";
                }

            } else {
                options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes";
            }

            if (open.hasAttribute("width")) {
                int w = open.getIntAttribute("width");
                options += ",width=" + w;
            }
            if (open.hasAttribute("height")) {
                int h = open.getIntAttribute("height");
                options += ",height=" + h;
            }

            Window.open(url, target, options);
        }
        childIndex++;
    }
    if (isClosed) {
        // don't render the content, something else will be opened to this
        // browser view
        rendering = false;
        return;
    }

    // Draw this application level window
    UIDL childUidl = uidl.getChildUIDL(childIndex);
    final Paintable lo = client.getPaintable(childUidl);

    if (layout != null) {
        if (layout != lo) {
            // remove old
            client.unregisterPaintable(layout);
            // add new
            setWidget((Widget) lo);
            layout = lo;
        }
    } else {
        setWidget((Widget) lo);
        layout = lo;
    }

    layout.updateFromUIDL(childUidl, client);
    if (!childUidl.getBooleanAttribute("cached")) {
        updateParentFrameSize();
    }

    // Save currently open subwindows to track which will need to be closed
    final HashSet<VWindow> removedSubWindows = new HashSet<VWindow>(subWindows);

    // Handle other UIDL children
    while ((childUidl = uidl.getChildUIDL(++childIndex)) != null) {
        String tag = childUidl.getTag().intern();
        if (tag == "actions") {
            if (actionHandler == null) {
                actionHandler = new ShortcutActionHandler(id, client);
            }
            actionHandler.updateActionMap(childUidl);
        } else if (tag == "execJS") {
            String script = childUidl.getStringAttribute("script");
            eval(script);
        } else if (tag == "notifications") {
            for (final Iterator<?> it = childUidl.getChildIterator(); it.hasNext();) {
                final UIDL notification = (UIDL) it.next();
                VNotification.showNotification(client, notification);
            }
        } else {
            // subwindows
            final Paintable w = client.getPaintable(childUidl);
            if (subWindows.contains(w)) {
                removedSubWindows.remove(w);
            } else {
                subWindows.add((VWindow) w);
            }
            w.updateFromUIDL(childUidl, client);
        }
    }

    // Close old windows which where not in UIDL anymore
    for (final Iterator<VWindow> rem = removedSubWindows.iterator(); rem.hasNext();) {
        final VWindow w = rem.next();
        client.unregisterPaintable(w);
        subWindows.remove(w);
        w.hide();
    }

    if (uidl.hasAttribute("focused")) {
        // set focused component when render phase is finished
        Scheduler.get().scheduleDeferred(new Command() {
            public void execute() {
                final Paintable toBeFocused = uidl.getPaintableAttribute("focused", connection);

                /*
                 * Two types of Widgets can be focused, either implementing
                 * GWT HasFocus of a thinner Vaadin specific Focusable
                 * interface.
                 */
                if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) {
                    final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused;
                    toBeFocusedWidget.setFocus(true);
                } else if (toBeFocused instanceof Focusable) {
                    ((Focusable) toBeFocused).focus();
                } else {
                    VConsole.log("Could not focus component");
                }
            }
        });
    }

    // Add window listeners on first paint, to prevent premature
    // variablechanges
    if (firstPaint) {
        Window.addWindowClosingHandler(this);
        Window.addResizeHandler(this);
    }

    onResize();

    // finally set scroll position from UIDL
    if (uidl.hasVariable("scrollTop")) {
        scrollable = true;
        scrollTop = uidl.getIntVariable("scrollTop");
        DOM.setElementPropertyInt(getElement(), "scrollTop", scrollTop);
        scrollLeft = uidl.getIntVariable("scrollLeft");
        DOM.setElementPropertyInt(getElement(), "scrollLeft", scrollLeft);
    } else {
        scrollable = false;
    }

    // Safari workaround must be run after scrollTop is updated as it sets
    // scrollTop using a deferred command.
    if (BrowserInfo.get().isSafari()) {
        Util.runWebkitOverflowAutoFix(getElement());
    }

    scrollIntoView(uidl);

    if (uidl.hasAttribute(FRAGMENT_VARIABLE)) {
        currentFragment = uidl.getStringAttribute(FRAGMENT_VARIABLE);
        if (!currentFragment.equals(History.getToken())) {
            History.newItem(currentFragment, true);
        }
    } else {
        // Initial request for which the server doesn't yet have a fragment
        // (and haven't shown any interest in getting one)
        currentFragment = History.getToken();

        // Include current fragment in the next request
        client.updateVariable(id, FRAGMENT_VARIABLE, currentFragment, false);
    }

    rendering = false;
}

From source file:com.webgocommerce.client.model.UIMantenimiento.java

private void initComponents() {
    header = new HeaderMenu();
    lblCenter = new Label("MODO - " + MODOINSERTAR);
    header.setCenterWidget(lblCenter);//from   w  w w .  ja  v  a2s .c om
    btnBack = new PushButton(new Image(MyResource.INSTANCE.getImgBack32()));
    btnBack.setTitle("Volver Atras");
    header.setLeftWidget(btnBack);
    contenido = new VerticalPanel();
    scrollPanel = new ScrollPanel();
    scrollPanel.setScrollingEnabledY(true);
    scrollPanel.setScrollingEnabledX(false);
    scrollPanel.setAutoHandleResize(true);
    scrollPanel.setWidget(contenido);
    pnlForm = new FlowPanel();
    contenido.add(pnlForm);
    contentForm = new Form();
    pnlForm.add(contentForm);
    btnOperacion = new Button("ACEPTAR");
    btnOperacion.setConfirm(true);
    contenido.add(btnOperacion);
    pnlContenedor = new FlowPanel();
    pnlContenedor.add(header);
    pnlContenedor.add(scrollPanel);
    this.initWidget(pnlContenedor);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            reCalcularWindows();
        }
    });
}

From source file:com.webgocommerce.client.uiutil.UIBuscarCliente.java

private void initComponents() {
    pnlFiltro = new FlexTable();
    progreso = new ProgressBar();
    lstFiltro = new ListBox();
    lstFiltro.addItem("Descripcion");
    lstFiltro.addItem("Nro. Doc");
    txtBuscar = new MSearchBox();
    txtBuscar.getElement().setPropertyString("placeholder", "escriba aqui");
    pnlFiltro.setWidget(0, 0, lstFiltro);
    pnlFiltro.setWidget(0, 1, txtBuscar);
    grid = new GridCliente();
    grid.setMinimumTableWidth(1024, Style.Unit.PX);
    pnlGuardar = new FlowPanel();
    btnGuardar = new Button("Seleccionar");
    pnlGuardar.add(btnGuardar);/*from   w w  w .  j  a  va2s  .  c o m*/
    btnGuardar.setConfirm(true);
    this.getPnlTabla().add(grid);
    this.getPnlTabla().add(grid.getPager());
    this.getPnlTabla().add(pnlGuardar);
    this.getPnlBusqueda().add(pnlFiltro);
    this.getPnlBotones().setVisible(false);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            reCalcularWindows();
        }
    });
}

From source file:com.webgocommerce.client.uiutil.UIGridDetalleVenta.java

private void initComponents() {
    pnlContenedor = new FlowPanel();
    grid = new GridDetalleVenta(ui);
    grid.setMinimumTableWidth(1024, Unit.PX);
    pnlContenedor.add(grid);//  w w w.  j  a  v  a 2  s  .  c  om
    this.initWidget(pnlContenedor);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            initStyle();
        }
    });
}

From source file:com.webgocommerce.client.uiutil.UIGridRegistroVenta.java

private void initComponents() {
    pnlContenedor = new FlowPanel();
    grid = new GridRegistroVenta();
    grid.setMinimumTableWidth(1024, Style.Unit.PX);
    pnlContenedor.add(grid);//from  w w  w . ja va 2  s.co m
    this.initWidget(pnlContenedor);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            initStyle();
        }
    });
}

From source file:com.webgocommerce.client.uiutil.UIItem.java

private void initComponents() {
    pnlContenedor = new FlowPanel();
    gridItem = new GridItemSingleSelection();
    gridItem.setMinimumTableWidth(512, Style.Unit.PX);
    pnlContenedor.add(gridItem);//from  ww  w . j a va2 s.co m
    this.initWidget(pnlContenedor);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            initStyle();
        }
    });
}

From source file:com.webgocommerce.client.uiutil.UIStockItemAlmacen.java

private void initComponents() {
    pnlContenedor = new FlowPanel();
    gridItem = new GridItemSingleSelection();
    gridAlmacen = new GridAlmacen();
    gridItem.setMinimumTableWidth(512, Style.Unit.PX);
    gridAlmacen.setMinimumTableWidth(200, Style.Unit.PX);
    pnlContenedor.add(gridItem);/* w w w . j  av  a 2s. c  o m*/
    pnlContenedor.add(gridAlmacen);
    this.initWidget(pnlContenedor);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            initStyle();
        }
    });
}

From source file:com.webgocommerce.client.view.uiaddconsultor.UIAddConsultor.java

private void initComponents() {
    progreso = new ProgressBar();
    header = new HeaderMenu();
    lblCenter = new Label("CATEGORIA - LISTA");
    btnBack = new PushButton(new Image(MyResource.INSTANCE.getImgBack32()));
    btnBack.setTitle("Volver Atras");
    header.setLeftWidget(btnBack);//w  ww  .  j  a  v a2s.co m
    header.setCenterWidget(lblCenter);
    //header.setRightWidget(btnActualizar);
    //formBuscar = new FlexTable();
    //lblBuscar = new Label("Buscar:");
    txtBuscar = new MSearchBox();
    txtBuscar.getElement().setPropertyString("placeholder", "escriba aqui");
    //formBuscar.setWidget(0, 0, lblBuscar);
    //formBuscar.setWidget(0, 1, txtBuscar);
    grid = new GridConsultorSinMesa();
    //grid.setAlwaysShowScrollBars(true);
    grid.setMinimumTableWidth(1024, Style.Unit.PX);
    pnlGuardar = new FlowPanel();
    btnGuardar = new com.googlecode.mgwt.ui.client.widget.button.Button("Agregar a Lista");
    pnlGuardar.add(btnGuardar);
    btnGuardar.setConfirm(true);
    this.getPnlTabla().add(grid);
    this.getPnlTabla().add(grid.getPager());
    this.getPnlTabla().add(pnlGuardar);
    this.getPnlBusqueda().add(header);
    HorizontalPanel pnlSearch = new HorizontalPanel();
    pnlSearch.add(txtBuscar);
    pnlSearch.setWidth("100%");
    this.getPnlBusqueda().add(pnlSearch);
    this.getPnlBotones().setVisible(false);
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            reCalcularWindows();
        }
    });
}