Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorXi Yan2019-01-14 20:40:19 +0000
committerXi Yan2019-01-17 21:10:01 +0000
commite28724ee06cedcf594176ec66c06abdcfc996f2a (patch)
tree9b2a7f0116829348b9061d73d29bf90db083a38f /tests
parentce2d380a4f6ab3facf81919f1e2546655ef70e7f (diff)
downloadeclipse.platform.swt-e28724ee06cedcf594176ec66c06abdcfc996f2a.tar.gz
eclipse.platform.swt-e28724ee06cedcf594176ec66c06abdcfc996f2a.tar.xz
eclipse.platform.swt-e28724ee06cedcf594176ec66c06abdcfc996f2a.zip
Bug 542940 - Method setEditor of class TreeEditor raises java
nullException Calling gtk_widget_show and then gtk_widget_hide in Control#setBounds from TreeEditor.setEditor causes display to be null. The workaround is to force Text to be visible on initialization so that we do not need to force show/hide in order to set bound for the TreeEditor text. See similar fix for Button in Bug 533469. Tested with attached snippet, Bug533469_GhostButton, Bug497705_setBoundsAfterSetVisible. Change-Id: I9fe8cfb63358608700246d9a6c9355b53169045d Signed-off-by: Xi Yan <xixiyan@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug542940_NPETreeSetEditor.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug542940_NPETreeSetEditor.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug542940_NPETreeSetEditor.java
new file mode 100644
index 0000000000..5d748ec095
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug542940_NPETreeSetEditor.java
@@ -0,0 +1,87 @@
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TreeEditor;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+public class Bug542940_NPETreeSetEditor {
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setText("Text Tree Editor");
+ shell.setLayout(new FillLayout());
+
+ final Tree tree = new Tree(shell, SWT.SINGLE);
+ for (int i = 0; i < 3; i++) {
+ TreeItem iItem = new TreeItem(tree, SWT.NONE);
+ iItem.setText("Item " + (i + 1));
+ for (int j = 0; j < 3; j++) {
+ TreeItem jItem = new TreeItem(iItem, SWT.NONE);
+ jItem.setText("Sub Item " + (j + 1));
+ for (int k = 0; k < 3; k++) {
+ new TreeItem(jItem, SWT.NONE).setText("Sub Sub Item " + (k + 1));
+ }
+ jItem.setExpanded(true);
+ }
+ iItem.setExpanded(true);
+ }
+
+ final TreeEditor editor = new TreeEditor(tree);
+ editor.horizontalAlignment = SWT.LEFT;
+ editor.grabHorizontal = true;
+
+ tree.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent event) {
+ if (event.keyCode == SWT.F2 && tree.getSelectionCount() == 1) {
+ final TreeItem item = tree.getSelection()[0];
+
+ final Text text = new Text(tree, SWT.NONE);
+// text.setBounds(0, 0, 1, 1);
+ text.setText(item.getText());
+ text.selectAll();
+ text.setFocus();
+
+ text.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusLost(FocusEvent event) {
+ item.setText(text.getText());
+ text.dispose();
+ }
+ });
+
+ text.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent event) {
+ switch (event.keyCode) {
+ case SWT.CR:
+ item.setText(text.getText());
+ case SWT.ESC:
+ text.dispose();
+ break;
+ }
+ }
+ });
+ editor.setEditor(text, item);
+ }
+ }
+ });
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+} \ No newline at end of file

Back to the top