Search in sources :

Example 1 with ContentProposalList

use of org.csstudio.autocomplete.ui.content.ContentProposalList 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);
}
Also used : ContentProposalList(org.csstudio.autocomplete.ui.content.ContentProposalList) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) AutoCompleteService(org.csstudio.autocomplete.AutoCompleteService) IAutoCompleteResultListener(org.csstudio.autocomplete.IAutoCompleteResultListener) List(java.util.List) ContentProposalList(org.csstudio.autocomplete.ui.content.ContentProposalList) ArrayList(java.util.ArrayList) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AutoCompleteResult (org.csstudio.autocomplete.AutoCompleteResult)1 AutoCompleteService (org.csstudio.autocomplete.AutoCompleteService)1 IAutoCompleteResultListener (org.csstudio.autocomplete.IAutoCompleteResultListener)1 Proposal (org.csstudio.autocomplete.proposals.Proposal)1 ContentProposalList (org.csstudio.autocomplete.ui.content.ContentProposalList)1