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

Bug 127132

Summary: [GTK] TableColumn#pack does not work for virtual table
Product: [Eclipse Project] Platform Reporter: Samantha Chan <chanskw>
Component: SWTAssignee: Xi Yan <xixiyan>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: arunkumar.thondapu, eclipse, ericwill, lufimtse, niraj.modi, xixiyan
Version: 3.2Keywords: triaged
Target Milestone: 4.9 M2   
Hardware: PC   
OS: Linux-GTK   
See Also: https://git.eclipse.org/r/124620
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=ebc68f80d66ed176ef3bb5409964b9c502d19556
https://git.eclipse.org/r/126031
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=110467fbdd4dac0efc1995fef03b4ab92d527232
Whiteboard:
Bug Depends on:    
Bug Blocks: 131184    
Attachments:
Description Flags
Sample to reproduce the NPE none

Description Samantha Chan CLA 2006-02-09 13:59:50 EST
I am using a virtual table, packing the columns after data is populated in the table has no effect on Linux GTK.

If the table is defined as non-virtual, TableColumn#pack works as expected.

/*
 * Testcase to demonstrate problem with Table not
 * being able to pack columns for virtual tables
 */
public class TestTableBug {

	private static TableColumn column1;
	private static TableColumn column2;
	private static TableColumn column3;

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		

		
		final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.VIRTUAL);
		final TableCursor cursor = new TableCursor(table, SWT.NONE);
		
		table.setLayoutData(new GridData(GridData.FILL_BOTH));
		column1 = new TableColumn(table, SWT.NONE);
		column1.setText("A");
		column2 = new TableColumn(table, SWT.NONE);
		column1.setText("B");
		column3 = new TableColumn(table, SWT.NONE);
		column1.setText("C");
		
		for (int i = 0; i < 500; i++) {
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText(new String[] { "cell "+i+" 0", "cell "+i+" 1", "cell "+i+" 2"});
		}
		
		// These have no effects on Linux GTK?
		column1.pack();
		column2.pack();
		column3.pack();
		
		Button action = new Button(shell, SWT.PUSH);
		action.setText("Pack Columns");
		action.addSelectionListener(new SelectionListener() {

			public void widgetSelected(SelectionEvent e) {
				// These have no effects on Linux GTK?
				column1.pack();
				column2.pack();
				column3.pack();
			}

			public void widgetDefaultSelected(SelectionEvent e) {
				
				
			}});
			
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 1 Veronika Irvine CLA 2006-02-10 09:40:43 EST
This is intentional.  In order for pack to work, it would need to send a SetData event for every row in the column.  This does not make sense for a virtual table.  The idea of the virtual table is that there are a large number of rows and it is too expensive to set the text and image for all the rows.  The text and image are only requested as required (made visible etc).   Pack needs to figure out which cell is widest by examinign the width of the text and image for every row.

Closing this bug report as wont fix.  You should use TableColumn.setWidth() for virtual tables.
Comment 2 Samantha Chan CLA 2006-02-10 10:13:50 EST
On Windows and Motif, pack actually works.  The size seems to be calculated based on what's being displayed.  This is different on Linux GTK.  When calling pack, it does nothing.

When running the same testcae, pressing the button will pack the columns on windows and motif, but not on Linux GTK.

Please reconsider this bug if possible.
Comment 3 Samantha Chan CLA 2006-02-16 16:16:54 EST
Veronika -

I am just trying this out again.  If I place my mouse at the column header and double click right on the border.  The columns would resize to the preferred size.  Why is it that we cannot do this programatically via #pack?  It's never mentioned in the javadoc that this would not work with virtual tables.  

I am not sure that using #setWidth to work around this is the right way to go.  As a client, I do not think we should write our own code to simulate the #pack behaviour.  And I don't think we can do it more efficiently than doing it in the swt layer.

Thanks...
Samantha
Comment 4 Samantha Chan CLA 2006-02-23 18:38:02 EST
Not sure if you got my previous comments.  Re-opening for comments.

Thanks...
Samantha
Comment 5 Grant Gayed CLA 2006-03-14 14:19:56 EST
OSX has the same behaviour
Comment 6 Veronika Irvine CLA 2006-03-16 15:44:42 EST
Samantha, I have not forgotten this bug - I just need to find some time to get to work on it.
Comment 7 Samantha Chan CLA 2006-04-10 11:38:13 EDT
Hi Veronika -
Just wondering if there is any chance of getting this fixed for 3.2?  Let me know if there is anything else I can do to help with this.
Thanks...
Samantha
Comment 8 Veronika Irvine CLA 2006-04-24 10:38:40 EDT
In RC1, I fixed pack for virtual table on GTK and Mac OS X (already worked for Windows and Motif).

The only reason I haven't closed this bug yet is because I am working on implementing the same sort for TreeColumn.
Comment 9 John Arthorne CLA 2006-05-31 16:22:02 EDT
Clearing milestone since this bug is still open.
Comment 10 Steve Northover CLA 2007-06-18 13:30:43 EDT
Bogdan to see whether Veronika fixed this for Tree as well.
Comment 11 Bogdan Gheorghe CLA 2007-06-19 13:07:23 EDT
Still missing the the TreeColumn code in RC4.
Comment 12 Eric Williams CLA 2016-08-17 12:17:37 EDT
This bug is still reproducible, not sure how important it is though. Tossing it back into the pool.
Comment 13 Arun Thondapu CLA 2017-05-25 06:28:58 EDT
Moving to 4.8.
Comment 14 Niraj Modi CLA 2018-05-14 05:12:25 EDT
Moving to 4.9, please re-target as required.
Comment 15 Eclipse Genie CLA 2018-06-15 12:35:31 EDT
New Gerrit change created: https://git.eclipse.org/r/124620
Comment 17 Eric Williams CLA 2018-06-18 11:53:23 EDT
(In reply to Eclipse Genie from comment #16)
> Gerrit change https://git.eclipse.org/r/124620 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=ebc68f80d66ed176ef3bb5409964b9c502d19556

In master now. Thanks for the patch Xi!
Comment 18 Eric Williams CLA 2018-07-03 16:31:59 EDT
*** Bug 531875 has been marked as a duplicate of this bug. ***
Comment 19 Thomas Singer CLA 2018-07-13 06:24:11 EDT
The latest changes cause an NPE when invoking pack on a virtual table. Attached you'll find a snippet to reproduce.
Comment 20 Thomas Singer CLA 2018-07-13 06:25:05 EDT
Created attachment 274967 [details]
Sample to reproduce the NPE
Comment 21 Eclipse Genie CLA 2018-07-13 11:17:40 EDT
New Gerrit change created: https://git.eclipse.org/r/126031
Comment 23 Eric Williams CLA 2018-07-13 15:49:06 EDT
(In reply to Eclipse Genie from comment #22)
> Gerrit change https://git.eclipse.org/r/126031 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=110467fbdd4dac0efc1995fef03b4ab92d527232

Patch is in master, thanks for catching that Thomas.