use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebWindowManager method createCloseShortcut.
public ShortcutListener createCloseShortcut(Window.TopLevelWindow topLevelWindow) {
String closeShortcut = clientConfig.getCloseShortcut();
KeyCombination combination = KeyCombination.create(closeShortcut);
return new ShortcutListener("onClose", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {
@Override
public void handleAction(Object sender, Object target) {
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow));
if (workArea.getState() != AppWorkArea.State.WINDOW_CONTAINER) {
return;
}
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheet != null) {
Layout layout = (Layout) tabSheet.getSelectedTab();
if (layout != null) {
tabSheet.focus();
WindowBreadCrumbs breadCrumbs = tabs.get(layout);
if (!canWindowBeClosed(breadCrumbs.getCurrentWindow())) {
return;
}
if (isCloseWithShortcutPrevented(breadCrumbs.getCurrentWindow())) {
return;
}
if (stacks.get(breadCrumbs).empty()) {
final Component previousTab = tabSheet.getPreviousTab(layout);
if (previousTab != null) {
breadCrumbs.getCurrentWindow().closeAndRun(Window.CLOSE_ACTION_ID, () -> tabSheet.setSelectedTab(previousTab));
} else {
breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
}
} else {
breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
}
}
}
} else {
Iterator<WindowBreadCrumbs> it = tabs.values().iterator();
if (it.hasNext()) {
Window currentWindow = it.next().getCurrentWindow();
if (!isCloseWithShortcutPrevented(currentWindow)) {
ui.focus();
currentWindow.close(Window.CLOSE_ACTION_ID);
}
}
}
}
};
}
use of com.vaadin.event.ShortcutListener 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();
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebAbstractTable method initComponent.
protected void initComponent(final T component) {
component.setMultiSelect(false);
component.setImmediate(true);
component.setValidationVisible(false);
component.setShowBufferedSourceException(false);
component.setBeforePaintListener(() -> {
com.vaadin.ui.Table.CellStyleGenerator generator = component.getCellStyleGenerator();
if (generator instanceof WebAbstractTable.StyleGeneratorAdapter) {
// noinspection unchecked
((StyleGeneratorAdapter) generator).resetExceptionHandledFlag();
}
});
Messages messages = AppBeans.get(Messages.NAME);
component.setSortAscendingLabel(messages.getMainMessage("tableSort.ascending"));
component.setSortResetLabel(messages.getMainMessage("tableSort.reset"));
component.setSortDescendingLabel(messages.getMainMessage("tableSort.descending"));
setClientCaching(component);
int defaultRowHeaderWidth = 16;
ThemeConstants theme = App.getInstance().getThemeConstants();
if (theme != null) {
defaultRowHeaderWidth = theme.getInt("cuba.web.Table.defaultRowHeaderWidth");
}
// CAUTION: vaadin considers null as row header property id;
// todo get width from theme
component.setColumnWidth(null, defaultRowHeaderWidth);
contextMenuPopup.setParent(component);
component.setContextMenuPopup(contextMenuPopup);
shortcutsDelegate.setAllowEnterShortcut(false);
component.addValueChangeListener(event -> {
if (datasource == null) {
return;
}
final Set<? extends Entity> selected = getSelected();
if (selected.isEmpty()) {
Entity dsItem = datasource.getItemIfValid();
datasource.setItem(null);
if (dsItem == null) {
// in this case item change event will not be generated
refreshActionsState();
}
} else {
// reset selection and select new item
if (isMultiSelect()) {
datasource.setItem(null);
}
Entity newItem = selected.iterator().next();
Entity dsItem = datasource.getItemIfValid();
datasource.setItem(newItem);
if (Objects.equals(dsItem, newItem)) {
// in this case item change event will not be generated
refreshActionsState();
}
}
LookupSelectionChangeEvent selectionChangeEvent = new LookupSelectionChangeEvent(this);
getEventRouter().fireEvent(LookupSelectionChangeListener.class, LookupSelectionChangeListener::lookupValueChanged, selectionChangeEvent);
});
component.addShortcutListener(new ShortcutListener("tableEnter", com.vaadin.event.ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == WebAbstractTable.this.component) {
if (enterPressAction != null) {
enterPressAction.actionPerform(WebAbstractTable.this);
} else {
handleClickAction();
}
}
}
});
component.addItemClickListener(event -> {
if (event.isDoubleClick() && event.getItem() != null) {
handleClickAction();
}
});
component.setSelectable(true);
component.setTableFieldFactory(createFieldFactory());
component.setColumnCollapsingAllowed(true);
component.setColumnReorderingAllowed(true);
setEditable(false);
componentComposition = new TableComposition();
componentComposition.setTable(component);
componentComposition.setPrimaryStyleName("c-table-composition");
componentComposition.addComponent(component);
component.setCellStyleGenerator(createStyleGenerator());
component.addColumnCollapseListener(this::handleColumnCollapsed);
// force default sizes
componentComposition.setHeightUndefined();
componentComposition.setWidthUndefined();
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebAbstractTree method initComponent.
public void initComponent(CubaTree component) {
componentComposition = new CssLayout();
componentComposition.setPrimaryStyleName("c-tree-composition");
componentComposition.setWidthUndefined();
componentComposition.addComponent(component);
component.setSizeFull();
component.addShortcutListener(new ShortcutListener("tableEnter", com.vaadin.event.ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == WebAbstractTree.this.component) {
if (enterPressAction != null) {
enterPressAction.actionPerform(WebAbstractTree.this);
} else {
handleClickAction();
}
}
}
});
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebComponentsHelper method addEnterShortcut.
@Deprecated
public static void addEnterShortcut(TextField textField, final Runnable runnable) {
CubaTextField cubaTextField = (CubaTextField) WebComponentsHelper.unwrap(textField);
cubaTextField.addShortcutListener(new ShortcutListener("", ShortcutAction.KeyCode.ENTER, KeyCombination.Modifier.codes()) {
@Override
public void handleAction(Object sender, Object target) {
runnable.run();
}
});
}
Aggregations