]> source.dussan.org Git - vaadin-framework.git/blob
481ea55267033e63417b774491a7cc46f6a3feaa
[vaadin-framework.git] /
1 package com.vaadin.tests.components.richtextarea;
2
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;
15
16 @SuppressWarnings("serial")
17 public class RichTextAreaWithKeyboardShortcuts extends TestBase {
18
19     private Handler actionHandler = new Handler() {
20
21         ShortcutAction save = new ShortcutAction("^Save");
22         private Action[] actions = new Action[] { save };
23
24         @Override
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() + "'";
29
30             AbstractField<String> f = (AbstractField<String>) target;
31             msg += " Target:" + target.getClass().getSimpleName() + " '"
32                     + f.getCaption() + "'";
33
34             String string = f.getValue().toString();
35
36             msg += " Value: " + string;
37             Notification notification = new Notification(msg);
38             notification.setHtmlContentAllowed(true);
39             notification.show(Page.getCurrent());
40
41         }
42
43         @Override
44         public Action[] getActions(Object target, Object sender) {
45             return actions;
46         }
47     };
48
49     @Override
50     protected void setup() {
51
52         getLayout().getUI().addActionHandler(actionHandler);
53         getLayout().addComponent(createRichTextArea("InMainLayout"));
54
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);
61
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();
68
69         getLayout().getUI().addWindow(w);
70
71     }
72
73     private RichTextArea createRichTextArea(String caption) {
74         RichTextArea rta = new RichTextArea(caption);
75         return rta;
76     }
77
78     @Override
79     protected String getDescription() {
80         return "RichTextArea shouls support shortcut actions just like other components do.";
81     }
82
83     @Override
84     protected Integer getTicketNumber() {
85         return 4175;
86     }
87
88 }