List of usage examples for org.eclipse.jface.viewers ViewerCell getForeground
public Color getForeground()
From source file:ca.uvic.chisel.javasketch.ui.internal.search.TraceSearchResultLabelProvider.java
License:Open Source License
/** * @param cell//from ww w .ja va2s. c o 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:org.eclipse.ptp.internal.rm.jaxb.control.ui.providers.ViewerDataCellLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { int index = cell.getColumnIndex(); Object element = cell.getElement(); Color color = getBackground(element, index); if (color != null) { cell.setBackground(color);/*from w w w . j a v a 2 s . co m*/ } color = getForeground(element, index); if (color != null) { cell.setForeground(color); } else { /* * If foreground color is not specified, then we use the edit status of the * cell to determine the color. We save the default foreground color to use * when the cell is editable. */ if (foregroundColor == null) { foregroundColor = cell.getForeground(); } if (!canEdit(element)) { cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); } else { cell.setForeground(foregroundColor); } } Font font = getFont(element, index); if (font != null) { cell.setFont(font); } Image img = getColumnImage(element, index); if (img != null) { cell.setImage(img); } cell.setText(getColumnText(element, index)); }
From source file:rabbit.ui.internal.viewers.TreePathDurationLabelProviderTest.java
License:Apache License
@Test public void updateShouldSetTheCellColorUsingTheGivenColorProvider() throws Exception { ViewerCell cell = newCell(0, new Object()); IValueProvider valueProvider = mock(IValueProvider.class); given(valueProvider.shouldPaint(cell.getElement())).willReturn(TRUE); Display display = PlatformUI.getWorkbench().getDisplay(); Color foreground = display.getSystemColor(SWT.COLOR_CYAN); Color background = display.getSystemColor(SWT.COLOR_BLUE); IColorProvider colors = mock(IColorProvider.class); given(colors.getForeground(cell.getElement())).willReturn(foreground); given(colors.getBackground(cell.getElement())).willReturn(background); TreePathDurationLabelProvider labelProvider = new TreePathDurationLabelProvider(valueProvider, colors); labelProvider.update(cell);/*ww w . j a v a2 s.c om*/ assertThat(cell.getForeground(), is(foreground)); assertThat(cell.getBackground(), is(background)); }
From source file:rabbit.ui.internal.viewers.TreePathIntLabelProviderTest.java
License:Apache License
@Test public void updateShouldSetTheCellColorUsingTheGivenColorProvider() throws Exception { ViewerCell cell = newCell(0, new Object()); IValueProvider valueProvider = mock(IValueProvider.class); given(valueProvider.shouldPaint(cell.getElement())).willReturn(TRUE); Display display = PlatformUI.getWorkbench().getDisplay(); Color foreground = display.getSystemColor(SWT.COLOR_CYAN); Color background = display.getSystemColor(SWT.COLOR_BLUE); IColorProvider colors = mock(IColorProvider.class); given(colors.getForeground(cell.getElement())).willReturn(foreground); given(colors.getBackground(cell.getElement())).willReturn(background); TreePathIntLabelProvider labelProvider = new TreePathIntLabelProvider(valueProvider, colors); labelProvider.update(cell);/*from ww w . j a v a 2 s . c o m*/ assertThat(cell.getForeground(), is(foreground)); assertThat(cell.getBackground(), is(background)); }