-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMultipleTextBox.java
76 lines (68 loc) · 2.04 KB
/
MultipleTextBox.java
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
package org.appfuse.client.widget;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.user.client.ui.TextBoxBase;
public class MultipleTextBox extends TextBoxBase {
/**
* Creates an empty multiple text box.
*/
public MultipleTextBox() {
this(Document.get().createTextInputElement(), "gwt-TextBox");
}
/**
* This constructor may be used by subclasses to explicitly use an existing
* element. This element must be an <input> element whose type is 'text'.
*
* @param element
* the element to be used
*/
protected MultipleTextBox(Element element) {
super(element);
assert InputElement.as(element).getType().equalsIgnoreCase("text");
}
MultipleTextBox(Element element, String styleName) {
super(element);
if (styleName != null) {
setStyleName(styleName);
}
}
@Override
public String getText() {
String wholeString = super.getText();
String lastString = wholeString;
if (wholeString != null && !wholeString.trim().equals("")) {
int lastComma = wholeString.trim().lastIndexOf(",");
if (lastComma > 0) {
lastString = wholeString.trim().substring(lastComma + 1);
}
}
return lastString;
}
@Override
public void setText(String text) {
String wholeString = super.getText();
if (text != null && text.equals("")) {
super.setText(text);
} else {
// Clean last text, to replace with new value, for example, if new
// text is [email protected]:
// "[email protected], v" need to be replaced with:
// "[email protected], [email protected], "
if (wholeString != null) {
int lastComma = wholeString.trim().lastIndexOf(",");
if (lastComma > 0) {
wholeString = wholeString.trim().substring(0, lastComma);
} else {
wholeString = "";
}
if (!wholeString.trim().endsWith(",")
&& !wholeString.trim().equals("")) {
wholeString = wholeString + ", ";
}
wholeString = wholeString + text + ", ";
super.setText(wholeString);
}
}
}
}