Reviewers: jlabanca,
Description:
- This allows easily create SuggestBoxes which override getText() to
return a customized substring to look for, instead of the entire text
which is used now.
- Although it is possible to change the behaviour passing a customized
TextBoxBase, which overrides getText, to the constructor, the way of
extending SuggestBox is easier.
- This patch does not modifies the original behaviour of the widget.
Please review this at http://gwt-code-reviews.appspot.com/132812
Affected files:
src/com/google/gwt/user/client/ui/SuggestBox.java
test/com/google/gwt/user/client/ui/SuggestBoxTest.java
Index: src/com/google/gwt/user/client/ui/SuggestBox.java
===================================================================
--- src/com/google/gwt/user/client/ui/SuggestBox.java (revisiĆ³n: 7423)
+++ src/com/google/gwt/user/client/ui/SuggestBox.java (copia de trabajo)
@@ -1034,7 +1034,7 @@
private void refreshSuggestions() {
// Get the raw text.
- String text = box.getText();
+ String text = getText();
if (text.equals(currentText)) {
return;
} else {
Index: test/com/google/gwt/user/client/ui/SuggestBoxTest.java
===================================================================
--- test/com/google/gwt/user/client/ui/SuggestBoxTest.java (revisiĆ³n: 7423)
+++ test/com/google/gwt/user/client/ui/SuggestBoxTest.java (copia de
trabajo)
@@ -173,6 +173,27 @@
assertTrue(b.getParent() == box);
}
+ public void testGettextShouldBeCalledWhenOverrided() {
+ // Asynchronous test
+ delayTestFinish(100);
+
+ // Create a customized SuggestBox which overrides getText
+ // The call to getText will finish the asynchronous test
+ SuggestBox box = new SuggestBox(createOracle(), new TextBox(), new
TestSuggestionDisplay()){
+ @Override
+ public String getText(){
+ finishTest();
+ return "";
+ }
+ };
+
+ // Attach the box
+ RootPanel.get().add(box);
+
+ // showSuggestionList will call the overridden method
+ box.showSuggestionList();
+ }
+
protected SuggestBox createSuggestBox() {
MultiWordSuggestOracle oracle = createOracle();
return new SuggestBox(oracle, new TextBox(), new
TestSuggestionDisplay());
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors