use of org.yamcs.studio.autocomplete.proposals.ProposalStyle in project yamcs-studio by yamcs.
the class LocalContentProvider method listResult.
@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
var 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
var count = 0;
if (locDesc.isCompletingVType() && locDesc.getvType() != null) {
var type = locDesc.getvType();
Proposal topProposal = null;
String closestMatchingType = null;
for (var vType : LocalContentDescriptor.listVTypes()) {
if (vType.startsWith(type)) {
var prefix = locDesc.getPvName() + LocalContentParser.VTYPE_START;
prefix = LocalContentParser.LOCAL_SOURCE + prefix;
var offset = prefix.length();
var 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();
td.value = "pvname";
var vType = locDesc.getvType();
if (vType != null) {
td.value += LocalContentParser.VTYPE_START + locDesc.getvType() + LocalContentParser.VTYPE_END;
}
td.value += LocalContentParser.INITIAL_VALUE_START;
var start = td.value.length();
td.value += locDesc.getInitialValueTooltip();
var 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();
td.value = "pvname<type>";
td.styles = new ProposalStyle[1];
td.styles[0] = ProposalStyle.getDefault(6, 12);
result.addTooltipData(td);
td = new TooltipData();
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();
td.value = "pvname";
td.styles = new ProposalStyle[1];
td.styles[0] = ProposalStyle.getDefault(from, to);
result.addTooltipData(td);
}
td = new TooltipData();
td.value = "pvname<type>";
td.styles = new ProposalStyle[1];
td.styles[0] = ProposalStyle.getDefault(from, to);
result.addTooltipData(td);
td = new TooltipData();
td.value = "pvname<type>(initialValue)";
td.styles = new ProposalStyle[1];
td.styles[0] = ProposalStyle.getDefault(from, to);
result.addTooltipData(td);
}
return result;
}
Aggregations