Summary: | TreeEditors don't follow Items when expanding items | ||
---|---|---|---|
Product: | [Eclipse Project] Platform | Reporter: | Rutger Ovidius <ovidr> |
Component: | SWT | Assignee: | Steve Northover <steve_northover> |
Status: | NEW --- | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | jussi.suistomaa, michael.krkoska, peter.kullmann, veronika_irvine, wcrisman |
Version: | 3.2 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows XP | ||
See Also: | https://bugs.eclipse.org/bugs/show_bug.cgi?id=551999 | ||
Whiteboard: | |||
Bug Depends on: | 73928 | ||
Bug Blocks: |
Description
Rutger Ovidius
2006-02-19 23:08:10 EST
*** 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. |