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