Search in sources :

Example 1 with DialogParams

use of com.haulmont.cuba.gui.DialogParams in project cuba by cuba-platform.

the class WebWindowManager method showMessageDialog.

@Override
public void showMessageDialog(String title, String message, MessageType messageType) {
    backgroundWorker.checkUIAccess();
    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(iconResolver.getIconResource(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();
}
Also used : Label(com.vaadin.ui.Label) DialogParams(com.haulmont.cuba.gui.DialogParams) ShortcutListener(com.vaadin.event.ShortcutListener) com.haulmont.cuba.web.toolkit.ui(com.haulmont.cuba.web.toolkit.ui) com.vaadin.ui(com.vaadin.ui) WebButton(com.haulmont.cuba.web.gui.components.WebButton) Button(com.vaadin.ui.Button)

Aggregations

DialogParams (com.haulmont.cuba.gui.DialogParams)1 WebButton (com.haulmont.cuba.web.gui.components.WebButton)1 com.haulmont.cuba.web.toolkit.ui (com.haulmont.cuba.web.toolkit.ui)1 ShortcutListener (com.vaadin.event.ShortcutListener)1 com.vaadin.ui (com.vaadin.ui)1 Button (com.vaadin.ui.Button)1 Label (com.vaadin.ui.Label)1