Community
Participate
Working Groups
This example shows: 1. After the delay the node is expanded, and the tree editors no longer align with the items to which they are attached. (Same when collapsing) 2. If you use the arrow up/down keyboard keys to move up and down the items, the TreeEdiors don't stick with their items as the scrollbar scrolls down. 3.2M5 Win32. ---------------- public static void addTTE(Tree t, TreeItem ti) { System.err.println(ti); TreeEditor editor = new TreeEditor(t); ti.setData("editor", editor); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; editor.setEditor(new myCanvas(t, SWT.NONE), ti, 1); } static class myCanvas extends Canvas implements PaintListener { Image i; public myCanvas(Composite parent, int style) { super(parent, SWT.NO_BACKGROUND); addPaintListener(this); i = new Image(getDisplay(), 16, 16); GC gc = new GC(i); gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLUE)); gc.fillRectangle(0, 0, 16, 16); gc.dispose(); } public void paintControl(PaintEvent e) { e.gc.drawImage(i, 0, 0, 16, 16, e.x, e.y, e.width, e.height); } } public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER | SWT.MULTI); new TreeColumn(tree, SWT.LEFT).setWidth(150); new TreeColumn(tree, SWT.LEFT).setWidth(150); tree.setHeaderVisible(true); tree.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TreeItem item = (TreeItem) event.item; TreeItem parentItem = item.getParentItem(); String text = null; if (parentItem == null) { text = "node " + tree.indexOf(item); } else { text = parentItem.getText() + " - " + parentItem.indexOf(item); } int ind = tree.indexOf(item); if (ind == 1) item.setItemCount(5); if (ind > 1 && ind < 5) { text = "HERE >>>"; addTTE(tree, item); } item.setText(text); } }); tree.setItemCount(20); shell.setSize(400, 300); shell.open(); display.timerExec(4000, new Runnable() { public void run() { TreeItem[] items = tree.getItems(); for (int i =0; i < items.length; ++i) items[i].setExpanded(true); } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
Solution depends on Bug 73928.
*** Bug 142556 has been marked as a duplicate of this bug. ***
*** Bug 174585 has been marked as a duplicate of this bug. ***
Here is a work around for this code: import org.eclipse.swt.*; import org.eclipse.swt.custom.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class PR_128574 { public static void addTTE(Tree t, TreeItem ti) { System.err.println(ti); TreeEditor editor = new TreeEditor(t); ti.setData("editor", editor); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; Canvas canvas = new myCanvas(t, SWT.NONE); editor.setEditor(canvas, ti, 1); canvas.setData ("_EDITOR", editor); } static class myCanvas extends Canvas implements PaintListener { Image i; public myCanvas(Composite parent, int style) { super(parent, SWT.NO_BACKGROUND); addPaintListener(this); i = new Image(getDisplay(), 16, 16); GC gc = new GC(i); gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLUE)); gc.fillRectangle(0, 0, 16, 16); gc.dispose(); } public void paintControl(PaintEvent e) { e.gc.drawImage(i, 0, 0, 16, 16, e.x, e.y, e.width, e.height); } } public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER | SWT.MULTI); new TreeColumn(tree, SWT.LEFT).setWidth(150); new TreeColumn(tree, SWT.LEFT).setWidth(150); tree.setHeaderVisible(true); tree.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TreeItem item = (TreeItem) event.item; TreeItem parentItem = item.getParentItem(); String text = null; if (parentItem == null) { text = "node " + tree.indexOf(item); } else { text = parentItem.getText() + " - " + parentItem.indexOf(item); } int ind = tree.indexOf(item); if (ind == 1) item.setItemCount(5); if (ind > 1 && ind < 5) { text = "HERE >>>"; addTTE(tree, item); } item.setText(text); } }); tree.setItemCount(20); shell.setSize(400, 300); shell.open(); display.timerExec(4000, new Runnable() { public void run() { TreeItem[] items = tree.getItems(); for (int i = 0; i < items.length; ++i) items[i].setExpanded(true); Control [] children = tree.getChildren (); for (int i=0; i<children.length; i++) { TreeEditor editor = (TreeEditor) children [i].getData("_EDITOR"); if (editor != null) editor.layout(); } } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
You could also use Control.notifyListeners() to send a fake SWT.Expand event.
Changed the title to reflect the issue 1 (the use of Tree.setExpanded()). The keyboard issues should be fixed.
The fix for the keyboard issue has a side-effect for our application: Since ControlEditor hooks key events in its parent Composite, the Composite takes the focus and doesn't give it down to the actual control when tabbed into. In our application (which shows multiple sibling ControlEditors side by side as a form) this means that tabbing no longer works. Is there a workaround for this? Subclassing the Composite? Using my own implementation of ControlEditor? Unfortunately the NO_FOCUS style is not available in a "normal" Composite (only in Canvasses).
*** Bug 214617 has been marked as a duplicate of this bug. ***
(In reply to comment #7) > The fix for the keyboard issue has a side-effect for our application: > Since ControlEditor hooks key events in its parent Composite, the > Composite takes the focus and doesn't give it down to the actual > control when tabbed into. In our application (which shows multiple sibling > ControlEditors side by side as a form) this means that tabbing no longer works. > > Is there a workaround for this? Subclassing the Composite? Using my own > implementation of ControlEditor? Unfortunately > the NO_FOCUS style is not available in a "normal" Composite (only in > Canvasses). > A workable fix is to subclass the composite and overwrite forceFocus() to always return false.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.