Search in sources :

Example 1 with TooltipData

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

the class FormulaFunctionProvider method generateTooltipData.

private TooltipData generateTooltipData(FormulaFunction function, int currentArgIndex) {
    TooltipData td = new TooltipData();
    StringBuilder sb = new StringBuilder();
    sb.append(function.getName() + "(");
    int nbArgs = function.getArgumentNames().size();
    int from = 0, to = 0;
    for (int i = 0; i < nbArgs; i++) {
        if (i == currentArgIndex) {
            from = sb.length();
        }
        sb.append("<");
        sb.append(function.getArgumentTypes().get(i).getSimpleName());
        sb.append(">");
        sb.append(function.getArgumentNames().get(i));
        if (i == currentArgIndex) {
            to = sb.length();
        }
        if (i < nbArgs - 1)
            sb.append(", ");
    }
    if (function.isVarArgs()) {
        if (currentArgIndex >= nbArgs) {
            from = sb.length();
            to = from + 4;
        }
        sb.append(",...");
    }
    sb.append(")");
    td.styles = new ProposalStyle[1];
    td.styles[0] = ProposalStyle.getDefault(from, to);
    td.value = sb.toString();
    return td;
}
Also used : TooltipData(org.csstudio.autocomplete.tooltips.TooltipData)

Example 2 with TooltipData

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

the class LocalContentProvider method listResult.

@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
    AutoCompleteResult 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
    int count = 0;
    if (locDesc.isCompletingVType() && locDesc.getvType() != null) {
        String type = locDesc.getvType();
        Proposal topProposal = null;
        String closestMatchingType = null;
        for (String vType : LocalContentDescriptor.listVTypes()) {
            if (vType.startsWith(type)) {
                String prefix = locDesc.getPvName() + LocalContentParser.VTYPE_START;
                if (desc.getDefaultDataSource() != LocalContentParser.LOCAL_SOURCE)
                    prefix = LocalContentParser.LOCAL_SOURCE + prefix;
                int offset = prefix.length();
                Proposal 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();
        // $NON-NLS-1$
        td.value = "pvname";
        String vType = locDesc.getvType();
        if (vType != null) {
            td.value += LocalContentParser.VTYPE_START + locDesc.getvType() + LocalContentParser.VTYPE_END;
        }
        td.value += LocalContentParser.INITIAL_VALUE_START;
        int start = td.value.length();
        td.value += locDesc.getInitialValueTooltip();
        int 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();
        // $NON-NLS-1$
        td.value = "pvname<type>";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(6, 12);
        result.addTooltipData(td);
        td = new TooltipData();
        // $NON-NLS-1$
        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();
            // $NON-NLS-1$
            td.value = "pvname";
            td.styles = new ProposalStyle[1];
            td.styles[0] = ProposalStyle.getDefault(from, to);
            result.addTooltipData(td);
        }
        td = new TooltipData();
        // $NON-NLS-1$
        td.value = "pvname<type>";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(from, to);
        result.addTooltipData(td);
        td = new TooltipData();
        // $NON-NLS-1$
        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.csstudio.autocomplete.AutoCompleteResult) ProposalStyle(org.csstudio.autocomplete.proposals.ProposalStyle) TooltipData(org.csstudio.autocomplete.tooltips.TooltipData) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 3 with TooltipData

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

the class SimContentProvider method generateTooltipData.

private TooltipData generateTooltipData(DSFunction function, int currentArgIndex) {
    // build content
    TooltipData td = new TooltipData();
    StringBuilder sb = new StringBuilder();
    sb.append(function.getName());
    int nbArgs = function.getNbArgs();
    if (nbArgs > 0)
        sb.append("(");
    int from = 0, to = 0;
    for (int i = 0; i < nbArgs; i++) {
        if (i == currentArgIndex) {
            from = sb.length();
        }
        sb.append("<");
        sb.append(function.getArgumentTypes().get(i).getSimpleName());
        sb.append(">");
        sb.append(function.getArgumentNames().get(i));
        if (i == currentArgIndex) {
            to = sb.length();
        }
        if (i < nbArgs - 1)
            sb.append(", ");
    }
    if (function.isVarArgs()) {
        if (currentArgIndex >= nbArgs) {
            from = sb.length();
            to = from + 4;
        }
        sb.append(",...");
    }
    if (nbArgs > 0)
        sb.append(")");
    if (function.getTooltip() != null) {
        td.styles = new ProposalStyle[2];
        td.styles[0] = ProposalStyle.getDefault(from, to);
        from = sb.length() + 1;
        sb.append(" " + function.getTooltip());
        to = sb.length();
        td.styles[1] = ProposalStyle.getItalic(from, to);
    } else {
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(from, to);
    }
    td.value = sb.toString();
    return td;
}
Also used : TooltipData(org.csstudio.autocomplete.tooltips.TooltipData)

Aggregations

TooltipData (org.csstudio.autocomplete.tooltips.TooltipData)3 AutoCompleteResult (org.csstudio.autocomplete.AutoCompleteResult)1 Proposal (org.csstudio.autocomplete.proposals.Proposal)1 ProposalStyle (org.csstudio.autocomplete.proposals.ProposalStyle)1