Search in sources :

Example 1 with Option

use of com.haulmont.cuba.gui.components.autocomplete.impl.Option in project cuba by cuba-platform.

the class JpqlSuggestionFactory method requestHint.

public static List<Suggestion> requestHint(String query, int queryPosition, AutoCompleteSupport sender, int senderCursorPosition, @Nullable HintProvider provider) {
    DomainModelBuilder builder = AppBeans.get(DomainModelWithCaptionsBuilder.NAME);
    DomainModel domainModel = builder.produce();
    if (provider == null) {
        provider = new HintProvider(domainModel);
    }
    try {
        HintRequest request = new HintRequest();
        request.setQuery(query);
        request.setPosition(queryPosition);
        HintResponse response = provider.requestHint(request);
        String prefix = response.getLastWord();
        List<Option> options = response.getOptionObjects();
        List<Suggestion> result = new ArrayList<>();
        for (Option option : options) {
            Suggestion suggestion = JpqlSuggestionFactory.produce(sender, option.getValue(), option.getDescription(), senderCursorPosition, prefix == null ? 0 : prefix.length());
            result.add(suggestion);
        }
        return result;
    } catch (org.antlr.runtime.RecognitionException e) {
        throw new RuntimeException(e);
    }
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) ArrayList(java.util.ArrayList) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) DomainModelBuilder(com.haulmont.cuba.core.sys.jpql.DomainModelBuilder) Option(com.haulmont.cuba.gui.components.autocomplete.impl.Option)

Aggregations

DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)1 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)1 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1