Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 197612 Details for
Bug 268135
[Viewers] [CellEditors] Table with SWT.MULTI and TableViewerEditor problem
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
FocusCellHighlighter that can handle multiselection and keyboard navigation (HACK!)
FocusCellOwnerDrawHighlighterForMultiselection.java (text/plain), 6.98 KB, created by
Dominik Kaspar
on 2011-06-08 11:06:40 EDT
(
hide
)
Description:
FocusCellHighlighter that can handle multiselection and keyboard navigation (HACK!)
Filename:
MIME Type:
Creator:
Dominik Kaspar
Created:
2011-06-08 11:06:40 EDT
Size:
6.98 KB
patch
obsolete
>package com.qnamic.ui.base.table; > >import java.lang.reflect.Method; > >import org.apache.log4j.Logger; >import org.eclipse.core.runtime.Assert; >import org.eclipse.jface.viewers.ColumnViewer; >import org.eclipse.jface.viewers.FocusCellHighlighter; >import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; >import org.eclipse.jface.viewers.TreeViewerFocusCellManager; >import org.eclipse.jface.viewers.ViewerCell; >import org.eclipse.jface.viewers.ViewerRow; >import org.eclipse.swt.SWT; >import org.eclipse.swt.graphics.Color; >import org.eclipse.swt.graphics.GC; >import org.eclipse.swt.graphics.Rectangle; >import org.eclipse.swt.widgets.Event; >import org.eclipse.swt.widgets.Listener; >import org.eclipse.swt.widgets.Widget; > >/** > * Hack for solving the jface Bug 268135 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=268135) [Viewers] [CellEditors] > * Table with SWT.MULTI and TableViewerEditor problem. > * > * @see FocusCellOwnerDrawHighlighter > */ >public class FocusCellOwnerDrawHighlighterForMultiselection extends FocusCellHighlighter { > > private static final Logger LOGGER = Logger.getLogger(FocusCellOwnerDrawHighlighterForMultiselection.class); > > /** > * Create a new instance which can be passed to a {@link TreeViewerFocusCellManager} > * @param viewer the viewer > */ > public FocusCellOwnerDrawHighlighterForMultiselection(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)) { > 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 = new Listener() { > > public void handleEvent(Event event) { > if ((event.detail & SWT.SELECTED) > 0) { > ViewerCell focusCell = getFocusCell(); > > try { > Method m = viewer.getClass().getDeclaredMethod("getViewerRowFromItem", Widget.class); > boolean access = m.isAccessible(); > if (!access) { > m.setAccessible(true); > } > ViewerRow row = (ViewerRow) m.invoke(viewer, event.item); > m.setAccessible(access); > > 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)) { > markFocusedCell(event, cell); > } > } catch (Exception e) { > LOGGER.error(e.getLocalizedMessage(), e); > } > > } > } > > }; > viewer.getControl().addListener(SWT.EraseItem, listener); > } > > /** > * The color to use when rendering the background of the selected cell when the control has the input focus > * @param cell the cell which is colored > * @return the color or <code>null</code> to use the default > */ > protected Color getSelectedCellBackgroundColor(ViewerCell cell) { > return cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); > } > > /** > * The color to use when rendering the foreground (=text) of the selected cell when the control has the input focus > * @param cell the cell which is colored > * @return the color or <code>null</code> to use the default > */ > protected Color getSelectedCellForegroundColor(ViewerCell cell) { > return null; > } > > /** > * The color to use when rendering the foreground (=text) of the selected cell when the control has <b>no</b> input > * focus > * @param cell the cell which is colored > * @return the color or <code>null</code> to use the same used when control has focus > * @since 3.4 > */ > protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) { > return null; > } > > /** > * The color to use when rendering the background of the selected cell when the control has <b>no</b> input focus > * @param cell the cell which is colored > * @return the color or <code>null</code> to use the same used when control has focus > * @since 3.4 > */ > protected Color getSelectedCellBackgroundColorNoFocus(ViewerCell cell) { > return null; > } > > /** > * Controls whether the whole cell or only the text-area is highlighted > * @param cell the cell which is highlighted > * @return <code>true</code> if only the text area should be highlighted > * @since 3.4 > */ > protected boolean onlyTextHighlighting(ViewerCell cell) { > return false; > } > > @Override > protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) { > super.focusCellChanged(newCell, oldCell); > > // Redraw new area > if (newCell != null) { > Rectangle rect = newCell.getBounds(); > int x = newCell.getColumnIndex() == 0 ? 0 : rect.x; > int width = newCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width; > // 1 is a fix for Linux-GTK > newCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true); > } > > if (oldCell != null) { > Rectangle rect = oldCell.getBounds(); > int x = oldCell.getColumnIndex() == 0 ? 0 : rect.x; > int width = oldCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width; > // 1 is a fix for Linux-GTK > oldCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true); > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 268135
:
128469
|
128470
| 197612 |
211087