Search in sources :

Example 1 with AutoCompleteResult

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

the class ParameterContentProvider method listResult.

@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
    String content = desc.getValue();
    if (content.startsWith(ParameterContentParser.PARA_SOURCE)) {
        content = content.substring(ParameterContentParser.PARA_SOURCE.length());
    }
    content = AutoCompleteHelper.trimWildcards(content);
    Pattern namePattern = AutoCompleteHelper.convertToPattern(content);
    namePattern = Pattern.compile(namePattern.pattern(), Pattern.CASE_INSENSITIVE);
    AutoCompleteResult pvs = new AutoCompleteResult();
    int matchCount = 0;
    for (ParameterInfo para : ParameterCatalogue.getInstance().getMetaParameters()) {
        Matcher m = namePattern.matcher(para.getQualifiedName());
        if (m.find()) {
            Proposal p = new Proposal(para.getQualifiedName(), false);
            p.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
            pvs.addProposal(p);
            matchCount++;
            if (matchCount >= limit)
                break;
        }
    }
    pvs.setCount(matchCount);
    return pvs;
}
Also used : Pattern(java.util.regex.Pattern) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) Matcher(java.util.regex.Matcher) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 2 with AutoCompleteResult

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

the class AutoCompleteHistoryProvider method listResult.

@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
    String content = desc.getOriginalContent();
    int startIndex = 0;
    if (desc.getContentType().equals(ContentType.PVName)) {
        content = desc.getValue();
        startIndex = desc.getStartIndex();
    }
    AutoCompleteResult result = new AutoCompleteResult();
    String cleanedName = AutoCompleteHelper.trimWildcards(content);
    Pattern namePattern = AutoCompleteHelper.convertToPattern(cleanedName);
    if (namePattern == null)
        return result;
    String entryType = AutoCompleteTypes.PV;
    if (content.startsWith("="))
        entryType = AutoCompleteTypes.Formula;
    LinkedList<String> fifo = new LinkedList<String>();
    fifo.addAll(AutoCompleteUIPlugin.getDefault().getHistory(entryType));
    if (fifo.isEmpty())
        // Empty result
        return result;
    int count = 0;
    for (String entry : fifo) {
        Matcher m = namePattern.matcher(entry);
        if (m.find()) {
            if (count < limit) {
                Proposal proposal = new Proposal(entry, false);
                proposal.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
                proposal.setInsertionPos(startIndex);
                result.addProposal(proposal);
            }
            count++;
        }
    }
    result.setCount(count);
    TopProposalFinder trf = new TopProposalFinder(Preferences.getSeparators());
    for (Proposal p : trf.getTopProposals(Pattern.quote(cleanedName), fifo)) result.addTopProposal(p);
    return result;
}
Also used : Pattern(java.util.regex.Pattern) TopProposalFinder(org.csstudio.autocomplete.proposals.TopProposalFinder) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 3 with AutoCompleteResult

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

the class FormulaFunctionProvider method listResult.

@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
    AutoCompleteResult result = new AutoCompleteResult();
    FunctionDescriptor functionDesc = null;
    if (desc instanceof FunctionDescriptor) {
        functionDesc = (FunctionDescriptor) desc;
    } else {
        // empty result
        return result;
    }
    String nameToFind = functionDesc.getFunctionName();
    // handle proposals
    int count = 0;
    // insertionPos is not yet provided for formula
    // TODO: improve parser
    String originalContent = desc.getOriginalContent();
    int insertionPos = originalContent.lastIndexOf(nameToFind);
    if (!functionDesc.hasOpenBracket()) {
        Proposal topProposal = null;
        String closestMatchingFunction = null;
        for (String functionName : functions.keySet()) {
            if (functionName.startsWith(nameToFind)) {
                Proposal proposal = new Proposal(functionName + "(", false);
                String description = functions.get(functionName).get(0).getDescription() + "\n\n";
                for (FormulaFunction ff : functions.get(functionName)) description += generateSignature(ff);
                proposal.setDescription(description);
                for (FormulaFunction ff : functions.get(functionName)) proposal.addTooltipData(generateTooltipData(ff, 0));
                proposal.addStyle(ProposalStyle.getDefault(0, nameToFind.length() - 1));
                proposal.setInsertionPos(insertionPos);
                // display function icon
                proposal.setFunction(true);
                result.addProposal(proposal);
                count++;
                if (closestMatchingFunction == null || closestMatchingFunction.compareTo(functionName) > 0) {
                    closestMatchingFunction = functionName;
                    topProposal = proposal;
                }
            }
        }
        // handle top proposals
        if (closestMatchingFunction != null)
            result.addTopProposal(topProposal);
    }
    result.setCount(count);
    // handle tooltip
    if (functionDesc.hasOpenBracket() && !functionDesc.isComplete()) {
        for (String setName : FormulaRegistry.getDefault().listFunctionSets()) {
            FormulaFunctionSet set = FormulaRegistry.getDefault().findFunctionSet(setName);
            for (FormulaFunction function : set.findFunctions(nameToFind)) {
                if (function.getName().equals(nameToFind))
                    if (function.getArgumentNames().size() >= functionDesc.getArgs().size() || function.isVarArgs())
                        result.addTooltipData(generateTooltipData(function, functionDesc.getCurrentArgIndex()));
            }
        }
    }
    return result;
}
Also used : FormulaFunctionSet(org.diirt.datasource.formula.FormulaFunctionSet) FormulaFunction(org.diirt.datasource.formula.FormulaFunction) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) FunctionDescriptor(org.csstudio.autocomplete.parser.FunctionDescriptor) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 4 with AutoCompleteResult

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

the class SimContentProvider method listResult.

@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
    AutoCompleteResult result = new AutoCompleteResult();
    FunctionDescriptor functionDesc = null;
    if (desc instanceof FunctionDescriptor) {
        functionDesc = (FunctionDescriptor) desc;
    } else {
        // empty result
        return result;
    }
    String functionName = functionDesc.getFunctionName();
    DSFunctionSet set = DSFunctionRegistry.getDefault().findFunctionSet(SimDSFunctionSet.name);
    // handle proposals
    int count = 0;
    if (!functionDesc.hasOpenBracket()) {
        String regex = functionName;
        regex = regex.replaceAll("\\*", ".*");
        regex = regex.replaceAll("\\?", ".");
        Pattern valuePattern = null;
        try {
            // start with !
            valuePattern = Pattern.compile("^" + regex);
        } catch (Exception e) {
            // empty result
            return result;
        }
        Proposal topProposal = null;
        DSFunction closestMatchingFunction = null;
        int offset = SimContentParser.SIM_SOURCE.length();
        for (DSFunction function : set.getFunctions()) {
            Matcher m = valuePattern.matcher(function.getName());
            if (m.find()) {
                String proposalStr = function.getName();
                if (hasMandatoryArgument(function))
                    proposalStr += "(";
                if (desc.getDefaultDataSource() != SimContentParser.SIM_SOURCE)
                    proposalStr = SimContentParser.SIM_SOURCE + proposalStr;
                Proposal proposal = new Proposal(proposalStr, false);
                String description = function.getDescription() + "\n\n" + generateSignature(function);
                for (DSFunction poly : function.getPolymorphicFunctions()) description += "\n" + generateSignature(poly);
                proposal.setDescription(description);
                int currentArgIndex = -1;
                if (hasMandatoryArgument(function))
                    currentArgIndex = 0;
                proposal.addTooltipData(generateTooltipData(function, currentArgIndex));
                for (DSFunction poly : function.getPolymorphicFunctions()) proposal.addTooltipData(generateTooltipData(poly, currentArgIndex));
                proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
                proposal.setInsertionPos(desc.getStartIndex());
                result.addProposal(proposal);
                count++;
                if (closestMatchingFunction == null || closestMatchingFunction.getName().compareTo(function.getName()) > 0) {
                    closestMatchingFunction = function;
                    topProposal = proposal;
                }
            }
        }
        // handle top proposals
        if (closestMatchingFunction != null && !functionName.isEmpty())
            result.addTopProposal(topProposal);
    }
    result.setCount(count);
    // handle tooltip
    if (!functionDesc.isComplete()) {
        for (DSFunction function : set.findFunctions(functionName)) {
            // no tooltip for incomplete functions => use proposals
            if (function.getName().equals(functionName)) {
                if (checkToken(function, functionDesc))
                    result.addTooltipData(generateTooltipData(function, functionDesc.getCurrentArgIndex()));
                for (DSFunction poly : function.getPolymorphicFunctions()) if (checkToken(poly, functionDesc))
                    result.addTooltipData(generateTooltipData(poly, functionDesc.getCurrentArgIndex()));
            }
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) Matcher(java.util.regex.Matcher) FunctionDescriptor(org.csstudio.autocomplete.parser.FunctionDescriptor) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 5 with AutoCompleteResult

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

the class SysContentProvider method provideFunctions.

private AutoCompleteResult provideFunctions(final SysContentDescriptor sysDesc, final int limit) {
    AutoCompleteResult result = new AutoCompleteResult();
    int count = 0;
    String regex = sysDesc.getValue();
    regex = regex.replaceAll("\\*", ".*");
    regex = regex.replaceAll("\\?", ".");
    Pattern valuePattern = null;
    try {
        // start with !
        valuePattern = Pattern.compile("^" + regex);
    } catch (Exception e) {
        // empty result
        return result;
    }
    Proposal topProposal = null;
    String closestMatchingFunction = null;
    int offset = SysContentParser.SYS_SOURCE.length();
    for (String function : SysContentDescriptor.listFunctions()) {
        Matcher m = valuePattern.matcher(function);
        if (m.find()) {
            String fctDisplay = function;
            if (sysDesc.getDefaultDataSource() != SysContentParser.SYS_SOURCE)
                fctDisplay = SysContentParser.SYS_SOURCE + function;
            if (function.equals(SYSTEM_FUNCTION))
                fctDisplay += SYSTEM_SEPARATOR;
            Proposal proposal = new Proposal(fctDisplay, false);
            proposal.setDescription(SysContentDescriptor.getDescription(function));
            proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
            proposal.setInsertionPos(sysDesc.getStartIndex());
            if (count <= limit)
                result.addProposal(proposal);
            count++;
            if (closestMatchingFunction == null || closestMatchingFunction.compareTo(function) > 0) {
                closestMatchingFunction = function;
                topProposal = proposal;
            }
        }
    }
    // handle top proposals
    if (closestMatchingFunction != null)
        result.addTopProposal(topProposal);
    result.setCount(count);
    return result;
}
Also used : Pattern(java.util.regex.Pattern) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) Matcher(java.util.regex.Matcher) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Aggregations

AutoCompleteResult (org.csstudio.autocomplete.AutoCompleteResult)10 Proposal (org.csstudio.autocomplete.proposals.Proposal)9 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 ArrayList (java.util.ArrayList)2 FunctionDescriptor (org.csstudio.autocomplete.parser.FunctionDescriptor)2 ProposalStyle (org.csstudio.autocomplete.proposals.ProposalStyle)2 TopProposalFinder (org.csstudio.autocomplete.proposals.TopProposalFinder)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Properties (java.util.Properties)1 AutoCompleteService (org.csstudio.autocomplete.AutoCompleteService)1 IAutoCompleteResultListener (org.csstudio.autocomplete.IAutoCompleteResultListener)1 TooltipData (org.csstudio.autocomplete.tooltips.TooltipData)1 ContentProposalList (org.csstudio.autocomplete.ui.content.ContentProposalList)1 FormulaFunction (org.diirt.datasource.formula.FormulaFunction)1 FormulaFunctionSet (org.diirt.datasource.formula.FormulaFunctionSet)1 ParameterInfo (org.yamcs.protobuf.Mdb.ParameterInfo)1