|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2024 SAP SE. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * SAP SE - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.jface.internal.text.contentassist; |
| 15 | + |
| 16 | +import org.eclipse.swt.SWT; |
| 17 | +import org.eclipse.swt.graphics.Color; |
| 18 | +import org.eclipse.swt.widgets.Event; |
| 19 | +import org.eclipse.swt.widgets.Listener; |
| 20 | +import org.eclipse.swt.widgets.Table; |
| 21 | + |
| 22 | +import org.eclipse.jface.internal.text.TableOwnerDrawSupport; |
| 23 | + |
| 24 | +/** |
| 25 | + * Provides custom drawing support for completion proposals. This class ensures that completion |
| 26 | + * proposals are always rendered with a focused appearance. |
| 27 | + * |
| 28 | + * <p> |
| 29 | + * This drawing behavior addresses the particular situation where the code completion is triggered |
| 30 | + * via keyboard shortcut, leaving the editor focused. In such cases, without this custom drawing |
| 31 | + * support, the completion proposal would appear unfocused, leading to a suboptimal coloring. |
| 32 | + * </p> |
| 33 | + */ |
| 34 | +public class CompletionProposalDrawSupport implements Listener { |
| 35 | + |
| 36 | + private TableOwnerDrawSupport fTableOwnerDrawSupport; |
| 37 | + |
| 38 | + private CompletionProposalDrawSupport(Table table) { |
| 39 | + fTableOwnerDrawSupport= new TableOwnerDrawSupport(table); |
| 40 | + } |
| 41 | + |
| 42 | + public static void install(Table table) { |
| 43 | + CompletionProposalDrawSupport listener= new CompletionProposalDrawSupport(table); |
| 44 | + table.addListener(SWT.Dispose, listener); |
| 45 | + table.addListener(SWT.MeasureItem, listener); |
| 46 | + table.addListener(SWT.EraseItem, listener); |
| 47 | + table.addListener(SWT.PaintItem, listener); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void handleEvent(Event event) { |
| 52 | + if (event.type == SWT.EraseItem && event.widget != null && event.gc != null) { |
| 53 | + Color background= event.widget.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND); |
| 54 | + Color forground= event.widget.getDisplay().getSystemColor(SWT.COLOR_WHITE); |
| 55 | + event.gc.setBackground(background); |
| 56 | + event.gc.setForeground(forground); |
| 57 | + } |
| 58 | + fTableOwnerDrawSupport.handleEvent(event); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments