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