Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 258196

Summary: [GTK] Virtual Tree does not resize correctly horizontally
Product: [Eclipse Project] Platform Reporter: Pawel Piech <pawel.1.piech>
Component: SWTAssignee: Eric Williams <ericwill>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: darin.eclipse, eclipse.felipe, ericwill, markus.kell.r
Version: 3.5Keywords: triaged
Target Milestone: 4.9   
Hardware: PC   
OS: Linux-GTK   
See Also: https://git.eclipse.org/r/123478
https://git.eclipse.org/r/123542
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=2bd7cc57d6f8db85984adca7abc84236618f0b2d
https://git.eclipse.org/c/platform/eclipse.platform.swt.binaries.git/commit/?id=4a1a10fc2fc99f6ee7f995f5952e40da40b3dede
Whiteboard:
Bug Depends on:    
Bug Blocks: 252677    
Attachments:
Description Flags
Image of the Debug view with missing scroll bar.
none
Patch with suggested fix. none

Description Pawel Piech CLA 2008-12-09 17:08:51 EST
Created attachment 119978 [details]
Image of the Debug view with missing scroll bar.

I ran into a problem with the virtual tree on Linux.  Our tree viewer implementation calls setTesxt() and setImage() in a separate update from setData().  However, the width of the column is calculated only right after setData() is called, which can leave with some of the items being cut off in the tree.  See the attached screenshot.

To easily reproduce the problem:
 - Make sure there is something in the Debug view
 - Make the debug view narrow enough so that there is a horizontal scroll bar.
 - Close and reopen the Debug view.
 - The text is cut off, but there is no horizontal scroll bar.
Comment 1 Pawel Piech CLA 2008-12-09 17:12:35 EST
Created attachment 119979 [details]
Patch with suggested fix.

This patch fixes the problem by causing the column size to be updated after an item's text/image/font has been set.  It seems safe to me, but I can't claim to be an SWT expert...
Comment 2 Felipe Heidrich CLA 2009-01-28 12:31:42 EST
>Our tree viewer implementation calls setTesxt() and setImage()
>in a separate update from setData().  

When exactly do you call setText/setImage ? Why can't you call it from SetData ?

Comment 3 Felipe Heidrich CLA 2009-01-28 12:32:32 EST
Can you provide a simple snippet for us to reproduce the problem here ? Thanks
Comment 4 Pawel Piech CLA 2009-01-28 12:47:13 EST
(In reply to comment #2)
> When exactly do you call setText/setImage ? Why can't you call it from SetData
> ?
The debugger views allow the label information to be calculated asynchronously (e.g. in a job), based on the element that was set to the item.

(In reply to comment #3)
> Can you provide a simple snippet for us to reproduce the problem here ? Thanks
Will do.

Comment 5 Pawel Piech CLA 2009-02-13 00:42:31 EST
The following snippet, which is a modified virtual tree snippet demonstrates the problem.  After the view appears, expand some elements and resize the shell to make some of the elements not fit.  The scroll bars do not appear as they should

public class Bug258192 {
    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.VIRTUAL | SWT.BORDER);
        tree.addListener(SWT.SetData, new Listener() {
            public void handleEvent(Event event) {
                final 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);
                }
                item.setData(text);
                item.setItemCount(10);
                display.asyncExec(new Runnable() {
                    public void run() {
                        if (!item.isDisposed()) {
                            item.setText(item.getData().toString());
                        }
                    }
                });
            }
        });
        tree.setItemCount(20);
        shell.setSize(400, 300);
        shell.open();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }

}
Comment 6 Pawel Piech CLA 2009-11-05 13:20:02 EST
ping
Comment 7 Praveen CLA 2010-05-17 11:21:35 EDT
It seems that this problem has cropped up from the recent versions of GTK (might be from 2.14 or 2.16).
Comment 8 Pawel Piech CLA 2010-05-20 13:49:11 EDT
(In reply to comment #7)
> It seems that this problem has cropped up from the recent versions of GTK
> (might be from 2.14 or 2.16).

Does that mean that my suggested fix may be accepted? ;-)
Comment 9 Pawel Piech CLA 2012-04-05 18:29:58 EDT
ping
Comment 10 Eric Williams CLA 2018-05-14 14:11:45 EDT
Still reproducible on GTK3.22, 4.8 M7, and Fedora 28.
Comment 11 Eclipse Genie CLA 2018-05-28 15:04:08 EDT
New Gerrit change created: https://git.eclipse.org/r/123478
Comment 12 Eric Williams CLA 2018-05-28 17:02:33 EDT
(In reply to Eclipse Genie from comment #11)
> New Gerrit change created: https://git.eclipse.org/r/123478

Will merge in 4.9.
Comment 13 Eclipse Genie CLA 2018-05-29 11:38:52 EDT
New Gerrit change created: https://git.eclipse.org/r/123542
Comment 16 Eric Williams CLA 2018-05-30 13:17:12 EDT
Patches for bumping versions merged along with the actual patch as well.