Example usage for org.eclipse.jface.viewers ViewerCell getFont

List of usage examples for org.eclipse.jface.viewers ViewerCell getFont

Introduction

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

Prototype

public Font getFont() 

Source Link

Document

Gets the font of the cell.

Usage

From source file:ca.uvic.chisel.javasketch.ui.internal.search.TraceSearchResultLabelProvider.java

License:Open Source License

/**
 * @param cell//from  w w  w .  j a  v a 2  s.  com
 */
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: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 });
}

From source file:com.microsoft.tfs.client.eclipse.ui.egit.importwizard.GitImportWizardSelectProjectsPage.java

License:Open Source License

private void setCellFontStyle(final ViewerCell cell, final int style) {
    if (style == SWT.ITALIC) {
        if (italicFont == null) {
            italicFont = createFont(cell.getFont(), SWT.ITALIC);
        }/* w  ww .j a  v  a2  s  . com*/
        cell.setFont(italicFont);
    } else if (style == SWT.BOLD) {
        if (boldFont == null) {
            boldFont = createFont(cell.getFont(), SWT.BOLD);
        }
        cell.setFont(boldFont);
    }
}

From source file:org.eclipse.wazaabi.engine.swt.commons.views.collections.ColumnManager.java

License:Open Source License

protected void createViewerColumn(final org.eclipse.swt.widgets.Widget w,
        final AbstractColumnDescriptor columnDescriptor, final int columnIndex) {

    ViewerColumn viewerColumn = null;//from  w ww  .  ja va  2 s. c  om
    if (w instanceof org.eclipse.swt.widgets.Tree) {
        viewerColumn = new TreeViewerColumn((TreeViewer) collectionView.getViewer(),
                getSWTColumnHeaderStyle(columnDescriptor));

        // TODO : not supported yet
        // viewerColumn.getColumn().setMoveable(true);

        final TreeColumn column = ((TreeViewerColumn) viewerColumn).getColumn();

        column.setText(columnDescriptor.getLabel() != null ? columnDescriptor.getLabel() : "");//$NON-NLS-1$

        if (getSWTWidget() instanceof org.eclipse.swt.widgets.Composite
                && ((org.eclipse.swt.widgets.Composite) getSWTWidget())
                        .getLayout() instanceof AbstractColumnLayout) {
            ColumnLayoutData columnLayoutData = null;
            if (columnDescriptor.eClass() == CoreCollectionsStylesPackage.Literals.COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnPixelData(((ColumnDescriptor) columnDescriptor).getWidth(),
                        columnDescriptor.isResizable());
            else if (columnDescriptor
                    .eClass() == CoreCollectionsStylesPackage.Literals.WEIGHTED_COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnWeightData(
                        ((WeightedColumnDescriptor) columnDescriptor).getWeight(),
                        ((WeightedColumnDescriptor) columnDescriptor).getMinimumWidth(),
                        columnDescriptor.isResizable());
            ((AbstractColumnLayout) ((org.eclipse.swt.widgets.Composite) getSWTWidget()).getLayout())
                    .setColumnData(column, columnLayoutData);
        }

    } else if (w instanceof org.eclipse.swt.widgets.Table) {
        viewerColumn = new TableViewerColumn((TableViewer) collectionView.getViewer(),
                getSWTColumnHeaderStyle(columnDescriptor));

        // TODO : not supported yet
        // viewerColumn.getColumn().setMoveable(true);

        ((TableViewerColumn) viewerColumn).getColumn()
                .setText(columnDescriptor.getLabel() != null ? columnDescriptor.getLabel() : "");//$NON-NLS-1$

        final TableColumn column = ((TableViewerColumn) viewerColumn).getColumn();

        column.setText(columnDescriptor.getLabel() != null ? columnDescriptor.getLabel() : "");//$NON-NLS-1$

        if (getSWTWidget() instanceof org.eclipse.swt.widgets.Composite
                && ((org.eclipse.swt.widgets.Composite) getSWTWidget())
                        .getLayout() instanceof AbstractColumnLayout) {
            ColumnLayoutData columnLayoutData = null;
            if (columnDescriptor.eClass() == CoreCollectionsStylesPackage.Literals.COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnPixelData(((ColumnDescriptor) columnDescriptor).getWidth(),
                        columnDescriptor.isResizable());
            else if (columnDescriptor
                    .eClass() == CoreCollectionsStylesPackage.Literals.WEIGHTED_COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnWeightData(
                        ((WeightedColumnDescriptor) columnDescriptor).getWeight(),
                        ((WeightedColumnDescriptor) columnDescriptor).getMinimumWidth(),
                        columnDescriptor.isResizable());
            ((AbstractColumnLayout) ((org.eclipse.swt.widgets.Composite) getSWTWidget()).getLayout())
                    .setColumnData(column, columnLayoutData);
        }

    }
    if (viewerColumn != null) {
        if (collectionView.getLabelProvider() instanceof PathSelectorLabelProvider) {
            final PathSelectorLabelProvider labelProvider = (PathSelectorLabelProvider) collectionView
                    .getLabelProvider();
            viewerColumn.setLabelProvider(new ColumnLabelProvider() {

                public String getText(Object element) {
                    return labelProvider.getColumnText(element, columnIndex);
                }

                public Image getImage(Object element) {
                    return labelProvider.getColumnImage(element, columnIndex);
                }

            });
        } else if (collectionView.getLabelProvider() instanceof DynamicLabelProvider) {
            final DynamicLabelProvider labelProvider = (DynamicLabelProvider) collectionView.getLabelProvider();
            viewerColumn.setLabelProvider(new StyledCellLabelProvider() {

                @Override
                public void update(ViewerCell cell) {
                    final Object element = cell.getElement();
                    final int columnIndex = cell.getColumnIndex();
                    final Display display = cell.getControl().getDisplay();
                    cell.setText(labelProvider.getColumnText(element, columnIndex));
                    cell.setImage(labelProvider.getColumnImage(element, columnIndex));
                    final Color foreground = labelProvider.getForegroundColor(element, columnIndex, display);
                    if (foreground != null)
                        cell.setForeground(foreground);
                    final Color background = labelProvider.getBackgroundColor(element, columnIndex, display);
                    if (background != null)
                        cell.setBackground(background);
                    final Font font = labelProvider.getFont(element, columnIndex, display, cell.getFont());
                    if (font != null)
                        cell.setFont(font);
                    super.update(cell);
                }
            });
        } else
            viewerColumn.setLabelProvider(new ColumnLabelProvider() {

                public String getText(Object element) {
                    return element != null ? element.toString() : ""; //$NON-NLS-1$
                }

            });
        if (columnDescriptor.getEditingSupport() != null) {
            DynamicEditingSupport dynamicEditingSupport = new DynamicEditingSupport(this, columnDescriptor);
            dynamicEditingSupports.put(columnDescriptor, dynamicEditingSupport);
            viewerColumn.setEditingSupport(dynamicEditingSupport);
        }
    }

}

From source file:org.jboss.tools.openshift.express.internal.ui.propertytable.PropertyValueCellLabelProvider.java

License:Open Source License

protected void createLink(IProperty property, final ViewerCell cell) {
    if (StringUtils.isEmpty(property.getValue())) {
        return;//from  w w  w.ja va 2 s  .c  o m
    }
    final Hyperlink link = new Hyperlink((Tree) cell.getControl(), SWT.NONE); // SWT.NO_BACKGROUND
    link.setBackground(cell.getBackground());
    link.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ACTIVE_HYPERLINK_COLOR));
    link.setFont(cell.getFont());
    link.setUnderlined(true);
    link.setText(property.getValue());
    link.setBackground(cell.getBackground());
    link.addMouseListener(onLinkClicked(property.getValue()));

    TreeUtils.createTreeEditor(link, property.getValue(), cell);
}

From source file:phasereditor.ui.PhaserEditorUI.java

License:Open Source License

public static StyledCellLabelProvider createSearchLabelProvider(Supplier<String> getStr,
        Function<Object, String> toStr) {
    return new StyledCellLabelProvider() {
        @Override/*from  ww w  .  ja va 2s  .  co m*/
        public void update(ViewerCell cell) {
            String search = getStr.get();
            String cellText = toStr.apply(cell.getElement());
            cell.setText(cellText);
            if (search != null && search.length() > 0) {
                int intRangesCorrectSize[] = getSearchTermOccurrences(search, cellText);
                List<StyleRange> styleRange = new ArrayList<>();
                for (int i = 0; i < intRangesCorrectSize.length / 2; i++) {
                    int start = intRangesCorrectSize[i];
                    int length = intRangesCorrectSize[++i];
                    StyleRange myStyledRange = new StyleRange(start, length, null, null);
                    myStyledRange.font = SWTResourceManager.getBoldFont(cell.getFont());
                    styleRange.add(myStyledRange);
                }
                cell.setStyleRanges(styleRange.toArray(new StyleRange[styleRange.size()]));
            } else {
                cell.setStyleRanges(null);
            }

            super.update(cell);

        }
    };
}

From source file:uk.ac.stfc.isis.ibex.ui.configserver.editing.blocks.BlockRowCellDecorator.java

License:Open Source License

private static void modifyFont(ViewerCell cell, int modifier) {
    FontData fontData = cell.getFont().getFontData()[0];
    Font font = SWTResourceManager.getFont(fontData.getName(), fontData.getHeight(),
            fontData.getStyle() | modifier);
    cell.setFont(font);/*from  w w w .j  ava 2 s. c o  m*/
}