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

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

Introduction

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

Prototype

public Control getControl() 

Source Link

Document

Get the control for this cell.

Usage

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  .j a  va2 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:org.jboss.tools.openshift.express.internal.ui.propertytable.PropertyValueCellLabelProvider.java

License:Open Source License

private void createStyledText(IProperty property, final ViewerCell cell) {
    StyledString.Styler style = new StyledString.Styler() {
        @Override/*  w  ww.j a v  a2 s.  c  o m*/
        public void applyStyles(TextStyle textStyle) {
            textStyle.foreground = cell.getControl().getDisplay().getSystemColor(SWT.COLOR_BLUE);
            textStyle.underline = true;
        }
    };
    StyledString styledString = new StyledString(StringUtils.null2emptyString(property.getValue()), style);
    cell.setStyleRanges(styledString.getStyleRanges());
    cell.setText(styledString.getString());
}

From source file:org.jboss.tools.openshift.express.internal.ui.utils.TreeUtils.java

License:Open Source License

/**
 * Creates a tree editor for the given cell with the given control.
 * <p>/*from   w  w w.jav a 2s. co m*/
 * A tree editor puts a control over a given cell in a tree. Furthermore it puts text into the cell so that the
 * column's large enough so that the control has enough room to overlay itself over it
 * 
 * @param cell the cell to put the control to
 * @param control the control to put to the given cell
 * @param cellText the text that's put into the table cell (overlayed by the editor), that only enlarges the
 *            column to have enough room for the editor
 * 
 * @return the tree editor
 * 
 * @see ViewerCell
 * @see TreeEditor
 */
public static TreeEditor createTreeEditor(Control control, String cellText, ViewerCell cell) {
    Assert.isTrue(cell.getControl() instanceof Tree);

    Tree tree = (Tree) cell.getControl();
    final TreeEditor treeEditor = new TreeEditor(tree);
    initializeTreeEditor(treeEditor, control, cellText, cell);
    tree.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            treeEditor.dispose();
        }
    });
    return treeEditor;
}

From source file:org.kalypso.contribs.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.FocusCellHighlighter#focusCellChanged(org.eclipse.jface.viewers.ViewerCell,
 *      org.eclipse.jface.viewers.ViewerCell)
 *///from w  ww  .ja  va 2s  .co  m
@Override
protected void focusCellChanged(final ViewerCell cell, final ViewerCell oldCell2) {
    super.focusCellChanged(cell, m_oldCell);

    // Redraw new area
    if (cell != null) {
        final Rectangle rect = cell.getBounds();
        final int x = cell.getColumnIndex() == 0 ? 0 : rect.x;
        final int width = cell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        // 1 is a fix for Linux-GTK
        cell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true);
    }

    if (m_oldCell != null) {
        final Rectangle rect = m_oldCell.getBounds();
        final int x = m_oldCell.getColumnIndex() == 0 ? 0 : rect.x;
        final int width = m_oldCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width;
        // 1 is a fix for Linux-GTK
        m_oldCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true);
    }

    m_oldCell = cell;
}

From source file:org.polymap.p4.imports.labels.MessageCellLabelProvider.java

License:Open Source License

/**
 * @param cell//from w  ww.  j  a  v  a 2s.co  m
 * @param string
 */
private void setCellText(ViewerCell cell, String text) {
    Rectangle cellBounds = cell.getControl().getBounds();
    Point point = getTextExtent(getTextMetricHelper(), cell, text);
    if (point.x > cellBounds.width - 10) {
        text = insertLineBreaksToFitCellWidth(cell, text, cellBounds);
    }
    cell.setText(text);
}

From source file:org.polymap.p4.imports.labels.MessageCellLabelProviderTest.java

License:Open Source License

private void executeSecondLineTextTest(FileDescription elementAssociatedWithCell, String expectedLabel) {
    ViewerCell viewerCell = mock(ViewerCell.class);
    ViewerRow viewerRow = mock(ViewerRow.class);
    TreeItem treeItem = mock(TreeItem.class);
    ShapeFileValidator shapeFileValidator = mock(ShapeFileValidator.class);
    Control control = mock(Control.class);
    int cellWidth = 100;
    Rectangle bounds = new Rectangle(0, 0, cellWidth, 0);
    TextMetricHelper textMetricHelper = mock(TextMetricHelper.class);
    int textWidth = 80;
    Point textExtent = new Point(textWidth, 0);
    FontMetrics fontMetrics = PowerMockito.mock(FontMetrics.class);

    ValidationEvent validationEvent = new ValidationEvent(elementAssociatedWithCell, IStatus.OK, "");

    when(shapeFileValidator.validate(elementAssociatedWithCell)).then(new Answer<Boolean>() {

        @Override/*from  www  . j  a va2 s .c o  m*/
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            labelProvider.handleStatus(viewerCell, validationEvent);
            return Boolean.TRUE;
        }
    });

    when(viewerCell.getElement()).thenReturn(elementAssociatedWithCell);
    when(viewerCell.getViewerRow()).thenReturn(viewerRow);
    when(viewerRow.getItem()).thenReturn(treeItem);
    when(treeItem.getExpanded()).thenReturn(true);
    when(viewerCell.getControl()).thenReturn(control);
    when(control.getBounds()).thenReturn(bounds);
    // for error case
    when(textMetricHelper.getTextExtent(viewerCell, "")).thenReturn(new Point(0, 0));
    when(textMetricHelper.getTextExtent(viewerCell, expectedLabel)).thenReturn(textExtent);
    when(textMetricHelper.getFontMetrics(viewerCell)).thenReturn(fontMetrics);

    labelProvider.setShapeFileValidator(shapeFileValidator);
    labelProvider.setTextMetricHelper(textMetricHelper);
    labelProvider.update(viewerCell);

    verify(treeItem).setData(RWT.CUSTOM_VARIANT, "firstRow");
    verify(viewerCell).setText(expectedLabel);
}

From source file:org.polymap.p4.imports.utils.TextMetricHelper.java

License:Open Source License

public Point getTextExtent(ViewerCell cell, String text) {
    GC gc = new GC(cell.getControl());
    Point point = gc.textExtent(text);
    gc.dispose();//  www .  j a v  a 2s.co  m
    return point;
}

From source file:org.polymap.p4.imports.utils.TextMetricHelper.java

License:Open Source License

public FontMetrics getFontMetrics(ViewerCell cell) {
    GC gc = new GC(cell.getControl());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();/*w w  w  . j  av a 2 s .c om*/
    return fontMetrics;
}

From source file:org.springframework.ide.eclipse.boot.dash.views.sections.CursorProviders.java

License:Open Source License

/**
 * Create a cursor provider for given//from w w  w .j a  v a  2 s  . c o  m
 */
public static CursorProvider forStyle(final int cursorStyle) {
    return new CursorProvider() {

        private Cursor cursor;

        @Override
        public Cursor getCursor(ViewerCell cell) {
            if (cursor == null) {
                cursor = new Cursor(cell.getControl().getDisplay(), cursorStyle);
            }
            return cursor;
        }
    };
}

From source file:org.springsource.ide.eclipse.commons.livexp.ui.util.SwtConnect.java

License:Open Source License

/**
 * Decorate a basic LabelProvider so that it bolds matched elements based on a text-based filter applied to its labels.
 *///from ww  w .  j a  v  a2 s.co  m
public static StyledCellLabelProvider boldMatchedElements(Stylers stylers, ILabelProvider baseLabels,
        Filter<String> filter) {
    return new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();

            //image
            cell.setImage(baseLabels.getImage(element));

            //styled label
            String label = baseLabels.getText(element);
            StyledString styledLabel = new StyledString(label);
            if (filter.accept(label)) {
                Styler bold = stylers.bold();
                for (IRegion r : filter.getHighlights(label)) {
                    styledLabel.setStyle(r.getOffset(), r.getLength(), bold);
                }
            }
            cell.setStyleRanges(styledLabel.getStyleRanges());
            cell.setText(styledLabel.getString());
            cell.getControl().redraw();
            //^^^ Sigh... Yes, this is needed. It seems SWT/Jface isn't smart enough to itself figure out that if 
            //the styleranges change a redraw is needed to make the change visible.
        }

    };
}