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();
}
Aggregations