Example usage for com.vaadin.ui Layout setWidthUndefined

List of usage examples for com.vaadin.ui Layout setWidthUndefined

Introduction

In this page you can find the example usage for com.vaadin.ui Layout setWidthUndefined.

Prototype

public void setWidthUndefined();

Source Link

Document

Clears any defined width.

Usage

From source file:com.haulmont.cuba.web.WebWindowManager.java

License:Apache License

protected Component showWindowDialog(Window window, OpenType openType, boolean forciblyDialog) {
    final CubaWindow vWindow = createDialogWindow(window);
    vWindow.setStyleName("c-app-dialog-window");
    if (ui.isTestMode()) {
        vWindow.setCubaId("dialog_" + window.getId());
        vWindow.setId(ui.getTestIdManager().getTestId("dialog_" + window.getId()));
    }//  w  ww . j  a v a2  s  .  c  o m

    Layout layout = (Layout) WebComponentsHelper.getComposition(window);
    vWindow.setContent(layout);

    vWindow.addPreCloseListener(event -> {
        event.setPreventClose(true);
        if (!isCloseWithCloseButtonPrevented(window)) {
            // user has clicked on X
            window.close(Window.CLOSE_ACTION_ID);
        }
    });

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    ShortcutAction exitAction = new ShortcutAction("closeShortcutAction", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers()));

    Map<com.vaadin.event.Action, Runnable> actions = singletonMap(exitAction, () -> {
        if (openType.getOpenMode() != OpenMode.DIALOG
                || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
            if (isCloseWithShortcutPrevented(window)) {
                return;
            }
            window.close(Window.CLOSE_ACTION_ID);
        }
    });

    WebComponentsHelper.setActions(vWindow, actions);

    boolean dialogParamsSizeUndefined = openType.getHeight() == null && openType.getWidth() == null;

    ThemeConstants theme = app.getThemeConstants();

    if (forciblyDialog && dialogParamsSizeUndefined) {
        layout.setHeight(100, Unit.PERCENTAGE);

        vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.width"), Unit.PIXELS);
        vWindow.setHeight(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.height"), Unit.PIXELS);

        // resizable by default, but may be overridden in dialog params
        vWindow.setResizable(BooleanUtils.isNotFalse(openType.getResizable()));

        window.setHeightFull();
    } else {
        if (openType.getWidth() == null) {
            vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.dialog.width"), Unit.PIXELS);
        } else if (openType.getWidth() == AUTO_SIZE_PX) {
            vWindow.setWidthUndefined();
            layout.setWidthUndefined();
            window.setWidthAuto();
        } else {
            vWindow.setWidth(openType.getWidth(),
                    openType.getWidthUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getWidthUnit())
                            : Unit.PIXELS);
        }

        if (openType.getHeight() != null && openType.getHeight() != AUTO_SIZE_PX) {
            vWindow.setHeight(openType.getHeight(),
                    openType.getHeightUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getHeightUnit())
                            : Unit.PIXELS);
            layout.setHeight("100%");
            window.setHeightFull();
        } else {
            window.setHeightAuto();
        }

        // non resizable by default
        vWindow.setResizable(BooleanUtils.isTrue(openType.getResizable()));
    }

    if (openType.getCloseable() != null) {
        vWindow.setClosable(openType.getCloseable());
    }

    boolean modal = true;
    if (!hasModalWindow() && openType.getModal() != null) {
        modal = openType.getModal();
    }
    vWindow.setModal(modal);

    if (vWindow.isModal()) {
        boolean informationDialog = false;
        if (openType.getCloseOnClickOutside() != null) {
            informationDialog = openType.getCloseOnClickOutside();
        }
        vWindow.setCloseOnClickOutside(informationDialog);
    }

    if (openType.getMaximized() != null) {
        if (openType.getMaximized()) {
            vWindow.setWindowMode(WindowMode.MAXIMIZED);
        } else {
            vWindow.setWindowMode(WindowMode.NORMAL);
        }
    }

    if (openType.getPositionX() == null && openType.getPositionY() == null) {
        vWindow.center();
    } else {
        if (openType.getPositionX() != null) {
            vWindow.setPositionX(openType.getPositionX());
        }
        if (openType.getPositionY() != null) {
            vWindow.setPositionY(openType.getPositionY());
        }
    }

    getDialogParams().reset();

    ui.addWindow(vWindow);

    return vWindow;
}