use of org.csstudio.autocomplete.proposals.TopProposalFinder 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;
}
use of org.csstudio.autocomplete.proposals.TopProposalFinder in project yamcs-studio by yamcs.
the class SysContentProvider method provideSystemProperties.
private AutoCompleteResult provideSystemProperties(final SysContentDescriptor sysDesc, final int limit) {
AutoCompleteResult result = new AutoCompleteResult();
int count = 0;
int dotIndex = sysDesc.getValue().indexOf(SYSTEM_SEPARATOR);
String propValue = sysDesc.getValue().substring(dotIndex + 1);
String regex = propValue.replaceAll("\\.", "\\\\.");
;
regex = regex.replaceAll("\\*", ".*");
regex = regex.replaceAll("\\?", ".");
Pattern valuePattern = null;
try {
// start with !
valuePattern = Pattern.compile("^" + regex);
} catch (Exception e) {
// empty result
return result;
}
List<String> matchingProperties = new ArrayList<String>();
Properties systemProperties = System.getProperties();
Enumeration<?> enuProp = systemProperties.propertyNames();
int offset = SysContentParser.SYS_SOURCE.length() + 7;
while (enuProp.hasMoreElements()) {
String propertyName = (String) enuProp.nextElement();
String propertyValue = systemProperties.getProperty(propertyName);
Matcher m = valuePattern.matcher(propertyName);
if (m.find()) {
String propDisplay = SYSTEM_FUNCTION + SYSTEM_SEPARATOR + propertyName;
if (sysDesc.getDefaultDataSource() != SysContentParser.SYS_SOURCE)
propDisplay = SysContentParser.SYS_SOURCE + propDisplay;
Proposal proposal = new Proposal(propDisplay, false);
proposal.setDescription(propertyValue);
proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
proposal.setInsertionPos(sysDesc.getStartIndex());
if (count <= limit)
result.addProposal(proposal);
matchingProperties.add(propertyName);
count++;
}
}
// handle top proposals
TopProposalFinder tpf = new TopProposalFinder(SYSTEM_SEPARATOR);
for (Proposal tp : tpf.getTopProposals(propValue, matchingProperties)) {
String propDisplay = SYSTEM_FUNCTION + SYSTEM_SEPARATOR + tp.getValue();
if (sysDesc.getDefaultDataSource() != SysContentParser.SYS_SOURCE)
propDisplay = SysContentParser.SYS_SOURCE + propDisplay;
Proposal proposal = new Proposal(propDisplay, tp.isPartial());
String propertyValue = systemProperties.getProperty(tp.getValue());
proposal.setDescription(propertyValue);
ProposalStyle tpStyle = tp.getStyles().get(0);
proposal.addStyle(ProposalStyle.getDefault(tpStyle.from, (offset + tpStyle.to)));
proposal.setInsertionPos(sysDesc.getStartIndex());
result.addTopProposal(proposal);
}
result.setCount(count);
return result;
}
Aggregations