diff options
author | Xi Yan | 2019-02-22 16:53:45 +0000 |
---|---|---|
committer | Eric Williams | 2019-03-11 19:42:25 +0000 |
commit | 1dd8b6850f4caf6a689de54a9065a448fc455e46 (patch) | |
tree | 8521d853a3d8147b8dddaeeed4a5b898a2cf1c22 | |
parent | b83f349e78cabfeffbaefdb40e59463b256b1084 (diff) | |
download | eclipse.platform.swt-1dd8b6850f4caf6a689de54a9065a448fc455e46.tar.gz eclipse.platform.swt-1dd8b6850f4caf6a689de54a9065a448fc455e46.tar.xz eclipse.platform.swt-1dd8b6850f4caf6a689de54a9065a448fc455e46.zip |
Bug 489751 - [GTK3] disposing an item will select a node
Disposing selected item in Tree/Table makes the next node selected
again. Avoid this by setting the selection to another item and
deselecting before disposing TableItem/TreeItem.
Change-Id: I0b8494a3f03d32d1926210c2293001306872e504
Signed-off-by: Xi Yan <xixiyan@redhat.com>
4 files changed, 194 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java index a80aabfd48..b2338bba37 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java @@ -239,6 +239,18 @@ void destroyWidget () { releaseHandle (); } +@Override +public void dispose () { + // Workaround to Bug489751, avoid selecting next node when selected node is disposed. + if (parent != null && parent.getItemCount() > 0) { + TableItem tmpItem = parent.getItem(0); + long /*int*/ path = GTK.gtk_tree_model_get_path (parent.modelHandle, tmpItem.handle); + GTK.gtk_tree_view_set_cursor (parent.handle, path, 0, false); + parent.deselectAll(); + } + super.dispose(); +} + /** * Returns the receiver's background color. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java index 1019df25ed..fe360c5136 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java @@ -1075,6 +1075,18 @@ void releaseWidget () { strings = null; } +@Override +public void dispose () { + // Workaround to Bug489751, avoid selecting next node when selected node is disposed. + if (parent != null && parent.getItemCount() > 0) { + TreeItem tmpItem = parent.getItem(0); + long /*int*/ path = GTK.gtk_tree_model_get_path (parent.modelHandle, tmpItem.handle); + GTK.gtk_tree_view_set_cursor (parent.handle, path, 0, false); + parent.deselectAll(); + } + super.dispose(); +} + /** * Removes all of the items from the receiver. * diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489751_TableItemDisposeSelect.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489751_TableItemDisposeSelect.java new file mode 100644 index 0000000000..678baa466b --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489751_TableItemDisposeSelect.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2019 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: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +public class Bug489751_TableItemDisposeSelect { + + private static final boolean DISPOSE_DIRECTLY = true; + + public static void main(String[] args) { + final Display display = new Display (); + final Shell shell = new Shell (display); + shell.setLayout(new FillLayout()); + final Table tree = new Table (shell, SWT.BORDER); + for (int i=0; i<4; i++) { + TableItem iItem = new TableItem (tree, 0); + iItem.setText ("TableItem (0) -" + i); + } + + tree.setSelection(tree.getItem(3)); + + shell.setSize(200, 200); + shell.open(); + + display.timerExec(1000, () -> { + if (shell.isDisposed()) { + return; + } + + // replace selected node + final TableItem[] selection = tree.getSelection(); + if (selection.length != 1) { + return; + } + + final TableItem item = selection[0]; + + tree.deselectAll(); + + if (DISPOSE_DIRECTLY) { + item.dispose(); + } + else { + display.asyncExec(() -> { + if (!item.isDisposed()) { + return; + } + + item.dispose(); + }); + } + }); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489751_TreeItemDisposeSelect.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489751_TreeItemDisposeSelect.java new file mode 100644 index 0000000000..8badedf7c4 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489751_TreeItemDisposeSelect.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2019 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: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +public class Bug489751_TreeItemDisposeSelect { + + private static final boolean DISPOSE_DIRECTLY = true; + + public static void main(String[] args) { + final Display display = new Display (); + final Shell shell = new Shell (display); + shell.setLayout(new FillLayout()); + final Tree tree = new Tree (shell, SWT.BORDER); + for (int i=0; i<4; i++) { + TreeItem iItem = new TreeItem (tree, 0); + iItem.setText ("TreeItem (0) -" + i); + for (int j=0; j<4; j++) { + TreeItem jItem = new TreeItem (iItem, 0); + jItem.setText ("TreeItem (1) -" + j); + for (int k=0; k<4; k++) { + TreeItem kItem = new TreeItem (jItem, 0); + kItem.setText ("TreeItem (2) -" + k); + for (int l=0; l<4; l++) { + TreeItem lItem = new TreeItem(kItem, 0); + lItem.setText ("TreeItem (3) -" + l); + } + } + } + } + + final TreeItem firstNode = tree.getItem(0); + firstNode.setExpanded(true); + tree.setSelection(firstNode.getItem(3)); + + shell.setSize(200, 200); + shell.open(); + + display.timerExec(1000, () -> { + if (shell.isDisposed()) { + return; + } + + // replace selected node + final TreeItem[] selection = tree.getSelection(); + if (selection.length != 1) { + return; + } + + final TreeItem item = selection[0]; + final TreeItem parentItem = item.getParentItem(); + if (parentItem == null) { + return; + } + + tree.deselectAll(); + + if (DISPOSE_DIRECTLY) { + item.dispose(); + } + else { + display.asyncExec(() -> { + if (!item.isDisposed()) { + return; + } + + item.dispose(); + }); + } + }); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose(); + } +}
\ No newline at end of file |