Search in sources :

Example 36 with StyledString

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IResolvedFeature(org.eclipse.xtext.xbase.typesystem.override.IResolvedFeature)

Example 37 with StyledString

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);
    }
}
Also used : XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JdtVariableCompletions(org.eclipse.xtext.common.types.xtext.ui.JdtVariableCompletions) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image)

Example 38 with StyledString

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 39 with StyledString

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;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 40 with 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;
}
Also used : ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DockerImage(org.eclipse.linuxtools.internal.docker.core.DockerImage) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

StyledString (org.eclipse.jface.viewers.StyledString)95 Image (org.eclipse.swt.graphics.Image)17 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)8 LazyJavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal)8 ViewerCell (org.eclipse.jface.viewers.ViewerCell)5 GridData (org.eclipse.swt.layout.GridData)5 Table (org.eclipse.swt.widgets.Table)5 Entry (java.util.Map.Entry)4 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)4 Styler (org.eclipse.jface.viewers.StyledString.Styler)4 Capability (org.osgi.resource.Capability)4 EObject (org.eclipse.emf.ecore.EObject)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Version (org.osgi.framework.Version)3 Resource (org.osgi.resource.Resource)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IStatus (org.eclipse.core.runtime.IStatus)2