You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RichTextAreaWithKeyboardShortcuts.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.vaadin.tests.components.richtextarea;
  2. import com.vaadin.event.Action;
  3. import com.vaadin.event.Action.Handler;
  4. import com.vaadin.event.ShortcutAction;
  5. import com.vaadin.server.Page;
  6. import com.vaadin.tests.components.TestBase;
  7. import com.vaadin.ui.Component;
  8. import com.vaadin.ui.Notification;
  9. import com.vaadin.ui.Panel;
  10. import com.vaadin.ui.RichTextArea;
  11. import com.vaadin.ui.VerticalLayout;
  12. import com.vaadin.ui.Window;
  13. import com.vaadin.v7.ui.AbstractField;
  14. @SuppressWarnings("serial")
  15. public class RichTextAreaWithKeyboardShortcuts extends TestBase {
  16. private Handler actionHandler = new Handler() {
  17. ShortcutAction save = new ShortcutAction("^Save");
  18. private Action[] actions = { save };
  19. @Override
  20. public void handleAction(Action action, Object sender, Object target) {
  21. String msg = "Action: " + action.getCaption();
  22. msg += " From : " + sender.getClass().getSimpleName() + " '"
  23. + ((Component) sender).getCaption() + "'";
  24. AbstractField<String> f = (AbstractField<String>) target;
  25. msg += " Target:" + target.getClass().getSimpleName() + " '"
  26. + f.getCaption() + "'";
  27. String string = f.getValue();
  28. msg += " Value: " + string;
  29. Notification notification = new Notification(msg);
  30. notification.setHtmlContentAllowed(true);
  31. notification.show(Page.getCurrent());
  32. }
  33. @Override
  34. public Action[] getActions(Object target, Object sender) {
  35. return actions;
  36. }
  37. };
  38. @Override
  39. protected void setup() {
  40. getLayout().getUI().addActionHandler(actionHandler);
  41. getLayout().addComponent(createRichTextArea("InMainLayout"));
  42. VerticalLayout panelLayout = new VerticalLayout();
  43. panelLayout.setMargin(true);
  44. Panel panel = new Panel("RTA Panel", panelLayout);
  45. panel.addActionHandler(actionHandler);
  46. panelLayout.addComponent(createRichTextArea("InPanel"));
  47. getLayout().addComponent(panel);
  48. VerticalLayout layout = new VerticalLayout();
  49. layout.setMargin(true);
  50. Window w = new Window("SubWindow", layout);
  51. w.addActionHandler(actionHandler);
  52. layout.addComponent(createRichTextArea("InSubWindow"));
  53. layout.setSizeUndefined();
  54. getLayout().getUI().addWindow(w);
  55. }
  56. private RichTextArea createRichTextArea(String caption) {
  57. RichTextArea rta = new RichTextArea(caption);
  58. return rta;
  59. }
  60. @Override
  61. protected String getDescription() {
  62. return "RichTextArea shouls support shortcut actions just like other components do.";
  63. }
  64. @Override
  65. protected Integer getTicketNumber() {
  66. return 4175;
  67. }
  68. }