Search in sources :

Example 11 with ShortcutListener

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);
                    }
                }
            }
        }
    };
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) ShortcutListener(com.vaadin.event.ShortcutListener) CssLayout(com.vaadin.ui.CssLayout) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 12 with ShortcutListener

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

Example 13 with ShortcutListener

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();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Table(com.haulmont.cuba.gui.components.Table) CubaEnhancedTable(com.haulmont.cuba.web.toolkit.ui.CubaEnhancedTable) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ShortcutListener(com.vaadin.event.ShortcutListener)

Example 14 with ShortcutListener

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();
                }
            }
        }
    });
}
Also used : CssLayout(com.vaadin.ui.CssLayout) ShortcutListener(com.vaadin.event.ShortcutListener)

Example 15 with ShortcutListener

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();
        }
    });
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener)

Aggregations

ShortcutListener (com.vaadin.event.ShortcutListener)15 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)3 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)2 Entity (com.haulmont.cuba.core.entity.Entity)2 KeyCombination (com.haulmont.cuba.gui.components.KeyCombination)2 CubaTree (com.haulmont.cuba.web.toolkit.ui.CubaTree)2 AbstractComponent (com.vaadin.ui.AbstractComponent)2 Component (com.vaadin.ui.Component)2 CssLayout (com.vaadin.ui.CssLayout)2 Level (ch.qos.logback.classic.Level)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 AppFolder (com.haulmont.cuba.core.entity.AppFolder)1 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 Security (com.haulmont.cuba.core.global.Security)1 LogArchiver (com.haulmont.cuba.core.sys.logging.LogArchiver)1 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)1 LoggingHelper (com.haulmont.cuba.core.sys.logging.LoggingHelper)1 AppConfig (com.haulmont.cuba.gui.AppConfig)1 DialogParams (com.haulmont.cuba.gui.DialogParams)1