use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class CubaFoldersPane method createSearchFoldersPane.
protected Component createSearchFoldersPane() {
searchFoldersTree = new CubaTree();
searchFoldersTree.setCubaId("searchFoldersTree");
searchFoldersTree.setSelectable(true);
searchFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider());
searchFoldersTree.addShortcutListener(new ShortcutListener("applySearchFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == searchFoldersTree) {
AbstractSearchFolder folder = (AbstractSearchFolder) searchFoldersTree.getValue();
if (folder != null) {
openFolder(folder);
}
}
}
});
List<SearchFolder> searchFolders = foldersService.loadSearchFolders();
searchFoldersRoot = messages.getMainMessage("folders.searchFoldersRoot");
searchFoldersTree.addItemClickListener(new FolderClickListener());
searchFoldersTree.addActionHandler(new SearchFolderActionsHandler());
if (!searchFolders.isEmpty()) {
fillTree(searchFoldersTree, searchFolders, isNeedRootSearchFolder() ? searchFoldersRoot : null);
}
for (Object itemId : searchFoldersTree.rootItemIds()) {
searchFoldersTree.expandItemsRecursively(itemId);
}
return searchFoldersTree;
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebWindowManager method createNextWindowTabShortcut.
public ShortcutListener createNextWindowTabShortcut(Window.TopLevelWindow topLevelWindow) {
String nextTabShortcut = clientConfig.getNextTabShortcut();
KeyCombination combination = KeyCombination.create(nextTabShortcut);
return new ShortcutListener("onNextTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {
@Override
public void handleAction(Object sender, Object target) {
TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheet != null && !hasDialogWindows() && tabSheet.getComponentCount() > 1) {
Component selectedTabComponent = tabSheet.getSelectedTab();
String tabId = tabSheet.getTab(selectedTabComponent);
int tabPosition = tabSheet.getTabPosition(tabId);
int newTabPosition = (tabPosition + 1) % tabSheet.getComponentCount();
String newTabId = tabSheet.getTab(newTabPosition);
tabSheet.setSelectedTab(newTabId);
moveFocus(tabSheet, newTabId);
}
}
};
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebWindowManager method createPreviousWindowTabShortcut.
public ShortcutListener createPreviousWindowTabShortcut(Window.TopLevelWindow topLevelWindow) {
String previousTabShortcut = clientConfig.getPreviousTabShortcut();
KeyCombination combination = KeyCombination.create(previousTabShortcut);
return new ShortcutListener("onPreviousTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {
@Override
public void handleAction(Object sender, Object target) {
TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheet != null && !hasDialogWindows() && tabSheet.getComponentCount() > 1) {
Component selectedTabComponent = tabSheet.getSelectedTab();
String selectedTabId = tabSheet.getTab(selectedTabComponent);
int tabPosition = tabSheet.getTabPosition(selectedTabId);
int newTabPosition = (tabSheet.getComponentCount() + tabPosition - 1) % tabSheet.getComponentCount();
String newTabId = tabSheet.getTab(newTabPosition);
tabSheet.setSelectedTab(newTabId);
moveFocus(tabSheet, newTabId);
}
}
};
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebDataGrid method initComponent.
protected void initComponent(CubaGrid component) {
setSelectionMode(SelectionMode.SINGLE);
component.setImmediate(true);
component.setColumnReorderingAllowed(true);
containerWrapper = new GeneratedPropertyContainer(component.getContainerDataSource());
component.setContainerDataSource(containerWrapper);
component.addSelectionListener(e -> {
if (datasource == null) {
return;
}
final Set<E> selected = getSelected();
if (selected.isEmpty()) {
Entity dsItem = datasource.getItemIfValid();
// noinspection unchecked
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()) {
// noinspection unchecked
datasource.setItem(null);
}
Entity newItem = selected.iterator().next();
Entity dsItem = datasource.getItemIfValid();
// noinspection unchecked
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);
if (getEventRouter().hasListeners(SelectionListener.class)) {
List<E> addedItems = getItemsByIds(e.getAdded());
List<E> removedItems = getItemsByIds(e.getRemoved());
List<E> selectedItems = getItemsByIds(e.getSelected());
SelectionEvent<E> event = new SelectionEvent<>(WebDataGrid.this, addedItems, removedItems, selectedItems);
// noinspection unchecked
getEventRouter().fireEvent(SelectionListener.class, SelectionListener::selected, event);
}
});
component.addShortcutListener(new ShortcutListener("dataGridEnter", KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == WebDataGrid.this.component) {
if (WebDataGrid.this.isEditorEnabled()) {
// since it's the default shortcut to open editor
return;
}
if (enterPressAction != null) {
enterPressAction.actionPerform(WebDataGrid.this);
} else {
handleDoubleClickAction();
}
}
}
});
component.addItemClickListener(e -> {
if (e.isDoubleClick() && e.getItem() != null && !WebDataGrid.this.isEditorEnabled()) {
// note: for now Grid doesn't send double click if editor is enabled,
// but it's better to handle it manually
handleDoubleClickAction();
}
if (getEventRouter().hasListeners(ItemClickListener.class)) {
MouseEventDetails mouseEventDetails = WebWrapperUtils.toMouseEventDetails(e);
// noinspection unchecked
E item = (E) datasource.getItem(e.getItemId());
if (item == null) {
// datasource, so we don't want to send such event because it's useless
return;
}
Column column = getColumnByPropertyId(e.getPropertyId());
ItemClickEvent<E> event = new ItemClickEvent<>(WebDataGrid.this, mouseEventDetails, item, e.getItemId(), column != null ? column.getId() : null);
// noinspection unchecked
getEventRouter().fireEvent(ItemClickListener.class, ItemClickListener::onItemClick, event);
}
});
component.addColumnReorderListener(e -> {
if (e.isUserOriginated()) {
// Grid doesn't know about columns hidden by security permissions,
// so we need to return them back to they previous positions
columnsOrder = restoreColumnsOrder(getColumnsOrderInternal());
if (getEventRouter().hasListeners(ColumnReorderListener.class)) {
ColumnReorderEvent event = new ColumnReorderEvent(WebDataGrid.this);
getEventRouter().fireEvent(ColumnReorderListener.class, ColumnReorderListener::columnReordered, event);
}
}
});
componentComposition = new GridComposition();
componentComposition.setPrimaryStyleName("c-data-grid-composition");
componentComposition.setGrid(component);
componentComposition.addComponent(component);
componentComposition.setWidthUndefined();
component.setSizeUndefined();
component.setHeightMode(HeightMode.UNDEFINED);
component.setRowStyleGenerator(createRowStyleGenerator());
component.setCellStyleGenerator(createCellStyleGenerator());
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebMaskedField method addEnterPressListener.
@Override
public void addEnterPressListener(EnterPressListener listener) {
getEventRouter().addListener(EnterPressListener.class, listener);
if (enterShortcutListener == null) {
enterShortcutListener = new ShortcutListener("enter", KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
EnterPressEvent event = new EnterPressEvent(WebMaskedField.this);
getEventRouter().fireEvent(EnterPressListener.class, EnterPressListener::enterPressed, event);
}
};
component.addShortcutListener(enterShortcutListener);
}
}
Aggregations