The update of the suggestions popup of an AutoCompleteTextField is said to
be completely asynchronous.
However, looking at the code of the AutoCompleteTextField class, it looks
like the filtering and creation of the model for the popup is called on the
EDT thread directly.
The only thing I see is a call to Display.getInstance().callSerially(new
Runnable() { but as far as I understand it, this do not create a thread in
parallel to the EDT but only postpone the operations in this runnable to
the next EDT cycle
So my question is: if I have a filtering process to create the popup that
might be long (because the server takes some time to answer or the
post-filtering of the server answer is complex), should I encapsulate that
filtering into an invokeAndBlock call?
For example if I have:
final DefaultListModel<String> options = new DefaultListModel<>();
AutoCompleteTextField atf = new AutoCompleteTextField(options) {
@Override
protected boolean filter(String text) {
if(text.length() == 0) {
return false;
}
String[] l = getSuggestions(text);
if(l == null || l.length == 0) {
return false;
}
options.removeAll();
for(String s : l) {
options.addItem(s);
}
return true;
}
};
and getSuggestions(text) can potentially take a while, should I wrote:
final DefaultListModel<String> options = new DefaultListModel<>();
AutoCompleteTextField atf = new AutoCompleteTextField(options) {
@Override
protected boolean filter(String text) {
if(text.length() == 0) {
return false;
}
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
String[] l = getSuggestions(text);
options.removeAll();
if(l != null && l.length > 0) {
for(String s : l) {
options.addItem(s);
}
}
}
});
if(options.getSize()==0){
return false;
}
return true;
}
};
to be sure not to block the EDT?
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/a6c06f05-b26b-4dbe-9c7b-fd2725d6c0b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.