Search in sources :

Example 91 with StyledString

use of org.eclipse.jface.viewers.StyledString in project linuxtools by eclipse.

the class DockerImageHierarchyLabelProvider method getStyledText.

/**
 * @param image
 *            the {@link IDockerImage} to process
 * @return the {@link StyledString} to be displayed.
 */
public static StyledString getStyledText(final IDockerImage image) {
    final Map<String, List<String>> imageTagsByRepo = DockerImage.extractTagsByRepo(image.repoTags());
    final List<String> imageRepos = new ArrayList<>(imageTagsByRepo.keySet());
    Collections.sort(imageRepos);
    final StyledString result = new StyledString();
    imageRepos.forEach(repo -> {
        result.append(repo);
        final List<String> tags = imageTagsByRepo.get(repo);
        final String joinedTags = tags.stream().collect(// $NON-NLS-1$
        Collectors.joining(", "));
        result.append(':');
        // $NON-NLS-1$
        result.append(joinedTags, StyledString.COUNTER_STYLER);
        result.append(' ');
    });
    // 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) image).shortId(), StyledString.QUALIFIER_STYLER).append(')', // $NON-NLS-1$
    StyledString.QUALIFIER_STYLER);
    return result;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) 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)

Example 92 with StyledString

use of org.eclipse.jface.viewers.StyledString in project linuxtools by eclipse.

the class LabelProviderUtils method getStyledText.

/**
 * @param mapping
 *            the {@link IDockerPortMapping} to process
 * @return the {@link StyledString} to be displayed.
 */
public static StyledString getStyledText(final IDockerPortMapping mapping) {
    final StyledString styledString = new StyledString();
    // $NON-NLS-1$
    styledString.append(mapping.getIp() + ":" + mapping.getPublicPort()).append(// $NON-NLS-1$
    " -> ").append(Integer.toString(mapping.getPrivatePort())).append(// $NON-NLS-1$ //$NON-NLS-2$
    " (" + mapping.getType() + ")", StyledString.QUALIFIER_STYLER);
    return styledString;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString)

Example 93 with StyledString

use of org.eclipse.jface.viewers.StyledString in project linuxtools by eclipse.

the class LabelProviderUtils method getStyledText.

/**
 * @param connection
 *            the {@link IDockerConnection} to process
 * @return the {@link StyledString} to be displayed.
 */
public static StyledString getStyledText(final IDockerConnection connection) {
    final String connectionName = (connection.getName() != null && !connection.getName().isEmpty()) ? connection.getName() : // $NON-NLS-1$
    DVMessages.getString("Connection.unnamed");
    final StyledString styledString = new StyledString();
    styledString.append(connectionName);
    if (connection.getUri() != null && !connection.getUri().isEmpty()) {
        styledString.append(// $NON-NLS-1$
        " (" + connection.getUri() + ")", // $NON-NLS-1$
        StyledString.QUALIFIER_STYLER);
    }
    return styledString;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 94 with StyledString

use of org.eclipse.jface.viewers.StyledString in project knime-core by knime.

the class RepositoryStyledLabelProvider method update.

@Override
public void update(final ViewerCell cell) {
    Object obj = cell.getElement();
    if (obj instanceof IRepositoryObject) {
        StyledString styledString = new StyledString(m_provider.getText(obj));
        if (m_appendCategory) {
            // receive the category string.
            String categoryString = getCategoryString((IRepositoryObject) obj);
            if (!categoryString.isEmpty()) {
                styledString.append(String.format("\t - %s", categoryString), StyledString.DECORATIONS_STYLER);
            }
        }
        if (m_appendAdditionalInfoKeys.length > 0) {
            if (obj instanceof AbstractRepositoryObject) {
                AbstractRepositoryObject aro = (AbstractRepositoryObject) obj;
                for (String key : m_appendAdditionalInfoKeys) {
                    if (aro.getAdditionalInfo(key) != null) {
                        styledString.append(String.format("\t [%s]", ((AbstractRepositoryObject) obj).getAdditionalInfo(key)), StyledString.QUALIFIER_STYLER);
                    }
                }
            }
        }
        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());
    } else {
        cell.setText(m_provider.getText(obj));
    }
    cell.setImage(m_provider.getImage(obj));
}
Also used : AbstractRepositoryObject(org.knime.workbench.repository.model.AbstractRepositoryObject) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) IContainerObject(org.knime.workbench.repository.model.IContainerObject) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) AbstractRepositoryObject(org.knime.workbench.repository.model.AbstractRepositoryObject) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 95 with StyledString

use of org.eclipse.jface.viewers.StyledString in project knime-core by knime.

the class LinkStyleLabelProvider method update.

@Override
public void update(final ViewerCell cell) {
    Object element = cell.getElement();
    if (element instanceof String) {
        // Multi-font support only works in JFace 3.5 and above (specifically, 3.5 M4 and above).
        // With JFace 3.4, the font information (bold in this example) will be ignored.
        Styler style = linkStyler;
        StyledString styledString = new StyledString((String) element, style);
        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());
    } else {
        // $NON-NLS-1$
        cell.setText("Unknown element");
    }
    super.update(cell);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler)

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