在Vaadin中使用快捷方式的问题 [英] Problems with using shortcuts in Vaadin
问题描述
我在使用表中的快捷方式时遇到了一些问题.我必须自定义一些键:删除-删除行并输入以使表可编辑/不可编辑,向上/向下箭头可将表的模式从可编辑切换为不可编辑.我将Table放在透明面板中,并使用Action.Handler捕获键盘事件.但是,当我在TextField,TextArea,Combobox中编写内容时,我想将事件传播到此组件(处理删除键禁用,无法使用它删除TextField中的文本,并且上/下键不允许使用键盘打开Combobox).我在handleAction()方法中看到了目标参数,但现在不知道如何使用它.了解如何添加快捷方式而不是替换方式也很有趣.
I have some problems with shortcuts in Table. I have to customize some keys: delete - for removing the rows and enter to make table editable/uneditable, up/down arrows to switch mode of table from editable to uneditable. I put my Table inside transparent Panel and use Action.Handler to catch keyboard events. But when I'm writing inside TextField, TextArea, Combobox I wanted to propagate events to this component (handling delete key disable using it for deleting text in TextField and up/down keys doesn't allow open Combobox with keyboard). I saw target parameter in handleAction() method, but I don't now how to use it. Also interesting to know how to add shortcuts instead of replacing.
// adding table inside Panel
tablePanel = new Panel();
tablePanel.setStyleName(Panel.STYLE_LIGHT);
VerticalLayout tableElementsLayout = new VerticalLayout();
tablePanel.setContent(tableElementsLayout);
tablePanel.setSizeFull();
tableElementsLayout.setSizeFull();
vl.addComponent(tablePanel);
vl.setExpandRatio(tablePanel, 1.0f);
tableElementsLayout.add(table);
// --- adding keyboard handler
final Action actionDel = new ShortcutAction("Delete",
ShortcutAction.KeyCode.DELETE, null);
deleteHandler = new Action.Handler() {
@Override
public void handleAction(Action action, Object sender, Object target) {
// I want handle events here when I'm not inside TextField
}
@Override
public Action[] getActions(Object target, Object sender) {
return new Action[] { actionDel };
}
};
tablePanel.addActionHandler(deleteHandler);
有什么想法怎么做?
推荐答案
我不确定这是实现这一目标的最佳方法还是最美观的方法,但至少它能起作用:
I'm not sure if this is the best or the most beautiful way to achieve this, but at least it works:
textField.addListener(new BlurListener() {
@Override
public void blur(BlurEvent event) {
tablePanel.addActionHandler(deleteHandler);
}
});
textField.addListener(new FocusListener() {
@Override
public void focus(FocusEvent event) {
tablePanel.removeActionHandler(deleteHandler);
}
});
这些侦听器将通过在每次用户进入该字段时将其禁用并在用户每次离开该字段时将其启用来保护deleteHandler
.
These listeners will take care of the deleteHandler
by disabling it every time the user enters the field and enabling it whenever the user leaves the field.
这篇关于在Vaadin中使用快捷方式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!