Search in sources :

Example 1 with TooltipData

use of org.yamcs.studio.autocomplete.tooltips.TooltipData in project yamcs-studio by yamcs.

the class LocalContentProvider method listResult.

@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
    var result = new AutoCompleteResult();
    LocalContentDescriptor locDesc = null;
    if (desc instanceof LocalContentDescriptor) {
        locDesc = (LocalContentDescriptor) desc;
    } else {
        // empty result
        return result;
    }
    if (locDesc.isComplete()) {
        // empty result
        return result;
    }
    // handle proposals
    var count = 0;
    if (locDesc.isCompletingVType() && locDesc.getvType() != null) {
        var type = locDesc.getvType();
        Proposal topProposal = null;
        String closestMatchingType = null;
        for (var vType : LocalContentDescriptor.listVTypes()) {
            if (vType.startsWith(type)) {
                var prefix = locDesc.getPvName() + LocalContentParser.VTYPE_START;
                prefix = LocalContentParser.LOCAL_SOURCE + prefix;
                var offset = prefix.length();
                var proposal = new Proposal(prefix + vType + LocalContentParser.VTYPE_END, false);
                proposal.setDescription(LocalContentDescriptor.getVTypeDescription(vType));
                proposal.addStyle(ProposalStyle.getDefault(0, offset + type.length() - 1));
                proposal.setInsertionPos(desc.getStartIndex());
                result.addProposal(proposal);
                count++;
                if (closestMatchingType == null || closestMatchingType.compareTo(vType) > 0) {
                    closestMatchingType = vType;
                    topProposal = proposal;
                }
            }
        }
        // handle top proposals
        if (closestMatchingType != null && !type.isEmpty()) {
            result.addTopProposal(topProposal);
        }
    }
    result.setCount(count);
    // handle tooltip
    TooltipData td = null;
    if (locDesc.isCompletingInitialValue()) {
        td = new TooltipData();
        td.value = "pvname";
        var vType = locDesc.getvType();
        if (vType != null) {
            td.value += LocalContentParser.VTYPE_START + locDesc.getvType() + LocalContentParser.VTYPE_END;
        }
        td.value += LocalContentParser.INITIAL_VALUE_START;
        var start = td.value.length();
        td.value += locDesc.getInitialValueTooltip();
        var end = td.value.length();
        td.value += LocalContentParser.INITIAL_VALUE_END;
        td.styles = new ProposalStyle[1];
        if (locDesc.checkParameters()) {
            td.styles[0] = ProposalStyle.getDefault(start, end);
        } else {
            td.styles[0] = ProposalStyle.getError(start, end);
        }
        result.addTooltipData(td);
    } else if (locDesc.isCompletingVType()) {
        td = new TooltipData();
        td.value = "pvname<type>";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(6, 12);
        result.addTooltipData(td);
        td = new TooltipData();
        td.value = "pvname<type>(initialValue)";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(6, 12);
        result.addTooltipData(td);
    } else {
        // bold <type>
        int from = 6, to = 12;
        if (locDesc.getvType() == null) {
            // bold pvname
            from = 0;
            to = 6;
            td = new TooltipData();
            td.value = "pvname";
            td.styles = new ProposalStyle[1];
            td.styles[0] = ProposalStyle.getDefault(from, to);
            result.addTooltipData(td);
        }
        td = new TooltipData();
        td.value = "pvname<type>";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(from, to);
        result.addTooltipData(td);
        td = new TooltipData();
        td.value = "pvname<type>(initialValue)";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(from, to);
        result.addTooltipData(td);
    }
    return result;
}
Also used : AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) ProposalStyle(org.yamcs.studio.autocomplete.proposals.ProposalStyle) TooltipData(org.yamcs.studio.autocomplete.tooltips.TooltipData) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Aggregations

AutoCompleteResult (org.yamcs.studio.autocomplete.AutoCompleteResult)1 Proposal (org.yamcs.studio.autocomplete.proposals.Proposal)1 ProposalStyle (org.yamcs.studio.autocomplete.proposals.ProposalStyle)1 TooltipData (org.yamcs.studio.autocomplete.tooltips.TooltipData)1