forked from GitHub/gf-core
GWT completion: only return request.getLimit() results to the SuggestBox. Re-request completions from the server if there is only one completion.
This commit is contained in:
@@ -88,9 +88,7 @@ public class CompletionOracle extends SuggestOracle {
|
||||
suggestions.add(c);
|
||||
}
|
||||
}
|
||||
// Use filtered old suggestions, if there are enough of them,
|
||||
// or if the old ones were already fewer than the limit.
|
||||
if (suggestions.size() > 0 && (suggestions.size() >= request.getLimit() || oldSuggestions.size() < request.getLimit())) {
|
||||
if (suggestions.size() > 1 && (suggestions.size() >= request.getLimit() || oldSuggestions.size() < request.getLimit())) {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
@@ -121,6 +119,7 @@ public class CompletionOracle extends SuggestOracle {
|
||||
private void suggestionsReady(SuggestOracle.Request request, SuggestOracle.Callback callback, List<CompletionSuggestion> suggestions) {
|
||||
this.oldQuery = request.getQuery();
|
||||
this.oldSuggestions = suggestions;
|
||||
suggestions = suggestions.size() <= request.getLimit() ? suggestions : SubList.makeSubList(suggestions, 0, request.getLimit());
|
||||
callback.onSuggestionsReady(request, new SuggestOracle.Response(suggestions));
|
||||
}
|
||||
|
||||
|
||||
37
src/server/gwt/src/se/chalmers/cs/gf/gwt/client/SubList.java
Normal file
37
src/server/gwt/src/se/chalmers/cs/gf/gwt/client/SubList.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package se.chalmers.cs.gf.gwt.client;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.List;
|
||||
|
||||
/** Work-around for missing List.subList() method in GWT JRE API emulation. */
|
||||
public class SubList<T> extends AbstractList<T> {
|
||||
|
||||
private List<T> list;
|
||||
|
||||
private int fromIndex;
|
||||
|
||||
private int toIndex;
|
||||
|
||||
public SubList(List<T> list, int fromIndex, int toIndex) {
|
||||
this.list = list;
|
||||
this.fromIndex = fromIndex;
|
||||
this.toIndex = toIndex;
|
||||
if (fromIndex < 0 || toIndex > list.size())
|
||||
throw new IndexOutOfBoundsException("Endpoint index value out of range");
|
||||
if (fromIndex > toIndex)
|
||||
throw new IllegalArgumentException("Endpoint indices out of order");
|
||||
}
|
||||
|
||||
public T get(int index) {
|
||||
return list.get(fromIndex + index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return toIndex - fromIndex;
|
||||
}
|
||||
|
||||
public static <T> SubList<T> makeSubList(List<T> list, int fromIndex, int toIndex) {
|
||||
return new SubList<T>(list, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user