Skip to content

Instantly share code, notes, and snippets.

@agoston
Last active October 30, 2015 12:44
Show Gist options
  • Save agoston/2965e038ad357244c2fe to your computer and use it in GitHub Desktop.
Save agoston/2965e038ad357244c2fe to your computer and use it in GitHub Desktop.
Installs a global hotkey in Vaadin. Then, when triggered, it would iterate through the component tree and some buttons. Nice example of rarely used operations/hacks :)
public void installHotkey() {
LOG.info("Sprinkling magic all over");
UI.getCurrent().addActionHandler(new Action.Handler() {
@Override
public Action[] getActions(Object target, Object sender) {
return new Action[]{new ShortcutAction("Ctrl-Alt-F12", ShortcutAction.KeyCode.F12, new int[]{ShortcutAction.ModifierKey.ALT, ShortcutAction.ModifierKey.CTRL})};
}
@Override
public void handleAction(Action action, Object sender, Object target) {
final Iterator iterator = IteratorUtils.objectGraphIterator(UI.getCurrent().getContent(), new Transformer() {
@Override
public Object transform(Object input) {
if (input instanceof Iterable) {
return ((Iterable) input).iterator();
} else {
return input;
}
}
});
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof Button) {
Button button = (Button) next;
if (button.getCaption().endsWith(" MenuAction")) {
button.setEnabled(true);
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment