Search in sources :

Example 16 with StyledString

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

the class TemplateProposal method getStyledDisplayString.

/*
	 * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension6#getStyledDisplayString()
	 * @since 3.4
	 */
public StyledString getStyledDisplayString() {
    if (fDisplayString == null) {
        String[] arguments = new String[] { fTemplate.getName(), fTemplate.getDescription() };
        String decorated = Messages.format(TemplateContentAssistMessages.TemplateProposal_displayString, arguments);
        StyledString string = new StyledString(fTemplate.getName(), StyledString.COUNTER_STYLER);
        fDisplayString = StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, string);
    }
    return fDisplayString;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 17 with StyledString

use of org.eclipse.jface.viewers.StyledString in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createRefactoringsTable.

private void createRefactoringsTable(Composite parent) {
    tableViewer = newCheckList(parent, BORDER | H_SCROLL | CHECK | NO_FOCUS | HIDE_SELECTION);
    createColumns(tableViewer);
    tableViewer.setContentProvider(new ArrayContentProvider());
    final List<RefactoringRule> refactorings = AllRefactoringRules.getAllRefactoringRules();
    tableViewer.setInput(refactorings);
    tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
        }
    });
    tableViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
            final String filter = filterText.getText().toLowerCase();
            final RefactoringRule rule = (RefactoringRule) refactoring;
            final String description = rule.getDescription().toLowerCase();
            final String name = rule.getName().toLowerCase();
            return description.contains(filter) || name.contains(filter);
        }
    });
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    tableViewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            final String filter = filterText.getText().toLowerCase();
            final String name = ((RefactoringRule) cell.getElement()).getName();
            cell.setText(name);
            cell.setStyleRanges(getStyleRanges(name, filter));
        }

        private StyleRange[] getStyleRanges(String text, String filter) {
            final int matchIndex = text.toLowerCase().indexOf(filter);
            final int matchLength = filter.length();
            if (matchIndex != -1 && matchLength != 0) {
                final StyledString styledString = new StyledString(text, defaultStyler);
                styledString.setStyle(matchIndex, matchLength, underlineStyler);
                return styledString.getStyleRanges();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object refactoring) {
            return ((RefactoringRule) refactoring).getDescription();
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(10, 20);
        }
    });
    final Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    packColumns(table);
    table.setFocus();
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) RefactoringRule(org.autorefactor.refactoring.RefactoringRule) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData)

Example 18 with StyledString

use of org.eclipse.jface.viewers.StyledString in project KaiZen-OpenAPI-Editor by RepreZen.

the class OutlineStyledLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (element instanceof AbstractNode) {
        StyledString styledString = getStyledString((AbstractNode) element);
        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());
        cell.setImage(getImage(getIcon((AbstractNode) element)));
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) StyledString(org.eclipse.jface.viewers.StyledString)

Example 19 with StyledString

use of org.eclipse.jface.viewers.StyledString in project KaiZen-OpenAPI-Editor by RepreZen.

the class Proposal method asStyledCompletionProposal.

/**
     * Returns a {@link CompletionProposal}.
     * 
     * The {@link CompletionProposal} will be returned only if the prefix is null, or if the replacement string starts
     * with or contains the prefix. Otherwise this method returns null.
     * 
     * @param prefix
     * @param offset
     * @return proposal
     */
public StyledCompletionProposal asStyledCompletionProposal(String prefix, int offset) {
    final StyledString styledString = new StyledString(displayString);
    if (type != null) {
        styledString.append(": ", typeStyler).append(type, typeStyler);
    }
    // If the replacement string has quotes
    // we should know which kind is it
    QuoteStyle quote = QuoteStyle.INVALID;
    if (StringUtils.isQuoted(replacementString)) {
        quote = StringUtils.QuoteStyle.parse(replacementString.charAt(0));
    }
    // If prefix is a quote, which kind is it
    QuoteStyle prefixQuote = QuoteStyle.INVALID;
    if (StringUtils.isQuoted(prefix)) {
        prefixQuote = StringUtils.QuoteStyle.parse(prefix.charAt(0));
    }
    // Handle quotes
    String rString = replacementString;
    if (quote != QuoteStyle.INVALID && prefixQuote != QuoteStyle.INVALID) {
        if (quote != prefixQuote) {
            // If quotes are not same, replace quotes from replacement
            // string with one from prefix
            rString = rString.substring(1);
            if (rString.endsWith(quote.getValue())) {
                rString = rString.substring(0, rString.length() - 1);
            }
            rString = prefixQuote.getValue() + rString;
        } else {
            // remove last quote to avoid duplicates
            rString = rString.substring(0, rString.length() - 1);
        }
    }
    StyledCompletionProposal proposal = null;
    if (Strings.emptyToNull(prefix) == null) {
        proposal = new StyledCompletionProposal(replacementString, styledString, null, description, offset);
    } else if (rString.toLowerCase().contains(prefix.toLowerCase())) {
        proposal = new StyledCompletionProposal(rString, styledString, prefix, description, offset);
    }
    return proposal;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) QuoteStyle(com.reprezen.swagedit.core.utils.StringUtils.QuoteStyle)

Example 20 with StyledString

use of org.eclipse.jface.viewers.StyledString in project tdi-studio-se by Talend.

the class MBeanLabelProvider method getStyledText.

/*
     * @see DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText( Object)
     */
@Override
public StyledString getStyledText(Object element) {
    StyledString text = new StyledString();
    boolean appendSuffix = false;
    ObjectName objectName = null;
    IActiveJvm jvm = null;
    if (element instanceof IMBeanNode) {
        text.append(((IMBeanNode) element).getName());
        if (element instanceof MBean && ((MBean) element).isNotificationSubsctibed()) {
            appendSuffix = true;
            jvm = ((MBean) element).getJvm();
        }
    }
    if (appendSuffix && jvm != null) {
        int notificationCount = jvm.getMBeanServer().getMBeanNotification().getNotifications(objectName).length;
        //$NON-NLS-1$ //$NON-NLS-2$
        String suffix = " [notifications: " + notificationCount + "]";
        int offset = text.length();
        text.append(suffix);
        text.setStyle(offset, suffix.length(), StyledString.DECORATIONS_STYLER);
    }
    return text;
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ObjectName(javax.management.ObjectName)

Aggregations

StyledString (org.eclipse.jface.viewers.StyledString)69 Image (org.eclipse.swt.graphics.Image)14 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 Capability (org.osgi.resource.Capability)4 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Styler (org.eclipse.jface.viewers.StyledString.Styler)3 TableViewer (org.eclipse.jface.viewers.TableViewer)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