use of org.csstudio.autocomplete.IAutoCompleteResultListener in project yamcs-studio by yamcs.
the class AutoCompleteProposalProvider method getProposals.
/**
* {@inheritDoc}
*/
@Override
public void getProposals(final String contents, final IContentProposalSearchHandler handler) {
currentId = System.currentTimeMillis();
synchronized (currentList) {
currentList.clear();
currentList.setOriginalValue(contents);
}
AutoCompleteService cns = AutoCompleteService.getInstance();
int expected = cns.get(currentId, AutoCompleteType.valueOf(type), contents, new IAutoCompleteResultListener() {
@Override
public void handleResult(Long uniqueId, Integer index, AutoCompleteResult result) {
if (uniqueId == currentId) {
synchronized (currentList) {
currentList.responseReceived();
}
if (result == null)
return;
List<Proposal> contentProposals = new ArrayList<Proposal>();
if (result.getProposals() != null)
for (final Proposal proposal : result.getProposals()) contentProposals.add(proposal);
Proposal[] contentProposalsArray = contentProposals.toArray(new Proposal[contentProposals.size()]);
List<Proposal> topContentProposals = new ArrayList<Proposal>();
if (result.getTopProposals() != null)
for (final Proposal proposal : result.getTopProposals()) topContentProposals.add(proposal);
ContentProposalList cpl = null;
synchronized (currentList) {
if (result.getProvider() != null)
currentList.addProposals(result.getProvider(), contentProposalsArray, result.getCount(), index);
currentList.addTopProposals(topContentProposals);
cpl = currentList.clone();
}
handler.handleResult(cpl);
handler.handleTooltips(result.getTooltips());
// System.out.println("PROCESSED: " + uniqueId + ", " + index);
}
}
});
currentList.setExpected(expected);
}
Aggregations