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

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

Introduction

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

Prototype

public ViewerRow getViewerRow() 

Source Link

Usage

From source file:net.certiv.fluentmark.tables.FocusBorderCellHighlighter.java

License:Open Source License

private void hookListener(final ColumnViewer viewer) {

    Listener listener = new Listener() {

        @Override/* w ww .  j a v a  2s .  co  m*/
        public void handleEvent(Event event) {
            if ((event.detail & SWT.SELECTED) > 0) {
                ViewerCell focusCell = getFocusCell();
                ViewerRow row = focusCell.getViewerRow();

                Assert.isNotNull(row,
                        "Internal structure invalid. Item without associated row is not possible."); //$NON-NLS-1$

                ViewerCell cell = row.getCell(event.index);

                if (focusCell == null || !cell.equals(focusCell)) {
                    removeSelectionInformation(event, cell);
                } else {
                    markFocusedCell(event, cell);
                }
            }
        }
    };
    viewer.getControl().addListener(SWT.EraseItem, listener);
}

From source file:net.tourbook.map3.ui.DialogLayerViewerToolTip.java

License:Open Source License

@Override
protected Object getToolTipArea(final Point ownerHoverPosition) {

    // set default values
    _mapLayer = null;/*from  w  w w.j ava  2s  .  co m*/
    _viewerRow = null;
    _sensitiveRowArea = null;

    Object ttArea = null;

    final ViewerCell viewerCell = _propViewer.getCell(ownerHoverPosition);

    if (viewerCell != null) {

        /*
         * Use the first column as content area, when mouse is hovering other cells in the same
         * row, the tooltip keeps open
         */
        _viewerRow = viewerCell.getViewerRow();

        _column0_Width = _tree.getColumn(0).getWidth();
        _hoverLeftBorder = (int) (_column0_Width * HOVERED_SENSITIVE_AREA);
        final int ownerHoveredPositionX = ownerHoverPosition.x;

        if (ownerHoveredPositionX > _hoverLeftBorder && ownerHoveredPositionX < _column0_Width) {

            /*
             * the info tooltip is opened when the mouse is in the last 1/3 part of the column 0
             */

            _sensitiveRowArea = _viewerRow;

            final Object element = _viewerRow.getElement();

            if (element instanceof TVIMap3Layer) {

                ttArea = _viewerRow;

                final TVIMap3Layer mapLayer = (TVIMap3Layer) element;
                _mapLayer = mapLayer;
            }
        }
    }

    /*
     * show user that sensitive row area is hovered and actions can be done
     */
    _propViewer.getTree().setCursor(_sensitiveRowArea == null ? null : getCursorHand());

    return ttArea;
}

From source file:net.tourbook.map3.ui.SlideoutMap3LayerTooltip.java

License:Open Source License

@Override
protected boolean isInNoHideArea(final Point ownerHoverPosition) {

    // set default values
    _mapLayer = null;//from   ww w. j  av a  2 s .co m
    _viewerRow = null;
    _sensitiveRowArea = null;

    Object ttArea = null;

    final ViewerCell viewerCell = _layerViewer.getCell(ownerHoverPosition);

    if (viewerCell != null) {

        /*
         * Use the first column as content area, when mouse is hovering other cells in the same
         * row, the tooltip keeps open
         */
        _viewerRow = viewerCell.getViewerRow();

        _column0_Width = _tree.getColumn(0).getWidth();
        _hoverLeftBorder = (int) (_column0_Width * HOVERED_SENSITIVE_AREA);
        final int ownerHoveredPositionX = ownerHoverPosition.x;

        if (ownerHoveredPositionX > _hoverLeftBorder && ownerHoveredPositionX < _column0_Width) {

            /*
             * the info tooltip is opened when the mouse is in the last 1/3 part of the column 0
             */

            _sensitiveRowArea = _viewerRow;

            final Object element = _viewerRow.getElement();

            if (element instanceof TVIMap3Layer) {

                ttArea = _viewerRow;

                final TVIMap3Layer mapLayer = (TVIMap3Layer) element;
                _mapLayer = mapLayer;
            }
        }
    }

    /*
     * show user that sensitive row area is hovered and actions can be done
     */
    _layerViewer.getTree().setCursor(_sensitiveRowArea == null ? null : _cursorHand);

    return ttArea != null;
}

From source file:net.tourbook.ui.views.tourMarker.TourMarkerView.java

License:Open Source License

/**
 * Column: Distance delta km/mi//w  w w  . j  a v  a2 s  .  co m
 */
private void defineColumn_Motion_DistanceDelta() {

    final ColumnDefinition colDef = TableColumnFactory.MOTION_DISTANCE_DELTA.createColumn(_columnManager, _pc);

    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final TourMarker tourMarker = (TourMarker) cell.getElement();

            final float markerDistance = tourMarker.getDistance();

            if (markerDistance == -1) {

                cell.setText(UI.EMPTY_STRING);

            } else {

                float prevDistance = 0;
                final ViewerRow lastRow = cell.getViewerRow().getNeighbor(ViewerRow.ABOVE, false);

                if (null != lastRow) {
                    final TourMarker element = (TourMarker) lastRow.getElement();
                    if (element instanceof TourMarker) {
                        prevDistance = element.getDistance();
                    }
                    prevDistance = prevDistance < 0 ? 0 : prevDistance;
                }

                cell.setText(_nf3.format(
                        (markerDistance - prevDistance) / 1000 / net.tourbook.ui.UI.UNIT_VALUE_DISTANCE));
            }
        }
    });
}

From source file:net.tourbook.ui.views.tourMarker.TourMarkerView.java

License:Open Source License

/**
 * Column: Time//from w w w  .  ja  va2  s  . co  m
 */
private void defineColumn_Time_TimeDelta() {

    final ColumnDefinition colDef = TableColumnFactory.MARKER_TIME_DELTA.createColumn(_columnManager, _pc);

    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final ViewerRow lastRow = cell.getViewerRow().getNeighbor(ViewerRow.ABOVE, false);
            int lastTime = 0;
            if (null != lastRow) {
                final Object element = lastRow.getElement();
                if (element instanceof TourMarker) {
                    lastTime = ((TourMarker) element).getTime();
                }
            }

            cell.setText(net.tourbook.common.UI
                    .format_hh_mm_ss(((TourMarker) cell.getElement()).getTime() - lastTime));

            final String text = ((TourMarker) cell.getElement()).getLabel();

            /*
             * Show text in red/bold when the text ends with a !, this hidden feature was
             * introduced by helmling
             */
            if (text.endsWith(UI.SYMBOL_EXCLAMATION_POINT)) {

                final Display display = Display.getCurrent();

                if (null != display) {
                    cell.setForeground(display.getSystemColor(SWT.COLOR_RED));
                }

                cell.setFont(_boldFont);
            }
        }
    });
}

From source file:org.eclipse.andmore.android.emulator.core.emulationui.AbstractEmuLabelProvider.java

License:Apache License

/**
 * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
 *//*from  ww  w .j  ava  2  s .  c  o  m*/
@Override
public void update(ViewerCell cell) {
    // The instance column index is set with the current cell column index,
    // as the logic
    // contained in this class depends on this information. Then after the
    // cell is
    // updated according to the standard procedure, the column index field
    // is reset so that
    // it does not interfere with subsequent updates.
    columnIndex = cell.getColumnIndex();
    super.update(cell);
    columnIndex = firstColumnIndex;

    // Checks if the cell needs to be highlighted. This will be true if the
    // values of
    // alternativeColorHost and alternativeColorBeanId are different from
    // null and -1
    if ((alternativeColorHost != null) && (alternativeColorBeanId != -1)) {

        Object element = cell.getElement();
        // Only leaf nodes can be highlighted
        if (element instanceof EmuViewerLeafNode) {
            // The next lines are used to check if the current element is
            // the one to be
            // highlighted. For that, the host and bean id needs to be
            // compared to the
            // alternativeColorHost and alternativeColorBeanId instance
            // field values
            EmuViewerLeafNode node = (EmuViewerLeafNode) element;
            long beanId = node.getBeanId();
            EmuViewerRootNode root = (EmuViewerRootNode) node.getParent().getParent();
            String host = root.getEmulatorIdentifier();

            if ((beanId == alternativeColorBeanId) && (host.equals(alternativeColorHost))) {
                // Highlighting the node

                cell.setBackground(alternativeColor);

                // Putting the node at the visible part of the tree

                ViewerRow highlightedRow = cell.getViewerRow();
                TreeItem highlightedItem = (TreeItem) highlightedRow.getItem();
                Tree tree = (Tree) cell.getControl();
                tree.showItem(highlightedItem);
            }
        }

    }
}

From source file:org.eclipse.babel.tapiji.tools.core.ui.widgets.provider.ResKeyTreeLabelProvider.java

License:Open Source License

public void updateTreeViewer(TreeViewer treeViewer) {

    for (TreeItem item : treeViewer.getTree().getItems()) {
        Rectangle bounds = item.getBounds();
        ViewerCell cell = treeViewer.getCell(new Point(bounds.x, bounds.y));
        ViewerRow viewerRow = cell.getViewerRow();

        for (int i = 0; i < viewerRow.getColumnCount(); i++) {
            updateCell(viewerRow.getCell(i));
        }/*  w ww  . ja v a2 s.  c  o m*/
    }
}

From source file:org.eclipse.e4mf.common.ui.viewer.ColumnViewerInformationControlToolTipSupport.java

License:Open Source License

protected boolean shouldCreateToolTip(Event event) {
    ViewerCell cell = getToolTipArea(event);
    if (cell != null && !cell.equals(currentCell)) {
        control.setToolTipText("");
        currentCell = cell;/*from   w ww. j  a va 2 s  .c  o  m*/
        ViewerRow row = cell.getViewerRow();
        if (row != null) {
            Object element = row.getItem().getData();
            CellLabelProvider labelProvider = viewer.getLabelProvider(cell.getColumnIndex());
            text = labelProvider.getToolTipText(element);
            boolean useNative = labelProvider.useNativeToolTip(element);
            if (useNative || text == null) {
                control.setToolTipText(text);
            } else {
                foregroundColor = labelProvider.getToolTipForegroundColor(element);
                backgroundColor = labelProvider.getToolTipBackgroundColor(element);
                font = labelProvider.getToolTipFont(element);
                return text != null;
            }
        }
    } else {
        currentCell = cell;
    }

    return false;
}

From source file:org.eclipse.jface.snippets.viewers.BooleanCellEditor.java

License:Open Source License

@Override
public void activate(ColumnViewerEditorActivationEvent activationEvent) {
    ViewerCell cell = (ViewerCell) activationEvent.getSource();
    index = cell.getColumnIndex();/*from   w w  w.  j ava  2  s .  c  om*/
    row = (ViewerRow) cell.getViewerRow().clone();
    restoredImage = row.getImage(index);
    restoredText = row.getText(index);
    row.setImage(index, null);
    row.setText(index, ""); //$NON-NLS-1$

    if (activationEvent.eventType != ColumnViewerEditorActivationEvent.TRAVERSAL && changeOnActivation) {
        button.setSelection(!button.getSelection());
    }

    //TODO Add a way to enable key traversal when CheckBoxes don't get focus
    //      if( Util.isMac() ) {
    //         button.getParent().addKeyListener(macSelectionListener);
    //      }

    super.activate(activationEvent);
}

From source file:org.eclipse.jface.snippets.viewers.FocusBorderCellHighlighter.java

License:Open Source License

private void hookListener(final ColumnViewer viewer) {

    Listener listener = event -> {/*from  w  ww  .j  a v a2 s.c o  m*/
        if ((event.detail & SWT.SELECTED) > 0) {
            ViewerCell focusCell = getFocusCell();
            ViewerRow row = focusCell.getViewerRow();

            Assert.isNotNull(row, "Internal structure invalid. Item without associated row is not possible."); //$NON-NLS-1$

            ViewerCell cell = row.getCell(event.index);

            if (focusCell == null || !cell.equals(focusCell)) {
                removeSelectionInformation(event, cell);
            } else {
                markFocusedCell(event, cell);
            }
        }
    };
    viewer.getControl().addListener(SWT.EraseItem, listener);
}