diff options
author | Xi Yan | 2019-03-26 20:44:38 +0000 |
---|---|---|
committer | Xi Yan | 2019-04-15 16:08:58 +0000 |
commit | 3e5feeebc01c8eb10163d3571e6bd367cf27de1c (patch) | |
tree | 125eeb438e61cc32753da4bbae243119282ce274 /tests | |
parent | 9304fe94fda6a01723eca1806e3ff9b70dc5e406 (diff) | |
download | eclipse.platform.swt-3e5feeebc01c8eb10163d3571e6bd367cf27de1c.tar.gz eclipse.platform.swt-3e5feeebc01c8eb10163d3571e6bd367cf27de1c.tar.xz eclipse.platform.swt-3e5feeebc01c8eb10163d3571e6bd367cf27de1c.zip |
Bug 545645 - [GTK] Table/Tree header must not keep focus
Address issue with updating SWT.VIRTUAL table making header being
focused on click.
Tested with 2 attached snippets and Snippet38.
Change-Id: If02802c01bab05db3b7c241e90dc4a4ed4176608
Signed-off-by: Xi Yan <xixiyan@redhat.com>
Diffstat (limited to 'tests')
2 files changed, 217 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545645_VirtualTableHeaderFocus.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545645_VirtualTableHeaderFocus.java new file mode 100644 index 0000000000..f17b114abf --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545645_VirtualTableHeaderFocus.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thomas Singer - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +public class Bug545645_VirtualTableHeaderFocus { + + // Constants ============================================================== + + private static final int COUNT1 = 1000; + + // Static ================================================================= + + public static void main(String[] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout(SWT.VERTICAL)); + + final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); + + table.setHeaderVisible(true); + + final Listener listener = new Listener() { + private boolean packPending = true; + + @Override + public void handleEvent(Event event) { + final TableItem item = (TableItem)event.item; + if (event.type == SWT.EraseItem) { + if (event.index < 2) { + event.detail &= ~SWT.FOREGROUND; + } + } + else if (event.type == SWT.PaintItem) { + if (event.index == 0) { + event.gc.drawText((String)item.getData(), event.x, event.y, true); + } + else if (event.index == 1) { + final String text = (String)item.getData(); + final Point size = event.gc.textExtent(text); + final Rectangle bounds = item.getBounds(event.index); + event.gc.drawText(text, bounds.x + bounds.width - size.x, bounds.y + bounds.height - size.y, true); + } + } + else if (event.type == SWT.MeasureItem) { + final String text = (String)item.getData(); + final Point point = event.gc.textExtent(text); + event.height = point.y * 2; + event.width = Math.max(event.width, point.x); + } + else if (event.type == SWT.SetData) { + final int index = table.indexOf(item); + final String data = "Item " + index; + item.setText(2, data); + item.setData(data); + if (packPending) { + packPending = false; + display.asyncExec(() -> { + table.setRedraw(false); + for (TableColumn column : table.getColumns()) { + column.pack(); + } + table.setRedraw(true); + }); + } + } + } + }; + table.addListener(SWT.EraseItem, listener); + table.addListener(SWT.SetData, listener); + table.addListener(SWT.MeasureItem, listener); + table.addListener(SWT.PaintItem, listener); + + createColumn(SWT.LEFT, "OD Left", table); + createColumn(SWT.RIGHT, "OD Right", table); + createColumn(SWT.LEFT, "Primitive", table); + + table.setItemCount(COUNT1); + table.select(0); + + shell.setSize(400, 500); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } + + private static void createColumn(int style, String text, Table table) { + final TableColumn tableColumn = new TableColumn(table, style); + tableColumn.setText(text); + tableColumn.setMoveable(true); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545645_VirtualTableHeaderFocus2.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545645_VirtualTableHeaderFocus2.java new file mode 100644 index 0000000000..9af90ea192 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545645_VirtualTableHeaderFocus2.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thomas Singer - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +public class Bug545645_VirtualTableHeaderFocus2 { + + // Constants ============================================================== + + private static final int COUNT1 = 1000; + + // Static ================================================================= + + public static void main(String[] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout(SWT.VERTICAL)); + + final Table table = new Table(shell, + SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); + + table.setHeaderVisible(true); + final Listener listener = event -> { + final TableItem item = (TableItem) event.item; + if (event.type == SWT.EraseItem) { + if (event.index < 2) { + event.detail &= ~SWT.FOREGROUND; + } + } else if (event.type == SWT.PaintItem) { + if (event.index == 0) { + event.gc.drawText((String) item.getData(), event.x, event.y, true); + } else if (event.index == 1) { + final String text1 = (String) item.getData(); + final Point size = event.gc.textExtent(text1); + final Rectangle bounds = item.getBounds(event.index); + event.gc.drawText(text1, bounds.x + bounds.width - size.x, bounds.y + bounds.height - size.y, true); + } + } else if (event.type == SWT.MeasureItem) { + final String text2 = (String) item.getData(); + final Point point = event.gc.textExtent(text2); + event.height = point.y * 2; + event.width = Math.max(event.width, point.x); + } else if (event.type == SWT.SetData) { + final int index = table.indexOf(item); + final String data = "Item " + index; + item.setText(2, data); + item.setData(data); + } + }; + table.addListener(SWT.EraseItem, listener); + table.addListener(SWT.SetData, listener); + table.addListener(SWT.MeasureItem, listener); + table.addListener(SWT.PaintItem, listener); + + createColumn(SWT.LEFT, "OD Left", table); + createColumn(SWT.RIGHT, "OD Right", table); + createColumn(SWT.LEFT, "Primitive", table); + + table.setItemCount(COUNT1); + table.select(0); + + shell.setSize(600, 500); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } + + private static void createColumn(int style, String text, Table table) { + final TableColumn tableColumn = new TableColumn(table, style); + tableColumn.setText(text); + tableColumn.setMoveable(true); + tableColumn.setWidth(75); + } +}
\ No newline at end of file |