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;
}
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();
}
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)));
}
}
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;
}
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;
}
Aggregations