public void afterEditorDeactivated( ColumnViewerEditorDeactivationEvent e ) { focusCellChanged( getFocusCell(), null ); } public void beforeEditorActivated( ColumnViewerEditorActivationEvent e )
removeSelectionInformation( null, oldCell ); markFocusedCell( null, newCell );
/** * Create a new instance which can be passed to a * {@link TreeViewerFocusCellManager} * * @param viewer * the viewer */ public FocusCellOwnerDrawHighlighter(ColumnViewer viewer) { super(viewer); hookListener(viewer); }
private void markFocusedCell(Event event, ViewerCell cell) { Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell) : getSelectedCellBackgroundColorNoFocus(cell); Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell) : getSelectedCellForegroundColorNoFocus(cell); if (foreground != null || background != null || onlyTextHighlighting(cell)) {
private void hookListener(final ColumnViewer viewer) { Listener listener = event -> { if ((event.detail & SWT.SELECTED) > 0) { ViewerCell focusCell = getFocusCell(); ViewerRow row = viewer.getViewerRowFromItem(event.item); 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); }
propertiesViewer, new FocusCellOwnerDrawHighlighter( propertiesViewer), strategy);
private void markFocusedCell(Event event, ViewerCell cell) { Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell) : getSelectedCellBackgroundColorNoFocus(cell); Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell) : getSelectedCellForegroundColorNoFocus(cell); if (foreground != null || background != null || onlyTextHighlighting(cell)) { GC gc = event.gc; if (background == null) { background = cell.getItem().getDisplay().getSystemColor( SWT.COLOR_LIST_SELECTION); } if (foreground == null) { foreground = cell.getItem().getDisplay().getSystemColor( SWT.COLOR_LIST_SELECTION_TEXT); } gc.setBackground(background); gc.setForeground(foreground); if (onlyTextHighlighting(cell)) { Rectangle area = event.getBounds(); Rectangle rect = cell.getTextBounds(); if( rect != null ) { area.x = rect.x; } gc.fillRectangle(area); } else { gc.fillRectangle(event.getBounds()); } event.detail &= ~SWT.SELECTED; } }
private void hookListener(final ColumnViewer viewer) { Listener listener = event -> { if ((event.detail & SWT.SELECTED) > 0) { ViewerCell focusCell = getFocusCell(); ViewerRow row = viewer.getViewerRowFromItem(event.item); 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)) { if (removeNonFocusedSelectionInformation) { removeSelectionInformation(event, cell); } } else { markFocusedCell(event, cell); } } }; viewer.getControl().addListener(SWT.EraseItem, listener); }
TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(getViewer(), new FocusCellOwnerDrawHighlighter(getViewer())); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(getViewer()) { @Override
private void markFocusedCell(Event event, ViewerCell cell) { Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell) : getSelectedCellBackgroundColorNoFocus(cell); Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell) : getSelectedCellForegroundColorNoFocus(cell); if (foreground != null || background != null || onlyTextHighlighting(cell)) { GC gc = event.gc; if (background == null) { background = cell.getItem().getDisplay().getSystemColor( SWT.COLOR_LIST_SELECTION); } if (foreground == null) { foreground = cell.getItem().getDisplay().getSystemColor( SWT.COLOR_LIST_SELECTION_TEXT); } gc.setBackground(background); gc.setForeground(foreground); if (onlyTextHighlighting(cell)) { Rectangle area = event.getBounds(); Rectangle rect = cell.getTextBounds(); if( rect != null ) { area.x = rect.x; } gc.fillRectangle(area); } else { gc.fillRectangle(event.getBounds()); } event.detail &= ~SWT.SELECTED; } }
TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(getViewer(), new FocusCellOwnerDrawHighlighter(getViewer())); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(getViewer()) { protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
/** * Create a new instance which can be passed to a * {@link TreeViewerFocusCellManager} * * @param viewer * the viewer * @param removeNonFocusedSelectionInformation * <code>true</code> if only the currently focused cell should be * indicated as selected. <code>false</code> to indicate both the * full selection and the currently focused cell. * @since 3.14 */ public FocusCellOwnerDrawHighlighter(ColumnViewer viewer, boolean removeNonFocusedSelectionInformation) { super(viewer); this.removeNonFocusedSelectionInformation = removeNonFocusedSelectionInformation; hookListener(viewer); }