use of org.yamcs.studio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.
the class SysContentProvider method provideFunctions.
private AutoCompleteResult provideFunctions(SysContentDescriptor sysDesc, int limit) {
var result = new AutoCompleteResult();
var count = 0;
var 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;
var offset = SysContentParser.SYS_SOURCE.length();
for (var function : SysContentDescriptor.listFunctions()) {
var m = valuePattern.matcher(function);
if (m.find()) {
var fctDisplay = function;
fctDisplay = SysContentParser.SYS_SOURCE + function;
if (function.equals(SYSTEM_FUNCTION)) {
fctDisplay += SYSTEM_SEPARATOR;
}
var 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;
}
use of org.yamcs.studio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.
the class ParameterContentProvider method listResult.
@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
var content = desc.getValue();
if (content.startsWith(getPrefix())) {
content = content.substring(getPrefix().length());
} else if (requirePrefix()) {
return new AutoCompleteResult();
}
content = AutoCompleteHelper.trimWildcards(content);
// Ignore specific index into array
content = content.replaceAll("\\[[0-9]+\\]", "[]");
var namePattern = AutoCompleteHelper.convertToPattern(content);
namePattern = Pattern.compile(namePattern.pattern(), Pattern.CASE_INSENSITIVE);
var result = new AutoCompleteResult();
var matchCount = 0;
var mdb = YamcsPlugin.getMissionDatabase();
if (mdb != null) {
for (var para : mdb.getParameters()) {
var pvCandidates = new ArrayList<String>();
pvCandidates.add(para.getQualifiedName());
if (para.hasType()) {
scanTypeForPvCandidates(para.getQualifiedName(), para.getType(), pvCandidates);
}
for (var pvCandidate : pvCandidates) {
var proposalValue = requirePrefix() ? getPrefix() + pvCandidate : pvCandidate;
var m = namePattern.matcher(proposalValue);
if (m.find()) {
var p = new Proposal(proposalValue, false);
p.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
result.addProposal(p);
matchCount++;
if (matchCount >= limit) {
break;
}
}
}
if (matchCount >= limit) {
break;
}
}
}
result.setCount(matchCount);
return result;
}
Aggregations