List of usage examples for org.eclipse.jface.viewers ViewerCell setStyleRanges
public void setStyleRanges(StyleRange[] styleRanges)
From source file:at.bestsolution.eclipse.properties.PropertyContentOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override//from w w w. ja v a2 s . c om public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof PropertyGroup) { cell.setText(((PropertyGroup) element).name); cell.setImage(Activator.getDefault().getImageRegistry().get(Activator.GROUP_ICON)); cell.setStyleRanges(null); } else if (element instanceof Property) { cell.setImage(Activator.getDefault().getImageRegistry().get(Activator.KEY_ICON)); StyledString s = new StyledString(((Property) element).pair.key); String text = ((Property) element).pair.value; if (text.length() > 20) { text = text.substring(0, 20) + "..."; } s.append(" : " + text, StyledString.DECORATIONS_STYLER); cell.setStyleRanges(s.getStyleRanges()); cell.setText(s.getString()); } super.update(cell); } }); viewer.setContentProvider(new HierarchicalContentProvider()); if (isSorted()) { setSorted(true); } createHierarchicalStructure(); if (isHierarchical()) { viewer.setInput(hierarchicalStructure); } else { viewer.setInput(flatStructure); } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.outline.PropertyContentOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override// ww w .j av a2 s . c o m public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof PropertyGroup) { cell.setText(((PropertyGroup) element).name); cell.setImage(JavaFXUIPlugin.getDefault().getImageRegistry().get(JavaFXUIPlugin.GROUP_ICON)); cell.setStyleRanges(null); } else if (element instanceof Property) { cell.setImage(JavaFXUIPlugin.getDefault().getImageRegistry().get(JavaFXUIPlugin.KEY_ICON)); StyledString s = new StyledString(((Property) element).pair.key); String text = ((Property) element).pair.value; if (text.length() > 20) { text = text.substring(0, 20) + "..."; } s.append(" : " + text, StyledString.DECORATIONS_STYLER); cell.setStyleRanges(s.getStyleRanges()); cell.setText(s.getString()); } super.update(cell); } }); viewer.setContentProvider(new HierarchicalContentProvider()); if (isSorted()) { setSorted(true); } createHierarchicalStructure(); if (isHierarchical()) { viewer.setInput(hierarchicalStructure); } else { viewer.setInput(flatStructure); } }
From source file:bndtools.editor.components.ComponentSvcRefTableLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { ComponentSvcReference svcRef = (ComponentSvcReference) cell.getElement(); int columnIndex = cell.getColumnIndex(); StyledString styledString;//ww w .j a v a 2 s. c om switch (columnIndex) { case 0: styledString = new StyledString(svcRef.getName()); String bind = svcRef.getBind(); String unbind = svcRef.getUnbind(); if (bind != null) { StringBuilder buffer = new StringBuilder(); buffer.append(" {").append(bind).append('/'); if (unbind != null) { buffer.append(unbind); } buffer.append('}'); styledString.append(buffer.toString(), StyledString.DECORATIONS_STYLER); } cell.setImage(svcRef.isDynamic() ? dynamicImg : staticImg); cell.setText(styledString.toString()); cell.setStyleRanges(styledString.getStyleRanges()); break; case 1: styledString = new StyledString(svcRef.getServiceClass(), StyledString.QUALIFIER_STYLER); cell.setText(styledString.toString()); cell.setStyleRanges(styledString.getStyleRanges()); break; case 2: char[] cardinality = new char[] { svcRef.isOptional() ? '0' : '1', '.', '.', svcRef.isMultiple() ? 'n' : '1' }; styledString = new StyledString(new String(cardinality), StyledString.COUNTER_STYLER); cell.setText(styledString.toString()); cell.setStyleRanges(styledString.getStyleRanges()); break; case 3: String target = svcRef.getTargetFilter(); cell.setText(target != null ? target : ""); break; } }
From source file:bndtools.editor.components.MethodProposalLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { StyledString styledString = getStyledString(cell.getElement()); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); }
From source file:bndtools.editor.pkgpatterns.HeaderClauseLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { @SuppressWarnings("unchecked") C clause = (C) cell.getElement();//from w w w . j av a 2 s. co m cell.setImage(packageImg); StyledString styledString = new StyledString(clause.getName()); String version = clause.getAttribs().get(org.osgi.framework.Constants.VERSION_ATTRIBUTE); if (version != null) { styledString.append(": " + version, StyledString.COUNTER_STYLER); } decorate(styledString, clause); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); }
From source file:bndtools.editor.pkgpatterns.PkgPatternsLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { HeaderClause clause = (HeaderClause) cell.getElement(); cell.setImage(packageImg);/*ww w. j a v a 2 s .co m*/ StyledString styledString = new StyledString(clause.getName()); String resolution = clause.getAttribs().get(Constants.RESOLUTION_DIRECTIVE); if (org.osgi.framework.Constants.RESOLUTION_OPTIONAL.equals(resolution)) { styledString.append(" <optional>", UIConstants.ITALIC_QUALIFIER_STYLER); } String version = clause.getAttribs().get(org.osgi.framework.Constants.VERSION_ATTRIBUTE); if (version != null) { styledString.append(": " + version, StyledString.COUNTER_STYLER); } cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); }
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"); }//ww w . j av a 2 s . co m } 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:ca.uvic.chisel.javasketch.ui.internal.search.TraceSearchResultLabelProvider.java
License:Open Source License
/** * @param cell// www .j ava 2s . co m */ private void setMatchText(ViewerCell cell) { Match match = (Match) cell.getElement(); ITraceModelProxy proxy = (ITraceModelProxy) match.getElement(); IProgramSketch sketch = SketchPlugin.getDefault().getSketch(proxy.getTrace()); PresentationData pd = PresentationData.connect(sketch); try { String annotation = pd.getAnnotation(proxy.getElementId()); if (annotation != null) { annotation = annotation.replaceAll("\\s+", " "); if (annotation.length() >= match.getOffset() + match.getLength()) { int summaryOffset = 0; String summary = annotation.substring(match.getOffset(), match.getOffset() + match.getLength()); StringBuilder builder = new StringBuilder(summary); int wordCount = 0; int index = match.getOffset() - 1; while (wordCount < 3 && index >= 0) { char c = annotation.charAt(index); if (Character.isWhitespace(c)) { wordCount++; if (wordCount > 3) { break; } } builder.insert(0, c); summaryOffset++; index--; } if (index >= 0) { builder.insert(0, "..."); summaryOffset += 3; } index = match.getOffset() + match.getLength(); wordCount = 0; while (wordCount < 3 && index < annotation.length()) { char c = annotation.charAt(index); if (Character.isWhitespace(c)) { wordCount++; if (wordCount > 3) { break; } } builder.append(c); index++; } if (index < annotation.length()) { builder.append("..."); } cell.setText(builder.toString()); Color fg = cell.getForeground(); Color bg = cell.getFont().getDevice().getSystemColor(SWT.COLOR_YELLOW); StyleRange range = new StyleRange(summaryOffset, match.getLength(), fg, bg); cell.setStyleRanges(new StyleRange[] { range }); } } } finally { pd.disconnect(); } }
From source file:cideplus.ui.astview.ASTViewLabelProvider.java
License:Open Source License
@Override public void update(final ViewerCell cell) { Object element = cell.getElement(); //cell.setStyleRanges(new StyleRange[]{new stylera}); String text = getText(element); cell.setText(text);/* w w w . jav a 2 s . c om*/ Image image = getImage(element); cell.setImage(image); if (fullBackgroundColor) { cell.setBackground(getBackground(element)); } cell.setForeground(getForeground(element)); cell.setFont(getFont(element)); cell.setStyleRanges(new StyleRange[] { new StyleRange(0, text.length(), getForeground(element), getBackground(element)) }); }
From source file:com.blackducksoftware.integration.eclipseplugin.views.providers.DependencyComponentColumnLabelProvider.java
License:Apache License
@Override public void styleCell(ViewerCell cell) { String[] compChunks = cell.getText().split(":"); cell.setText(String.format("%1$s %2$s ", compChunks[0], compChunks[1])); Display display = Display.getCurrent(); final Color versionColor = decodeHex(display, "#285F8F"); final Color backgroundColor = decodeHex(display, "#fafafa"); final Color borderColor = decodeHex(display, "#dddddd"); final StyleRange versionStyle = new StyleRange(compChunks[0].length() + 1, compChunks[1].length() + 2, versionColor, backgroundColor); versionStyle.borderStyle = SWT.BORDER_SOLID; versionStyle.borderColor = borderColor; int versionHeight = (int) (cell.getFont().getFontData()[0].getHeight() * 0.85); versionStyle.font = FontDescriptor.createFrom(cell.getFont()).setHeight(versionHeight).createFont(display); cell.setStyleRanges(new StyleRange[] { versionStyle }); }