use of org.eclipse.jface.viewers.StyledString in project xtext-xtend by eclipse.
the class AbstractMultiModeOutlineTreeProvider method computeDecoratedText.
protected Object computeDecoratedText(final Object modelElement, final int inheritanceDepth) {
Object supertext = super.getText(modelElement);
if (!(supertext instanceof StyledString)) {
return supertext;
}
StyledString styledText = (StyledString) supertext;
if (inheritanceDepth > 0) {
styledText = applyStylerToFirstSegment(styledText, ColoringLabelProvider.INHERITED_STYLER);
}
if (modelElement instanceof JvmIdentifiableElement) {
JvmIdentifiableElement jvmElement = (JvmIdentifiableElement) modelElement;
if (!getAssociations().getSourceElements(jvmElement).isEmpty() && !getAssociations().isPrimaryJvmElement(jvmElement)) {
styledText = applyStylerToFirstSegment(styledText, StyledString.QUALIFIER_STYLER);
}
}
if (isShowInherited()) {
if (modelElement instanceof IResolvedFeature) {
String qualifier = createQualifier((IResolvedFeature) modelElement);
appendQualifier(styledText, qualifier);
} else if (modelElement instanceof JvmMember) {
String qualifier = createQualifier((JvmMember) modelElement);
appendQualifier(styledText, qualifier);
} else if (modelElement instanceof XtendMember) {
XtendMember xtendMember = (XtendMember) modelElement;
if (xtendMember.eContainer() instanceof XtendTypeDeclaration) {
String qualifiedName = createQualifier((XtendTypeDeclaration) xtendMember.eContainer(), '.');
appendQualifier(styledText, qualifiedName);
} else if (xtendMember instanceof XtendTypeDeclaration) {
XtendFile xtendFile = EcoreUtil2.getContainerOfType(xtendMember, XtendFile.class);
String qualifiedName = xtendFile.getPackage() == null ? "(default package)" : xtendFile.getPackage();
appendQualifier(styledText, qualifiedName);
}
}
}
return styledText;
}
use of org.eclipse.jface.viewers.StyledString in project xtext-xtend by eclipse.
the class XtendProposalProvider method completeParameter_Name.
@Override
public void completeParameter_Name(final EObject model, Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
if (model instanceof XtendParameter) {
final List<XtendParameter> siblings = EcoreUtil2.getSiblingsOfType(model, XtendParameter.class);
Set<String> alreadyTaken = Sets.newHashSet();
for (XtendParameter sibling : siblings) {
alreadyTaken.add(sibling.getName());
}
alreadyTaken.addAll(getAllKeywords());
completions.getVariableProposals(model, XtendPackage.Literals.XTEND_PARAMETER__PARAMETER_TYPE, VariableType.PARAMETER, alreadyTaken, new JdtVariableCompletions.CompletionDataAcceptor() {
@Override
public void accept(String replaceText, StyledString label, Image img) {
acceptor.accept(createCompletionProposal(replaceText, label, img, context));
}
});
} else {
super.completeParameter_Name(model, assignment, context, acceptor);
}
}
use of org.eclipse.jface.viewers.StyledString in project linuxtools by eclipse.
the class StyledTextBuilder method parse.
/**
* Parses the given {@code lineText} and returns a {@link StyledString} with
* configured foreground color on specific portions.
*
* @param lineText
* the line of text to parse
* @return the corresponding {@link StyledString}
* @see <a href="https://en.wikipedia.org/wiki/ANSI_escape_code">ANSI escape
* codes</a>
*/
public static StyledString parse(final String lineText) {
final StyledString result = new StyledString();
// looking for blocks of characters starting with 'ESC[xxm' (where 'xx'
// is
// a color code)
// and optionally ending with 'ESC[0m'
final Pattern colorSequencePattern = Pattern.compile(// $NON-NLS-1$
"\\x1b\\[(?<colorcode>\\d{1,2})m(?<content>.*)");
final Matcher colorSequenceMatcher = colorSequencePattern.matcher(lineText);
int lastColorSequencePosition = 0;
// default color (Black)
int lastColorSequenceCode = 0;
while (colorSequenceMatcher.find(lastColorSequencePosition)) {
final int currentColorSequenceStartPosition = colorSequenceMatcher.start();
final String colorCode = colorSequenceMatcher.group("colorcode");
// color code boundaries or with the last color sequence position
if (lastColorSequencePosition < currentColorSequenceStartPosition) {
final String inbetweenContent = lineText.substring(lastColorSequencePosition, currentColorSequenceStartPosition);
if (!inbetweenContent.isEmpty()) {
result.append(inbetweenContent, StylerBuilder.styler(lastColorSequenceCode));
}
}
lastColorSequencePosition = currentColorSequenceStartPosition + // counting the 'ESC' char too
(ESC + "[" + colorCode + "m").length();
lastColorSequenceCode = Integer.parseInt(colorCode);
}
// boundaries
if (lastColorSequencePosition < lineText.length()) {
final String lastSequence = lineText.substring(lastColorSequencePosition);
result.append(new StyledString(lastSequence, StylerBuilder.styler(lastColorSequenceCode)));
}
return result;
}
use of org.eclipse.jface.viewers.StyledString in project linuxtools by eclipse.
the class LabelProviderUtils method getStyledText.
/**
* @param containerVolume
* the {@link DockerContainerVolume} to process
* @return the {@link StyledString} to be displayed.
*/
public static StyledString getStyledText(final DockerContainerVolume containerVolume) {
final StyledString styledString = new StyledString();
final String hostPath = containerVolume.getHostPath();
if (containerVolume.getHostPath() != null && containerVolume.getContainerPath() != null) {
// $NON-NLS-1$
styledString.append(hostPath).append(" -> ").append(containerVolume.getContainerPath());
} else if (containerVolume.getHostPath() == null && containerVolume.getContainerPath() != null) {
styledString.append(containerVolume.getContainerPath());
}
if (containerVolume.getFlags() != null) {
// $NON-NLS-1$ //$NON-NLS-2$
styledString.append(// $NON-NLS-1$ //$NON-NLS-2$
" (" + containerVolume.getFlags() + ")", StyledString.QUALIFIER_STYLER);
}
return styledString;
}
use of org.eclipse.jface.viewers.StyledString in project linuxtools by eclipse.
the class LabelProviderUtils method getStyledText.
/**
* @param dockerImage
* the {@link IDockerImage} to process
* @return the {@link StyledString} to be displayed.
*/
public static StyledString getStyledText(final IDockerImage dockerImage) {
final StyledString result = new StyledString(dockerImage.repo());
if (!dockerImage.tags().isEmpty()) {
final List<String> tags = new ArrayList<>(dockerImage.tags());
Collections.sort(tags);
result.append(":");
// $NON-NLS-1$
result.append(// $NON-NLS-1$
tags.stream().collect(Collectors.joining(", ")), StyledString.COUNTER_STYLER);
}
// TODO: remove the cast to 'DockerImage' once the 'shortId()'
// method is in the public API
// $NON-NLS-1$
result.append(" (", StyledString.QUALIFIER_STYLER).append(((DockerImage) dockerImage).shortId(), StyledString.QUALIFIER_STYLER).append(')', // $NON-NLS-1$
StyledString.QUALIFIER_STYLER);
return result;
}
Aggregations