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