Example usage for com.vaadin.server SizeWithUnit getSize

List of usage examples for com.vaadin.server SizeWithUnit getSize

Introduction

In this page you can find the example usage for com.vaadin.server SizeWithUnit getSize.

Prototype

public float getSize() 

Source Link

Document

Returns the numeric value stored in this object.

Usage

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

License:Apache License

@Override
public void showMessageDialog(String title, String message, MessageType messageType) {
    backgroundWorker.checkUIAccess();//from w  w w .jav  a2s.c  om

    final com.vaadin.ui.Window vWindow = new CubaWindow(title);

    if (ui.isTestMode()) {
        vWindow.setCubaId("messageDialog");
        vWindow.setId(ui.getTestIdManager().getTestId("messageDialog"));
    }

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

    vWindow.addAction(new ShortcutListener("Esc", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers())) {
        @Override
        public void handleAction(Object sender, Object target) {
            vWindow.close();
        }
    });

    vWindow.addAction(new ShortcutListener("Enter", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            vWindow.close();
        }
    });

    VerticalLayout layout = new VerticalLayout();
    layout.setStyleName("c-app-message-dialog");
    layout.setSpacing(true);
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        layout.setWidthUndefined();
    }
    vWindow.setContent(layout);

    Label messageLab = new CubaLabel();
    messageLab.setValue(message);
    if (MessageType.isHTML(messageType)) {
        messageLab.setContentMode(ContentMode.HTML);
    } else {
        messageLab.setContentMode(ContentMode.TEXT);
    }
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        messageLab.setWidthUndefined();
    }
    layout.addComponent(messageLab);

    DialogAction action = new DialogAction(Type.OK);
    Button button = WebComponentsHelper.createButton();

    button.setCaption(action.getCaption());
    button.setIcon(WebComponentsHelper.getIcon(action.getIcon()));
    button.addStyleName(WebButton.ICON_STYLE);
    button.addClickListener(event -> vWindow.close());

    button.focus();

    layout.addComponent(button);

    layout.setComponentAlignment(button, Alignment.BOTTOM_RIGHT);

    float width;
    SizeUnit unit;
    DialogParams dialogParams = getDialogParams();
    if (messageType.getWidth() != null) {
        width = messageType.getWidth();
        unit = messageType.getWidthUnit();
    } else if (dialogParams.getWidth() != null) {
        width = dialogParams.getWidth();
        unit = dialogParams.getWidthUnit();
    } else {
        SizeWithUnit size = SizeWithUnit
                .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.messageDialog.width"));
        width = size.getSize();
        unit = size.getUnit();
    }

    vWindow.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS);
    vWindow.setResizable(false);

    boolean modal = true;
    if (!hasModalWindow()) {
        if (messageType.getModal() != null) {
            modal = messageType.getModal();
        } else if (dialogParams.getModal() != null) {
            modal = dialogParams.getModal();
        }
    }
    vWindow.setModal(modal);

    boolean closeOnClickOutside = false;
    if (vWindow.isModal()) {
        if (messageType.getCloseOnClickOutside() != null) {
            closeOnClickOutside = messageType.getCloseOnClickOutside();
        }
    }
    ((CubaWindow) vWindow).setCloseOnClickOutside(closeOnClickOutside);

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

    dialogParams.reset();

    ui.addWindow(vWindow);
    vWindow.center();
    vWindow.focus();
}

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

License:Apache License

@Override
public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
    backgroundWorker.checkUIAccess();/*  w w w  . j a  v a 2s. c  om*/

    final com.vaadin.ui.Window window = new CubaWindow(title);

    if (ui.isTestMode()) {
        window.setCubaId("optionDialog");
        window.setId(ui.getTestIdManager().getTestId("optionDialog"));
    }
    window.setClosable(false);

    Label messageLab = new CubaLabel();
    messageLab.setValue(message);
    if (MessageType.isHTML(messageType)) {
        messageLab.setContentMode(ContentMode.HTML);
    } else {
        messageLab.setContentMode(ContentMode.TEXT);
    }
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        messageLab.setWidthUndefined();
    }

    float width;
    SizeUnit unit;
    if (messageType.getWidth() != null) {
        width = messageType.getWidth();
        unit = messageType.getWidthUnit();
    } else if (getDialogParams().getWidth() != null) {
        width = getDialogParams().getWidth();
        unit = getDialogParams().getWidthUnit();
    } else {
        SizeWithUnit size = SizeWithUnit
                .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.optionDialog.width"));
        width = size.getSize();
        unit = size.getUnit();
    }

    if (messageType.getModal() != null) {
        log.warn("MessageType.modal is not supported for showOptionDialog");
    }

    getDialogParams().reset();

    window.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS);
    window.setResizable(false);
    window.setModal(true);

    boolean closeOnClickOutside = false;
    if (window.isModal()) {
        if (messageType.getCloseOnClickOutside() != null) {
            closeOnClickOutside = messageType.getCloseOnClickOutside();
        }
    }
    ((CubaWindow) window).setCloseOnClickOutside(closeOnClickOutside);

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

    VerticalLayout layout = new VerticalLayout();
    layout.setStyleName("c-app-option-dialog");
    layout.setSpacing(true);
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        layout.setWidthUndefined();
    }
    window.setContent(layout);

    HorizontalLayout buttonsContainer = new HorizontalLayout();
    buttonsContainer.setSpacing(true);

    boolean hasPrimaryAction = false;
    Map<Action, Button> buttonMap = new HashMap<>();
    for (Action action : actions) {
        Button button = WebComponentsHelper.createButton();
        button.setCaption(action.getCaption());
        button.addClickListener(event -> {
            try {
                action.actionPerform(null);
            } finally {
                ui.removeWindow(window);
            }
        });

        if (StringUtils.isNotEmpty(action.getIcon())) {
            button.setIcon(WebComponentsHelper.getIcon(action.getIcon()));
            button.addStyleName(WebButton.ICON_STYLE);
        }

        if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
            button.addStyleName("c-primary-action");
            button.focus();

            hasPrimaryAction = true;
        }

        if (ui.isTestMode()) {
            button.setCubaId("optionDialog_" + action.getId());
            button.setId(ui.getTestIdManager().getTestId("optionDialog_" + action.getId()));
        }

        buttonsContainer.addComponent(button);
        buttonMap.put(action, button);
    }

    assignDialogShortcuts(buttonMap);

    if (!hasPrimaryAction && actions.length > 0) {
        ((Button) buttonsContainer.getComponent(0)).focus();
    }

    layout.addComponent(messageLab);
    layout.addComponent(buttonsContainer);

    layout.setExpandRatio(messageLab, 1);
    layout.setComponentAlignment(buttonsContainer, Alignment.BOTTOM_RIGHT);

    ui.addWindow(window);
    window.center();
}