use of org.csstudio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.
the class AutoCompleteProposalProvider method getProposals.
/**
* {@inheritDoc}
*/
@Override
public void getProposals(final String contents, final IContentProposalSearchHandler handler) {
currentId = System.currentTimeMillis();
synchronized (currentList) {
currentList.clear();
currentList.setOriginalValue(contents);
}
AutoCompleteService cns = AutoCompleteService.getInstance();
int expected = cns.get(currentId, AutoCompleteType.valueOf(type), contents, new IAutoCompleteResultListener() {
@Override
public void handleResult(Long uniqueId, Integer index, AutoCompleteResult result) {
if (uniqueId == currentId) {
synchronized (currentList) {
currentList.responseReceived();
}
if (result == null)
return;
List<Proposal> contentProposals = new ArrayList<Proposal>();
if (result.getProposals() != null)
for (final Proposal proposal : result.getProposals()) contentProposals.add(proposal);
Proposal[] contentProposalsArray = contentProposals.toArray(new Proposal[contentProposals.size()]);
List<Proposal> topContentProposals = new ArrayList<Proposal>();
if (result.getTopProposals() != null)
for (final Proposal proposal : result.getTopProposals()) topContentProposals.add(proposal);
ContentProposalList cpl = null;
synchronized (currentList) {
if (result.getProvider() != null)
currentList.addProposals(result.getProvider(), contentProposalsArray, result.getCount(), index);
currentList.addTopProposals(topContentProposals);
cpl = currentList.clone();
}
handler.handleResult(cpl);
handler.handleTooltips(result.getTooltips());
// System.out.println("PROCESSED: " + uniqueId + ", " + index);
}
}
});
currentList.setExpected(expected);
}
use of org.csstudio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.
the class DataSourceProvider method listResult.
@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
AutoCompleteResult result = new AutoCompleteResult();
for (String ds : dataSources) {
if (ds.startsWith(desc.getValue())) {
Proposal proposal = new Proposal(ds, true);
proposal.addStyle(ProposalStyle.getDefault(0, desc.getValue().length() - 1));
proposal.setInsertionPos(desc.getStartIndex());
result.addTopProposal(proposal);
}
}
return result;
}
use of org.csstudio.autocomplete.AutoCompleteResult 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;
}
use of org.csstudio.autocomplete.AutoCompleteResult 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;
}
use of org.csstudio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.
the class SysContentProvider method listResult.
@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
AutoCompleteResult result = new AutoCompleteResult();
SysContentDescriptor sysDesc = null;
if (desc instanceof SysContentDescriptor) {
sysDesc = (SysContentDescriptor) desc;
} else {
// empty result
return result;
}
int dotIndex = desc.getValue().indexOf(SYSTEM_SEPARATOR);
if (dotIndex == -1) {
result = provideFunctions(sysDesc, limit);
} else if (desc.getValue().substring(0, dotIndex).equals(SYSTEM_FUNCTION)) {
result = provideSystemProperties(sysDesc, limit);
}
Collections.sort(result.getProposals());
return result;
}
Aggregations