17
17
import java .util .HashSet ;
18
18
import java .util .Set ;
19
19
20
+ import org .eclipse .jface .resource .ColorRegistry ;
21
+ import org .eclipse .jface .resource .JFaceResources ;
20
22
import org .eclipse .swt .SWT ;
21
23
import org .eclipse .swt .graphics .Color ;
22
24
import org .eclipse .swt .graphics .Rectangle ;
@@ -166,20 +168,16 @@ public void update(ViewerCell cell) {
166
168
}
167
169
168
170
/**
169
- * Handle the erase event. The default implementation colors the background
170
- * of selected areas with {@link SWT#COLOR_LIST_SELECTION} and foregrounds
171
- * with {@link SWT#COLOR_LIST_SELECTION_TEXT}. Note that this
172
- * implementation causes non-native behavior on some platforms. Subclasses
173
- * should override this method and <b>not</b> call the super
171
+ * Handle the erase event. The default implementation colors the background of
172
+ * selected areas with "org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND" and
173
+ * foregrounds with "org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND". Note
174
+ * that this implementation causes non-native behavior on some platforms.
175
+ * Subclasses should override this method and <b>not</b> call the super
174
176
* implementation.
175
177
*
176
- * @param event
177
- * the erase event
178
- * @param element
179
- * the model object
178
+ * @param event the erase event
179
+ * @param element the model object
180
180
* @see SWT#EraseItem
181
- * @see SWT#COLOR_LIST_SELECTION
182
- * @see SWT#COLOR_LIST_SELECTION_TEXT
183
181
*/
184
182
protected void erase (Event event , Object element ) {
185
183
@@ -189,11 +187,16 @@ protected void erase(Event event, Object element) {
189
187
Color oldForeground = event .gc .getForeground ();
190
188
Color oldBackground = event .gc .getBackground ();
191
189
192
- event .gc .setBackground (event .item .getDisplay ().getSystemColor (
193
- SWT .COLOR_LIST_SELECTION ));
194
- event .gc .setForeground (event .item .getDisplay ().getSystemColor (
195
- SWT .COLOR_LIST_SELECTION_TEXT ));
190
+ ColorRegistry colorRegistry = JFaceResources .getColorRegistry ();
191
+ if (event .widget instanceof Control control && control .isFocusControl ()) {
192
+ event .gc .setBackground (colorRegistry .get ("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND" )); //$NON-NLS-1$
193
+ event .gc .setForeground (colorRegistry .get ("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND" )); //$NON-NLS-1$
194
+ } else {
195
+ event .gc .setBackground (colorRegistry .get ("org.eclipse.ui.workbench.SELECTED_CELL_BACKGROUND_NO_FOCUS" )); //$NON-NLS-1$
196
+ event .gc .setForeground (colorRegistry .get ("org.eclipse.ui.workbench.SELECTED_CELL_FOREGROUND_NO_FOCUS" )); //$NON-NLS-1$
197
+ }
196
198
event .gc .fillRectangle (bounds );
199
+
197
200
/* restore the old GC colors */
198
201
event .gc .setForeground (oldForeground );
199
202
event .gc .setBackground (oldBackground );
0 commit comments