Search in sources :

Example 1 with ContentProposalList

use of org.yamcs.studio.autocomplete.ui.content.ContentProposalList in project yamcs-studio by yamcs.

the class AutoCompleteProposalProvider method getProposals.

@Override
public void getProposals(String contents, IContentProposalSearchHandler handler) {
    currentId = System.currentTimeMillis();
    synchronized (currentList) {
        currentList.clear();
        currentList.setOriginalValue(contents);
    }
    var cns = AutoCompleteService.getInstance();
    var expected = cns.get(currentId, AutoCompleteType.valueOf(type), contents, (uniqueId, index, result) -> {
        if (uniqueId == currentId) {
            synchronized (currentList) {
                currentList.responseReceived();
            }
            if (result == null) {
                return;
            }
            List<Proposal> contentProposals = new ArrayList<>();
            if (result.getProposals() != null) {
                contentProposals.addAll(result.getProposals());
            }
            var contentProposalsArray = contentProposals.toArray(new Proposal[contentProposals.size()]);
            List<Proposal> topContentProposals = new ArrayList<>();
            if (result.getTopProposals() != null) {
                topContentProposals.addAll(result.getTopProposals());
            }
            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);
}
Also used : ContentProposalList(org.yamcs.studio.autocomplete.ui.content.ContentProposalList) ArrayList(java.util.ArrayList) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Aggregations

ArrayList (java.util.ArrayList)1 Proposal (org.yamcs.studio.autocomplete.proposals.Proposal)1 ContentProposalList (org.yamcs.studio.autocomplete.ui.content.ContentProposalList)1