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);
}
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class WebTextField method addEnterPressListener.
@Override
public void addEnterPressListener(EnterPressListener listener) {
getEventRouter().addListener(EnterPressListener.class, listener);
if (enterShortcutListener == null) {
enterShortcutListener = new ShortcutListener("", KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
EnterPressEvent event = new EnterPressEvent(WebTextField.this);
getEventRouter().fireEvent(EnterPressListener.class, EnterPressListener::enterPressed, event);
}
};
component.addShortcutListener(enterShortcutListener);
}
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class CubaFoldersPane method createAppFoldersPane.
protected Component createAppFoldersPane() {
List<AppFolder> appFolders = foldersService.loadAppFolders();
if (appFolders.isEmpty())
return null;
appFoldersTree = new CubaTree();
appFoldersTree.setCubaId("appFoldersTree");
appFoldersTree.setSelectable(true);
appFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider());
appFoldersTree.addShortcutListener(new ShortcutListener("applyAppFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == appFoldersTree) {
AbstractSearchFolder folder = (AbstractSearchFolder) appFoldersTree.getValue();
if (folder != null) {
openFolder(folder);
}
}
}
});
appFoldersTree.addExpandListener(new Tree.ExpandListener() {
@Override
public void nodeExpand(Tree.ExpandEvent event) {
AppFolder folder = (AppFolder) event.getItemId();
if (StringUtils.isBlank(folder.getQuantityScript())) {
folder.setQuantity(null);
folder.setItemStyle(null);
setFolderTreeItemCaption(appFoldersTree, folder);
}
}
});
appFoldersTree.addCollapseListener(new Tree.CollapseListener() {
@Override
public void nodeCollapse(Tree.CollapseEvent event) {
AppFolder folder = (AppFolder) event.getItemId();
if (StringUtils.isBlank(folder.getQuantityScript())) {
reloadSingleParentFolder(folder, null);
setFolderTreeItemCaption(appFoldersTree, folder);
}
}
});
appFoldersRoot = messages.getMainMessage("folders.appFoldersRoot");
fillTree(appFoldersTree, appFolders, isNeedRootAppFolder() ? appFoldersRoot : null);
appFoldersTree.addItemClickListener(new FolderClickListener());
appFoldersTree.addActionHandler(new AppFolderActionsHandler());
for (Object itemId : appFoldersTree.rootItemIds()) {
appFoldersTree.expandItemsRecursively(itemId);
}
return appFoldersTree;
}
use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.
the class ServerLogWindow method init.
@Override
public void init(Map<String, Object> params) {
localJmxField.setValue(jmxControlAPI.getLocalNodeName());
localJmxField.setEditable(false);
localJmxInstance = jmxControlAPI.getLocalInstance();
jmxInstancesDs.refresh();
jmxConnectionField.setValue(localJmxInstance);
jmxConnectionField.setRequired(true);
jmxConnectionField.addValueChangeListener(e -> {
JmxInstance jmxInstance = (JmxInstance) e.getValue();
try {
refreshHostInfo();
} catch (JmxControlException ex) {
showNotification(getMessage("exception.unableToConnectToInterface"), NotificationType.WARNING);
if (jmxInstance != localJmxInstance) {
jmxConnectionField.setValue(localJmxInstance);
}
}
});
autoRefreshCheck.addValueChangeListener(e -> {
if (Boolean.TRUE.equals(e.getValue())) {
updateLogTailTimer.start();
} else {
updateLogTailTimer.stop();
}
});
jmxConnectionField.removeAllActions();
LookupAction action = LookupAction.create(jmxConnectionField);
action.setAfterLookupCloseHandler((window, actionId) -> {
jmxInstancesDs.refresh();
});
jmxConnectionField.addAction(action);
jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
instanceEditor.addCloseListener(actionId -> {
if (COMMIT_ACTION_ID.equals(actionId)) {
jmxInstancesDs.refresh();
jmxConnectionField.setValue(instanceEditor.getItem());
}
});
}));
logTailLabel.setSizeAuto();
logTailLabel.setHtmlEnabled(true);
logTailLabel.setStyleName("c-log-content");
loggerLevelField.setOptionsList(LoggingHelper.getLevels());
appenderLevelField.setOptionsList(LoggingHelper.getLevels());
refreshHostInfo();
loggerNameField.addValueChangeListener(e -> {
List<String> currentLoggers = new ArrayList<>(jmxRemoteLoggingAPI.getLoggerNames(getSelectedConnection()));
Collections.sort(currentLoggers);
currentLoggers.add(0, getMessage("logger.new"));
if (e.getValue() != null && e.getValue().equals(currentLoggers.get(0))) {
openAddLoggerDialog();
}
});
downloadButton.setEnabled(security.isSpecificPermitted("cuba.gui.administration.downloadlogs"));
ComboBox comboBox = logFileNameField.unwrap(ComboBox.class);
comboBox.addShortcutListener(new ShortcutListener("", KeyCode.D, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {
@Override
public void handleAction(Object sender, Object target) {
downloadLog();
}
});
comboBox.addShortcutListener(new ShortcutListener("", KeyCode.S, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {
@Override
public void handleAction(Object sender, Object target) {
showLogTail();
}
});
downloadButton.setDescription("CTRL-SHIFT-D");
showTailButton.setDescription("CTRL-SHIFT-S");
}
Aggregations