Example usage for org.eclipse.jface.viewers StyledString StyledString

List of usage examples for org.eclipse.jface.viewers StyledString StyledString

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StyledString StyledString.

Prototype

public StyledString(String string, Styler styler) 

Source Link

Document

Creates an StyledString initialized with a string and a style.

Usage

From source file:bndtools.model.importanalysis.ImportsExportsTreeLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    if (IMPORTS_PLACEHOLDER.equals(cell.getElement())) {
        if (cell.getColumnIndex() == 0) {
            cell.setImage(pkgFolderImg);
            cell.setText("Import Packages");
        }//from  w ww.j a v a  2  s .  c om
    } else if (EXPORTS_PLACEHOLDER.equals(cell.getElement())) {
        if (cell.getColumnIndex() == 0) {
            cell.setImage(pkgFolderImg);
            cell.setText("Export Packages");
        }
    } else if (REQUIRED_PLACEHOLDER.equals(cell.getElement())) {
        if (cell.getColumnIndex() == 0) {
            cell.setImage(bundleFolderImg);
            cell.setText("Required Bundles");
        }
    } else if (cell.getElement() instanceof ImportUsedByPackage) {
        if (cell.getColumnIndex() == 0) {
            StyledString styledString = new StyledString("Used By: ", UIConstants.ITALIC_QUALIFIER_STYLER);
            styledString.append(((ImportUsedByPackage) cell.getElement()).usedByName);
            cell.setText(styledString.getString());
            cell.setStyleRanges(styledString.getStyleRanges());
        }
    } else if (cell.getElement() instanceof ImportUsedByClass) {
        if (cell.getColumnIndex() == 0) {
            ImportUsedByClass importUsedBy = (ImportUsedByClass) cell.getElement();
            String fqn = importUsedBy.clazz.getFQN();
            String className = fqn.substring(fqn.lastIndexOf('.') + 1);
            cell.setText(className);
            cell.setImage(classImg);
        }
    } else if (cell.getElement() instanceof ExportUsesPackage) {
        if (cell.getColumnIndex() == 0) {
            StyledString styledString = new StyledString("Uses: ", UIConstants.ITALIC_QUALIFIER_STYLER);
            styledString.append(((ExportUsesPackage) cell.getElement()).name);
            cell.setText(styledString.getString());
            cell.setStyleRanges(styledString.getStyleRanges());
        }
    } else if (cell.getElement() instanceof RequiredBundle) {
        RequiredBundle rb = (RequiredBundle) cell.getElement();
        switch (cell.getColumnIndex()) {
        case 0:
            StyledString label;
            if (rb.isSatisfied())
                label = new StyledString(rb.getName(), StyledString.QUALIFIER_STYLER);
            else
                label = new StyledString(rb.getName());

            String version = rb.getAttribs().get(Constants.BUNDLE_VERSION_ATTRIBUTE);
            if (version != null)
                label.append(" " + version, StyledString.COUNTER_STYLER);

            String resolution = rb.getAttribs().get(Constants.RESOLUTION_DIRECTIVE);
            boolean optional = org.osgi.framework.Constants.RESOLUTION_OPTIONAL.equals(resolution);
            if (resolution != null)
                label.append(" <" + resolution + ">", UIConstants.ITALIC_QUALIFIER_STYLER);

            cell.setText(label.getString());
            cell.setStyleRanges(label.getStyleRanges());

            if (optional)
                cell.setImage(requiredBundleOptImg);
            else if (rb.isSatisfied())
                cell.setImage(requiredBundleSatisfiedImg);
            else
                cell.setImage(requiredBundleImg);
            break;
        case 1:
            cell.setText(formatAttribs(rb.getAttribs()));
            break;
        default:
            break;
        }
    } else if (cell.getElement() instanceof ImportPackage || cell.getElement() instanceof ExportPackage) {
        HeaderClause entry = (HeaderClause) cell.getElement();
        switch (cell.getColumnIndex()) {
        case 0:
            boolean selfImport = false;
            if (entry instanceof ImportPackage) {
                selfImport = ((ImportPackage) entry).isSelfImport();
            }

            StyledString styledString;
            if (selfImport) {
                styledString = new StyledString(entry.getName(), StyledString.QUALIFIER_STYLER);
            } else {
                styledString = new StyledString(entry.getName());
            }

            String version = entry.getAttribs().get(Constants.VERSION_ATTRIBUTE);
            if (version != null)
                styledString.append(" " + version, StyledString.COUNTER_STYLER);

            String resolution = entry.getAttribs().get(Constants.RESOLUTION_DIRECTIVE);
            boolean optional = org.osgi.framework.Constants.RESOLUTION_OPTIONAL.equals(resolution);
            if (resolution != null) {
                styledString.append(" <" + resolution + ">", UIConstants.ITALIC_QUALIFIER_STYLER);
            }

            cell.setText(styledString.getString());
            cell.setStyleRanges(styledString.getStyleRanges());
            if (optional) {
                cell.setImage(packageOptImg);
            } else if (selfImport) {
                cell.setImage(packageImpExpImg);
            } else {
                cell.setImage(packageImg);
            }
            break;
        case 1:
            cell.setText(formatAttribs(entry.getAttribs()));
            break;
        default:
            break;
        }
    }
}

From source file:com.aptana.editor.common.scripting.snippets.SnippetTemplateProposal.java

License:Open Source License

public StyledString getStyledDisplayString() {
    if (styledDisplayString == null) {
        Template template = getTemplate();
        styledDisplayString = new StyledString(template.getDescription(), styler);
    }/*from w w w .  j  a v  a  2s  .c om*/
    return styledDisplayString;
}

From source file:com.aptana.editor.common.scripting.snippets.SnippetTemplateProposal.java

License:Open Source License

public StyledString getStyledActivationString() {
    if (styledActivationString == null) {
        Template template = getTemplate();
        styledActivationString = new StyledString(String.format("%1$10.10s ", //$NON-NLS-1$
                template.getName() + " \u00bb") //$NON-NLS-1$
                + ((triggerChar == '\000') ? " " : String.valueOf(triggerChar)) //$NON-NLS-1$
                // Need padding on windows to work around the width computation
                + (Platform.OS_WIN32.equals(Platform.getOS()) ? "                                " : ""), //$NON-NLS-1$ //$NON-NLS-2$ 
                styler);/*from  w  w w . j a  va  2  s  .  com*/
    }
    return styledActivationString;
}

From source file:com.dubture.symfony.ui.views.ServiceLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {

    Object element = cell.getElement();

    Styler style = null;/*from  ww w . j a v a2s  . c  o  m*/

    if (element instanceof IProject) {

        IProject project = (IProject) element;
        StyledString styledString = new StyledString(project.getName(), style);
        cell.setText(styledString.toString());
        cell.setImage(PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_PROJECT));

    } else if (element instanceof Service) {

        Service service = (Service) element;
        String name = service.getClassName() != null ? service.getClassName() : service.getId();
        StyledString styledString = new StyledString(name, style);

        String decoration = MessageFormat.format(" [{0}]", new Object[] { service.getId() }); //$NON-NLS-1$
        styledString.append(decoration, StyledString.DECORATIONS_STYLER);

        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());

        if (service.isPublic()) {
            cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_SERVICE_PUBLIC));
        } else {
            cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_SERVICE_PRIVATE));
        }

    } else if (element instanceof Bundle) {

        Bundle bundle = (Bundle) element;

        StyledString styledString = new StyledString(bundle.getElementName(), style);
        cell.setText(styledString.toString());
        cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_BUNDLE2));

    }
}

From source file:com.google.dart.tools.search.internal.ui.text.FileLabelProvider.java

License:Open Source License

@SuppressWarnings("unchecked")
private StyledString getLineElementLabel(LineElement lineElement) {
    int lineNumber = lineElement.getLine();
    String lineNumberString = Messages.format(SearchMessages.FileLabelProvider_line_number,
            new Integer(lineNumber));

    StyledString str = new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER);

    Match[] matches = lineElement.getMatches(fPage.getInput());
    Arrays.sort(matches, fMatchComparator);

    String content = lineElement.getContents();

    int pos = evaluateLineStart(matches, content, lineElement.getOffset());

    int length = content.length();

    int charsToCut = getCharsToCut(length, matches); // number of characters to leave away if the line is too long
    for (int i = 0; i < matches.length; i++) {
        FileMatch match = (FileMatch) matches[i];
        int start = Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0);
        // append gap between last match and the new one
        if (pos < start) {
            if (charsToCut > 0) {
                charsToCut = appendShortenedGap(content, pos, start, charsToCut, i == 0, str);
            } else {
                str.append(content.substring(pos, start));
            }/*from  ww w  .j a v  a 2s.c o m*/
        }
        // append match
        int end = Math.min(match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(),
                lineElement.getLength());
        str.append(content.substring(start, end), DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE);
        pos = end;
    }
    // append rest of the line
    if (charsToCut > 0) {
        appendShortenedGap(content, pos, length, charsToCut, false, str);
    } else {
        str.append(content.substring(pos));
    }
    return str;
}

From source file:com.google.dart.tools.ui.callhierarchy.CallHierarchyLabelProvider.java

License:Open Source License

@Override
public StyledString getStyledText(Object element) {
    if (isNormalMethodWrapper(element)) {
        MethodWrapper wrapper = (MethodWrapper) element;
        String decorated = getElementLabel(wrapper);

        StyledString styledLabel = super.getStyledText(wrapper.getMember());
        StyledString styledDecorated = StyledCellLabelProvider.styleDecoratedString(decorated,
                StyledString.COUNTER_STYLER, styledLabel);
        if (isSpecialConstructorNode(wrapper)) {
            decorated = Messages.format(CallHierarchyMessages.CallHierarchyLabelProvider_constructor_label,
                    decorated);//from  ww w  .  j  a v  a2 s.  c  o  m
            styledDecorated = StyledCellLabelProvider.styleDecoratedString(decorated,
                    ColoringLabelProvider.INHERITED_STYLER, styledDecorated);
        }
        return styledDecorated;
    }

    String specialLabel = getSpecialLabel(element);
    Styler styler = element instanceof RealCallers ? ColoringLabelProvider.INHERITED_STYLER : null;
    return new StyledString(specialLabel, styler);
}

From source file:com.google.dart.tools.ui.internal.filesview.ResourceLabelProvider.java

License:Open Source License

@Override
public StyledString getStyledText(Object element) {
    if (element instanceof IResource) {
        IResource resource = (IResource) element;

        // Un-analyzed resources are grey.
        if (!DartCore.isAnalyzed(resource)) {
            return new StyledString(resource.getName(), StyledString.QUALIFIER_STYLER);
        }/*from  ww  w. j  a va  2  s  .  co m*/

        StyledString string = new StyledString(resource.getName());

        DartElement dartElement = DartCore.create(resource);

        // Append the library name to library units.
        if (dartElement instanceof CompilationUnit) {
            if (((CompilationUnit) dartElement).definesLibrary()) {
                DartLibrary library = ((CompilationUnit) dartElement).getLibrary();

                string.append(" [" + library.getDisplayName() + "]", StyledString.QUALIFIER_STYLER);
            }
        }

        return string;
    }
    if (element instanceof DartLibraryNode && ((DartLibraryNode) element).getCategory() != null) {
        StyledString string = new StyledString(((DartLibraryNode) element).getLabel());
        string.append(" [" + ((DartLibraryNode) element).getCategory() + "]", StyledString.QUALIFIER_STYLER);

        return string;
    }

    return workbenchLabelProvider.getStyledText(element);
}

From source file:com.mentor.nucleus.bp.ui.search.providers.ModelSearchLabelProvider.java

License:Open Source License

private StyledString getMatchLabel(Match_c element) {
    ContentMatch_c cm = ContentMatch_c.getOneSR_CMOnR9801(element);
    if (cm != null) {
        String content = getContentFor(cm);
        int[] lineData = calculateLineNumber(content, cm.getStartposition());
        int lineStart = lineData[1];
        int lineEnd = lineData[2];
        int lineNumber = lineData[0];
        StyledString string = new StyledString(lineNumber + ": ", StyledString.QUALIFIER_STYLER);
        if (lineStart != cm.getStartposition()) {
            string.append(content.substring(lineStart, cm.getStartposition()));
        }/*from   www .  j a  va  2s . co m*/
        if (lineEnd < cm.getStartposition() + cm.getMatchlength()) {
            string.append(content.substring(cm.getStartposition(), lineEnd),
                    DecoratingModelSearchLabelProvider.HIGHLIGHT_STYLE);
        } else {
            string.append(content.substring(cm.getStartposition(), cm.getStartposition() + cm.getMatchlength()),
                    DecoratingModelSearchLabelProvider.HIGHLIGHT_STYLE);
        }
        if (lineEnd > cm.getStartposition() + cm.getMatchlength()) {
            string.append(content.substring(cm.getStartposition() + cm.getMatchlength(), lineEnd));
        }
        return string;
    }
    return new StyledString(getText(element));
}

From source file:com.netxforge.netxstudio.callflow.screens.CallFlowsTreeLabelProvider.java

License:Open Source License

private void updateColumn5(ViewerCell cell, Object element) {
    if (element instanceof ServiceFlowRelationship) {
        ServiceFlowRelationship rel = (ServiceFlowRelationship) element;

        if (rel.eIsSet(ServicesPackage.Literals.SERVICE_FLOW_RELATIONSHIP__REFERENCE_RELATIONSHIP)) {
            ReferenceRelationship referenceRelationship = rel.getReferenceRelationship();

            // Check if the interface is set.
            if (referenceRelationship
                    .eIsSet(LibraryPackage.Literals.REFERENCE_RELATIONSHIP__REF_INTERFACE2_REF)) {
                NodeType nodeTypeRef = referenceRelationship.getRefInterface2Ref();

                // Set the name of the Node Type.
                StyledString styledString = new StyledString(nodeTypeRef.getName(), null);
                cell.setText(styledString.getString());
                // Image img = ResourceManager.getPluginImage(
                // "com.netxforge.netxstudio.models.edit",
                // "icons/full/obj16/Company_H.png");
                // cell.setImage(img);
                cell.setStyleRanges(styledString.getStyleRanges());

            }/*from   w  w w  . ja  v a2 s. c o  m*/
        } else {
            cell.setText("-");
        }
    }
}

From source file:com.netxforge.netxstudio.callflow.screens.CallFlowsTreeLabelProvider.java

License:Open Source License

private void updateColumn6(ViewerCell cell, Object element) {
    if (element instanceof ServiceFlowRelationship) {
        ServiceFlowRelationship sfRel = (ServiceFlowRelationship) element;
        if (sfRel.eIsSet(ServicesPackage.Literals.SERVICE_FLOW_RELATIONSHIP__PROTOCOL)) {
            Protocol protocol = sfRel.getProtocol();

            // Set the name of the Node Type.
            StyledString styledString = new StyledString(protocol.getName(), null);
            cell.setText(styledString.getString());
            // Image img = ResourceManager.getPluginImage(
            // "com.netxforge.netxstudio.models.edit",
            // "icons/full/obj16/Company_H.png");
            // cell.setImage(img);
            cell.setStyleRanges(styledString.getStyleRanges());

        } else {//from   w  w w. ja  v a  2 s  .c om
            cell.setText("-");
        }
    }
}