Search in sources :

Example 1 with ShortcutListenerDelegate

use of io.jmix.ui.widget.ShortcutListenerDelegate in project jmix by jmix-framework.

the class CubaFoldersPane method createFoldersPaneLayout.

protected JmixVerticalActionsLayout createFoldersPaneLayout(Component foldersPane, Label foldersLabel) {
    JmixVerticalActionsLayout layout = new JmixVerticalActionsLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();
    if (foldersLabel != null)
        addFoldersLabel(layout, foldersLabel);
    layout.addComponent(foldersPane);
    layout.setExpandRatio(foldersPane, 1);
    layout.addShortcutListener(new ShortcutListenerDelegate("apply" + foldersPane.getJTestId(), ShortcutAction.KeyCode.ENTER, null).withHandler((sender, target) -> {
        if (sender == layout) {
            handleFoldersPaneShortcutAction(foldersPane);
        }
    }));
    return layout;
}
Also used : UserSettingsTools(com.haulmont.cuba.web.app.settings.UserSettingsTools) JmixTree(io.jmix.ui.widget.JmixTree) MetaClass(io.jmix.core.metamodel.model.MetaClass) Security(com.haulmont.cuba.core.global.Security) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate) CubaProperties(com.haulmont.cuba.CubaProperties) JmixTimer(io.jmix.ui.widget.JmixTimer) AppBeans(com.haulmont.cuba.core.global.AppBeans) StringUtils(org.apache.commons.lang3.StringUtils) WindowConfig(io.jmix.ui.WindowConfig) UiProperties(io.jmix.ui.UiProperties) EnhancedTreeDataProvider(io.jmix.ui.widget.tree.EnhancedTreeDataProvider) AccessDeniedException(io.jmix.core.security.AccessDeniedException) PersistenceHelper(com.haulmont.cuba.core.global.PersistenceHelper) FileUploadDialog(com.haulmont.cuba.gui.app.core.file.FileUploadDialog) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) ContextClickEvent(com.vaadin.event.ContextClickEvent) ShortcutAction(com.vaadin.event.ShortcutAction) COMMIT_ACTION_ID(io.jmix.ui.component.Window.COMMIT_ACTION_ID) Method(java.lang.reflect.Method) MouseEventDetails(com.vaadin.shared.MouseEventDetails) Action(com.vaadin.event.Action) DataManager(io.jmix.core.DataManager) Dialogs(io.jmix.ui.Dialogs) Messages(com.haulmont.cuba.core.global.Messages) CoreProperties(io.jmix.core.CoreProperties) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) Serializable(java.io.Serializable) BackgroundTaskWrapper(com.haulmont.cuba.gui.executors.BackgroundTaskWrapper) Stream(java.util.stream.Stream) Folder(com.haulmont.cuba.core.entity.Folder) AppUI(io.jmix.ui.AppUI) JmixVerticalActionsLayout(io.jmix.ui.widget.JmixVerticalActionsLayout) SerializableFunction(com.vaadin.server.SerializableFunction) JmixSingleSelectionModel(io.jmix.ui.widget.grid.JmixSingleSelectionModel) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) FoldersService(com.haulmont.cuba.core.app.FoldersService) TaskLifeCycle(io.jmix.ui.executor.TaskLifeCycle) CommitContext(com.haulmont.cuba.core.global.CommitContext) Frame(io.jmix.ui.component.Frame) Supplier(java.util.function.Supplier) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Metadata(com.haulmont.cuba.core.global.Metadata) Notifications(io.jmix.ui.Notifications) ReflectTools(com.vaadin.util.ReflectTools) ExportFormat(com.haulmont.cuba.gui.export.ExportFormat) CubaComponentsHelper(com.haulmont.cuba.gui.components.CubaComponentsHelper) DialogAction(io.jmix.ui.action.DialogAction) Window(io.jmix.ui.component.Window) Nullable(javax.annotation.Nullable) UserSettingService(io.jmix.ui.settings.UserSettingService) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) TreeData(com.vaadin.data.TreeData) BackgroundTask(io.jmix.ui.executor.BackgroundTask) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Consumer(java.util.function.Consumer) ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) WebExportDisplay(com.haulmont.cuba.web.filestorage.WebExportDisplay) WindowInfo(io.jmix.ui.WindowInfo) FileUploadingAPI(com.haulmont.cuba.gui.upload.FileUploadingAPI) HierarchicalQuery(com.vaadin.data.provider.HierarchicalQuery) EntityStates(io.jmix.core.EntityStates) JmixGridContextMenu(io.jmix.ui.widget.grid.JmixGridContextMenu) com.vaadin.ui(com.vaadin.ui) ComponentsHelper(io.jmix.ui.component.ComponentsHelper) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate) JmixVerticalActionsLayout(io.jmix.ui.widget.JmixVerticalActionsLayout)

Example 2 with ShortcutListenerDelegate

use of io.jmix.ui.widget.ShortcutListenerDelegate in project jmix by jmix-framework.

the class AbstractTable method initComponent.

protected void initComponent(T component) {
    component.setMultiSelect(false);
    component.setValidationVisible(false);
    component.setShowBufferedSourceException(false);
    component.setCustomCellValueFormatter(this::formatCellValue);
    component.addValueChangeListener(this::tableSelectionChanged);
    component.setSpecificVariablesHandler(this::handleSpecificVariables);
    component.setIconProvider(this::getItemIcon);
    component.setBeforePaintListener(this::beforeComponentPaint);
    component.addColumnReorderListener(this::onColumnReorder);
    component.setSortAscendingLabel(messages.getMessage("tableSort.ascending"));
    component.setSortResetLabel(messages.getMessage("tableSort.reset"));
    component.setSortDescendingLabel(messages.getMessage("tableSort.descending"));
    component.setSelectAllLabel(messages.getMessage("tableColumnSelector.selectAll"));
    component.setDeselectAllLabel(messages.getMessage("tableColumnSelector.deselectAll"));
    int defaultRowHeaderWidth = 16;
    ThemeConstantsManager themeConstantsManager = applicationContext.getBean(ThemeConstantsManager.class, ThemeConstantsManager.class);
    ThemeConstants theme = themeConstantsManager.getConstants();
    if (theme != null) {
        defaultRowHeaderWidth = theme.getInt("jmix.ui.Table.defaultRowHeaderWidth", 16);
    }
    component.setColumnWidth(ROW_HEADER_PROPERTY_ID, defaultRowHeaderWidth);
    contextMenuPopup.setParent(component);
    component.setContextMenuPopup(contextMenuPopup);
    shortcutsDelegate.setAllowEnterShortcut(false);
    component.addShortcutListener(new ShortcutListenerDelegate("tableEnter", KeyCode.ENTER, null).withHandler((sender, target) -> {
        T tableImpl = AbstractTable.this.component;
        AppUI ui = (AppUI) tableImpl.getUI();
        if (!ui.isAccessibleForUser(tableImpl)) {
            LoggerFactory.getLogger(AbstractTable.class).debug("Ignore click attempt because Table is inaccessible for user");
            return;
        }
        if (target == this.component) {
            if (enterPressAction != null) {
                enterPressAction.actionPerform(this);
            } else {
                handleClickAction();
            }
        }
    }));
    component.addShortcutListener(new ShortcutListenerDelegate("tableSelectAll", KeyCode.A, new int[] { com.vaadin.event.ShortcutAction.ModifierKey.CTRL }).withHandler((sender, target) -> {
        if (target == this.component) {
            selectAll();
        }
    }));
    component.addItemClickListener(event -> {
        if (event.isDoubleClick() && event.getItem() != null) {
            T tableImpl = AbstractTable.this.component;
            AppUI ui = (AppUI) tableImpl.getUI();
            if (!ui.isAccessibleForUser(tableImpl)) {
                LoggerFactory.getLogger(AbstractTable.class).debug("Ignore click attempt because Table is inaccessible for user");
                return;
            }
            handleClickAction();
        }
    });
    component.setAfterUnregisterComponentHandler(this::onAfterUnregisterComponent);
    component.setBeforeRefreshRowCacheHandler(this::onBeforeRefreshRowCache);
    component.setSelectable(true);
    component.setTableFieldFactory(createFieldFactory());
    component.setColumnCollapsingAllowed(true);
    component.setColumnReorderingAllowed(true);
    setEditable(false);
    componentComposition = new TableComposition();
    componentComposition.setTable(component);
    componentComposition.setPrimaryStyleName("jmix-table-composition");
    componentComposition.addComponent(component);
    component.setCellStyleGenerator(createStyleGenerator());
    component.addColumnCollapseListener(this::handleColumnCollapsed);
    // force default sizes
    componentComposition.setHeightUndefined();
    componentComposition.setWidthUndefined();
    setClientCaching();
    initEmptyState();
}
Also used : PaginationEmptyBinder(io.jmix.ui.component.pagination.data.PaginationEmptyBinder) DataLoadingSettingsBinder(io.jmix.ui.settings.component.binder.DataLoadingSettingsBinder) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) FetchPlanRepository(io.jmix.core.FetchPlanRepository) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) Action(io.jmix.ui.action.Action) Range(io.jmix.core.metamodel.model.Range) ColumnHeaderMode(com.vaadin.v7.ui.Table.ColumnHeaderMode) TablePresentations(io.jmix.ui.presentation.TablePresentations) Preconditions.checkNotNullArgument(io.jmix.core.common.util.Preconditions.checkNotNullArgument) Property(com.vaadin.v7.data.Property) ConverterUtil(com.vaadin.v7.data.util.converter.ConverterUtil) Subscription(io.jmix.core.common.event.Subscription) EntityPreconditions(io.jmix.core.entity.EntityPreconditions) Datatype(io.jmix.core.metamodel.datatype.Datatype) InvocationTargetException(java.lang.reflect.InvocationTargetException) ThemeConstantsManager(io.jmix.ui.theme.ThemeConstantsManager) IconResolver(io.jmix.ui.icon.IconResolver) AggregatableDelegate(io.jmix.ui.component.data.aggregation.impl.AggregatableDelegate) MessageTools(io.jmix.core.MessageTools) BindingState(io.jmix.ui.component.data.BindingState) io.jmix.ui.component(io.jmix.ui.component) java.util(java.util) UiComponentProperties(io.jmix.ui.UiComponentProperties) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) FrameOwner(io.jmix.ui.screen.FrameOwner) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Converter(com.vaadin.v7.data.util.converter.Converter) TableSettings(io.jmix.ui.settings.component.TableSettings) SettingsWrapper(io.jmix.ui.settings.component.SettingsWrapper) Strings(com.google.common.base.Strings) InstanceContainer(io.jmix.ui.model.InstanceContainer) Resource(com.vaadin.server.Resource) DatatypeRegistry(io.jmix.core.metamodel.datatype.DatatypeRegistry) BaseAction(io.jmix.ui.action.BaseAction) Nullable(javax.annotation.Nullable) Actions(io.jmix.ui.Actions) CollectionContainer(io.jmix.ui.model.CollectionContainer) FetchPlan(io.jmix.core.FetchPlan) JmixEnhancedTable(io.jmix.ui.widget.JmixEnhancedTable) TablePresentationsLayout(io.jmix.ui.component.presentation.TablePresentationsLayout) UiControllerUtils(io.jmix.ui.screen.UiControllerUtils) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Entity(io.jmix.core.Entity) com.vaadin.ui(com.vaadin.ui) MetaClass(io.jmix.core.metamodel.model.MetaClass) ComponentSettingsBinder(io.jmix.ui.settings.component.binder.ComponentSettingsBinder) Preconditions(io.jmix.core.common.util.Preconditions) Formatter(io.jmix.ui.component.formatter.Formatter) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) InstallTargetHandler(io.jmix.ui.screen.InstallTargetHandler) EventHub(io.jmix.core.common.event.EventHub) EntityValues(io.jmix.core.entity.EntityValues) Messages(io.jmix.core.Messages) ParseException(java.text.ParseException) MetadataTools(io.jmix.core.MetadataTools) Method(java.lang.reflect.Method) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) JmixValueChangeEvent(io.jmix.ui.widget.compatibility.JmixValueChangeEvent) DataUnit(io.jmix.ui.component.data.DataUnit) ComponentSettings(io.jmix.ui.settings.component.ComponentSettings) AccessManager(io.jmix.core.AccessManager) LookupSelectionChangeNotifier(io.jmix.ui.component.LookupComponent.LookupSelectionChangeNotifier) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) PaginationDataUnitBinder(io.jmix.ui.component.pagination.data.PaginationDataUnitBinder) Collectors(java.util.stream.Collectors) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) AbstractComponent(com.vaadin.ui.AbstractComponent) JmixButton(io.jmix.ui.widget.JmixButton) AppUI(io.jmix.ui.AppUI) AggregationContainer(io.jmix.ui.widget.data.AggregationContainer) HasValueSource(io.jmix.ui.component.data.HasValueSource) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Aggregations(io.jmix.ui.component.data.aggregation.Aggregations) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) AggregationInputValueChangeContext(io.jmix.ui.widget.JmixEnhancedTable.AggregationInputValueChangeContext) SettingsHelper(io.jmix.ui.settings.SettingsHelper) CssLayout(com.vaadin.ui.CssLayout) io.jmix.ui.component.table(io.jmix.ui.component.table) Function(java.util.function.Function) InitializingBean(org.springframework.beans.factory.InitializingBean) Notifications(io.jmix.ui.Notifications) LOOKUP_ENTER_PRESSED_ACTION_ID(io.jmix.ui.screen.LookupScreen.LOOKUP_ENTER_PRESSED_ACTION_ID) Aggregation(io.jmix.ui.component.data.aggregation.Aggregation) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ScreenContext(io.jmix.ui.screen.ScreenContext) Logger(org.slf4j.Logger) TableItems(io.jmix.ui.component.data.TableItems) ThemeConstants(io.jmix.ui.theme.ThemeConstants) LOOKUP_ITEM_CLICK_ACTION_ID(io.jmix.ui.screen.LookupScreen.LOOKUP_ITEM_CLICK_ACTION_ID) Metadata(io.jmix.core.Metadata) ComponentSettingsRegistry(io.jmix.ui.settings.ComponentSettingsRegistry) UserSettingsTools(io.jmix.ui.settings.UserSettingsTools) Sizeable(com.vaadin.server.Sizeable) TablePresentation(io.jmix.ui.presentation.model.TablePresentation) SettingsWrapperImpl(io.jmix.ui.settings.component.SettingsWrapperImpl) Consumer(java.util.function.Consumer) VaadinSession(com.vaadin.server.VaadinSession) EntityStates(io.jmix.core.EntityStates) Element(org.dom4j.Element) DataComponents(io.jmix.ui.model.DataComponents) Component(com.vaadin.ui.Component) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) ThemeConstants(io.jmix.ui.theme.ThemeConstants) ThemeConstantsManager(io.jmix.ui.theme.ThemeConstantsManager) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate) AppUI(io.jmix.ui.AppUI)

Example 3 with ShortcutListenerDelegate

use of io.jmix.ui.widget.ShortcutListenerDelegate in project jmix by jmix-framework.

the class DialogWindowImpl method setupDialogShortcuts.

protected void setupDialogShortcuts() {
    String closeShortcut = screenProperties.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);
    ShortcutListenerDelegate exitAction = new ShortcutListenerDelegate("closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()));
    exitAction.withHandler(this::onCloseShortcutTriggered);
    dialogWindow.addActionHandler(new Action.Handler() {

        @Override
        public Action[] getActions(Object target, Object sender) {
            return new ShortcutAction[] { exitAction };
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (action == exitAction) {
                exitAction.handleAction(sender, target);
            }
        }
    });
}
Also used : StandardCloseAction(io.jmix.ui.screen.StandardCloseAction) ShortcutAction(com.vaadin.event.ShortcutAction) Action(com.vaadin.event.Action) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate)

Example 4 with ShortcutListenerDelegate

use of io.jmix.ui.widget.ShortcutListenerDelegate in project jmix by jmix-framework.

the class AbstractDataGrid method createShortcutsDelegate.

protected ShortcutsDelegate<ShortcutListener> createShortcutsDelegate() {
    return new ShortcutsDelegate<ShortcutListener>() {

        @Override
        protected ShortcutListener attachShortcut(String actionId, KeyCombination keyCombination) {
            ShortcutListener shortcut = new ShortcutListenerDelegate(actionId, keyCombination.getKey().getCode(), KeyCombination.Modifier.codes(keyCombination.getModifiers())).withHandler((sender, target) -> {
                if (sender == componentComposition) {
                    Action action = getAction(actionId);
                    if (action != null && action.isEnabled() && action.isVisible()) {
                        action.actionPerform(AbstractDataGrid.this);
                    }
                }
            });
            componentComposition.addShortcutListener(shortcut);
            return shortcut;
        }

        @Override
        protected void detachShortcut(Action action, ShortcutListener shortcutDescriptor) {
            componentComposition.removeShortcutListener(shortcutDescriptor);
        }

        @Override
        protected Collection<Action> getActions() {
            return AbstractDataGrid.this.getActions();
        }
    };
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate) ShortcutsDelegate(io.jmix.ui.sys.ShortcutsDelegate)

Example 5 with ShortcutListenerDelegate

use of io.jmix.ui.widget.ShortcutListenerDelegate in project jmix by jmix-framework.

the class MaskedFieldImpl method addEnterPressListener.

@Override
public Subscription addEnterPressListener(Consumer<EnterPressEvent> listener) {
    if (enterShortcutRegistration == null) {
        ShortcutListener enterShortcutListener = new ShortcutListenerDelegate("enter", KeyCode.ENTER, null).withHandler((sender, target) -> {
            EnterPressEvent event = new EnterPressEvent(MaskedFieldImpl.this);
            publish(EnterPressEvent.class, event);
        });
        enterShortcutRegistration = component.addShortcutListener(enterShortcutListener);
    }
    getEventHub().subscribe(EnterPressEvent.class, listener);
    return () -> internalRemoveEnterPressListener(listener);
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) ShortcutListenerDelegate(io.jmix.ui.widget.ShortcutListenerDelegate)

Aggregations

ShortcutListenerDelegate (io.jmix.ui.widget.ShortcutListenerDelegate)8 ShortcutListener (com.vaadin.event.ShortcutListener)5 Action (io.jmix.ui.action.Action)4 BaseAction (io.jmix.ui.action.BaseAction)3 ShortcutsDelegate (io.jmix.ui.sys.ShortcutsDelegate)3 Action (com.vaadin.event.Action)2 ShortcutAction (com.vaadin.event.ShortcutAction)2 com.vaadin.ui (com.vaadin.ui)2 EntityStates (io.jmix.core.EntityStates)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 AppUI (io.jmix.ui.AppUI)2 Notifications (io.jmix.ui.Notifications)2 Method (java.lang.reflect.Method)2 java.util (java.util)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Strings (com.google.common.base.Strings)1 CubaProperties (com.haulmont.cuba.CubaProperties)1