Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SWTBotText |
|
| 1.0;1 | ||||
SWTBotText$1 |
|
| 1.0;1 | ||||
SWTBotText$2 |
|
| 1.0;1 |
1 | 9 | /******************************************************************************* |
2 | * Copyright (c) 2008 Ketan Padegaonkar and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Ketan Padegaonkar - initial API and implementation | |
10 | * Paulin - http://swtbot.org/bugzilla/show_bug.cgi?id=36 | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.swtbot.swt.finder.widgets; | |
13 | ||
14 | import org.eclipse.swt.widgets.Event; | |
15 | import org.eclipse.swt.widgets.Text; | |
16 | import org.eclipse.swtbot.swt.finder.ReferenceBy; | |
17 | import org.eclipse.swtbot.swt.finder.SWTBotWidget; | |
18 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | |
19 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
20 | import org.eclipse.swtbot.swt.finder.utils.MessageFormat; | |
21 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
22 | import org.hamcrest.SelfDescribing; | |
23 | ||
24 | /** | |
25 | * This represents a {@link Text} widget. | |
26 | * | |
27 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
28 | * @version $Id$ | |
29 | */ | |
30 | @SWTBotWidget(clasz = Text.class, preferredName = "text", referenceBy = { ReferenceBy.LABEL, ReferenceBy.TEXT, ReferenceBy.TOOLTIP, ReferenceBy.MESSAGE }) | |
31 | public class SWTBotText extends AbstractSWTBot<Text> { | |
32 | ||
33 | /** | |
34 | * Constructs a new instance of this object. | |
35 | * | |
36 | * @param w the widget. | |
37 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
38 | */ | |
39 | public SWTBotText(Text w) throws WidgetNotFoundException { | |
40 | 3 | this(w, null); |
41 | 3 | } |
42 | ||
43 | /** | |
44 | * Constructs a new instance of this object. | |
45 | * | |
46 | * @param w the widget. | |
47 | * @param description the description of the widget, this will be reported by {@link #toString()} | |
48 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
49 | */ | |
50 | public SWTBotText(Text w, SelfDescribing description) throws WidgetNotFoundException { | |
51 | 72 | super(w, description); |
52 | 72 | } |
53 | ||
54 | /** | |
55 | * Sets the text of the widget. | |
56 | * | |
57 | * @param text the text to be set. | |
58 | * @return the same instance. | |
59 | */ | |
60 | public SWTBotText setText(final String text) { | |
61 | 9 | waitForEnabled(); |
62 | 9 | asyncExec(new VoidResult() { |
63 | public void run() { | |
64 | 9 | widget.setText(text); |
65 | 9 | } |
66 | }); | |
67 | 9 | return this; |
68 | } | |
69 | ||
70 | /** | |
71 | * Types the string in the text box. | |
72 | * | |
73 | * @param text the text to be typed. | |
74 | * @return the same instance. | |
75 | * @since 1.2 | |
76 | */ | |
77 | public SWTBotText typeText(final String text) { | |
78 | 1 | return typeText(text, SWTBotPreferences.TYPE_INTERVAL); |
79 | } | |
80 | ||
81 | /** | |
82 | * Types the string in the text box. | |
83 | * | |
84 | * @param text the text to be typed. | |
85 | * @param interval the interval between consecutive key strokes. | |
86 | * @return the same instance. | |
87 | * @since 1.2 | |
88 | */ | |
89 | public SWTBotText typeText(final String text, int interval) { | |
90 | 1 | log.debug(MessageFormat.format("Inserting text:{0} into text {1}", text, this)); //$NON-NLS-1$ |
91 | 1 | setFocus(); |
92 | 1 | keyboard().typeText(text, interval); |
93 | 1 | return this; |
94 | } | |
95 | ||
96 | /** | |
97 | * Notifies of the keyboard event. | |
98 | * <p> | |
99 | * FIXME need some work for CTRL|SHIFT + 1 the 1 is to be sent as '!' in this case. | |
100 | * </p> | |
101 | * | |
102 | * @param modificationKeys the modification keys. | |
103 | * @param c the character. | |
104 | * @see Event#character | |
105 | * @see Event#stateMask | |
106 | * @deprecated use {@link #pressShortcut(int, char)} instead. This api will be removed. | |
107 | */ | |
108 | @Deprecated | |
109 | public void notifyKeyboardEvent(int modificationKeys, char c) { | |
110 | 0 | keyboard().pressShortcut(modificationKeys, c); |
111 | 0 | } |
112 | ||
113 | /** | |
114 | * Notifies of keyboard event. | |
115 | * | |
116 | * @param modificationKeys the modification key. | |
117 | * @param c the character. | |
118 | * @param keyCode any special keys (function keys, arrow or navigation keys etc.) | |
119 | * @see Event#keyCode | |
120 | * @see Event#character | |
121 | * @see Event#stateMask | |
122 | * @deprecated use {@link #pressShortcut(int, int, char)} instead. This api will be removed. | |
123 | */ | |
124 | @Deprecated | |
125 | public void notifyKeyboardEvent(int modificationKeys, char c, int keyCode) { | |
126 | 0 | pressShortcut(modificationKeys, keyCode, c); |
127 | 0 | } |
128 | ||
129 | /** | |
130 | * Select the contents of the entire widget. | |
131 | * @return the same instance. | |
132 | */ | |
133 | public SWTBotText selectAll() { | |
134 | 0 | syncExec(new VoidResult() { |
135 | public void run() { | |
136 | 0 | widget.selectAll(); |
137 | 0 | } |
138 | }); | |
139 | 0 | return this; |
140 | } | |
141 | ||
142 | } |