use of org.csstudio.autocomplete.proposals.ProposalStyle in project yamcs-studio by yamcs.
the class ContentHelperPopup method updateDisplay.
private void updateDisplay() {
if (content == null || !isValid())
return;
text.setText(content.value);
for (ProposalStyle ps : content.styles) {
Color color = control.getDisplay().getSystemColor(ps.fontColor);
text.setStyle(color, ps.fontStyle, ps.from, ps.to - ps.from);
}
}
use of org.csstudio.autocomplete.proposals.ProposalStyle in project yamcs-studio by yamcs.
the class ContentProposalPopup method initializeTextLayouts.
private void initializeTextLayouts() {
Display display = Display.getCurrent();
FontData defaultFontData = display.getSystemFont().getFontData()[0];
String fontName = defaultFontData.getName();
int fontHeight = defaultFontData.getHeight();
Font headerFont = new Font(display, new FontData(fontName, fontHeight, SWT.ITALIC | SWT.BOLD));
Font noFont = new Font(display, new FontData(fontName, fontHeight, SWT.NORMAL));
Color black = display.getSystemColor(SWT.COLOR_BLACK);
int index = 0;
textLayouts = new SSTextLayout[getTableLength()];
for (Proposal proposal : proposalList.getTopProposalList()) {
textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
String text = getString(proposal);
textLayouts[index].init(display, text);
textLayouts[index].addStyle(noFont, black, 0, text.length());
if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
for (ProposalStyle style : proposal.getStyles()) {
FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
Font font = new Font(display, newFontData);
Color color = display.getSystemColor(style.fontColor);
textLayouts[index].addStyle(font, color, style.from, style.to);
}
}
index++;
}
for (String provider : proposalList.getProviderList()) {
textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
int count = proposalList.getCount(provider);
String headerText = provider + " (" + count + " matching items)";
textLayouts[index].init(display, headerText);
textLayouts[index].addStyle(headerFont, black, 0, headerText.length());
index++;
for (Proposal proposal : proposalList.getProposals(provider)) {
textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
String text = getString(proposal);
textLayouts[index].init(display, text);
textLayouts[index].addStyle(noFont, black, 0, text.length());
if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
for (ProposalStyle style : proposal.getStyles()) {
FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
Font font = new Font(display, newFontData);
Color color = display.getSystemColor(style.fontColor);
textLayouts[index].addStyle(font, color, style.from, style.to);
}
}
index++;
}
}
for (SSTextLayout sstl : textLayouts) if (sstl != null && sstl.getBounds() != null && sstl.getBounds().width > maxItemWidth)
maxItemWidth = sstl.getBounds().width;
adjustTableBounds();
}
use of org.csstudio.autocomplete.proposals.ProposalStyle 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.proposals.ProposalStyle 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.proposals.ProposalStyle in project yamcs-studio by yamcs.
the class TooltipDataHandler method generateTooltipContent.
public TooltipContent generateTooltipContent(String fieldContent) {
if (tooltipDataList.isEmpty() || fieldContent == null || fieldContent.trim().isEmpty())
// no content
return null;
// build content
int offset = 0, maxLineLength = 0, numberOfLines = 0;
StringBuilder sb = new StringBuilder();
List<ProposalStyle> styleList = new ArrayList<ProposalStyle>();
synchronized (tooltipDataList) {
for (TooltipData data : tooltipDataList) {
int startLength = sb.length();
sb.append(data.value);
sb.append("\n");
if (data.styles != null) {
for (ProposalStyle style : data.styles) {
ProposalStyle ps = new ProposalStyle(style);
ps.from += offset;
ps.to += offset;
styleList.add(ps);
}
}
offset += sb.length() - startLength;
maxLineLength = Math.max(maxLineLength, sb.length() - startLength);
numberOfLines++;
}
}
if (sb.length() == 0) {
// no content
return null;
}
// delete last \n
sb.deleteCharAt(sb.length() - 1);
TooltipContent tc = new TooltipContent();
tc.value = sb.toString();
tc.styles = styleList.toArray(new ProposalStyle[styleList.size()]);
tc.numberOfLines = numberOfLines;
tc.maxLineLength = maxLineLength;
return tc;
}
Aggregations