Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 301682 - TableRidget#setColumnWidths: document standard limitations reg. layout managers
Summary: TableRidget#setColumnWidths: document standard limitations reg. layout managers
Status: RESOLVED FIXED
Alias: None
Product: Riena
Classification: RT
Component: ridget (show other bugs)
Version: 1.2.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-03 06:16 EST by Ralf Ebert CLA
Modified: 2012-05-21 06:43 EDT (History)
2 users (show)

See Also:


Attachments
Snippet (4.74 KB, text/plain)
2010-02-05 02:14 EST, Elias Volanakis CLA
no flags Details
Bug (4.97 KB, application/octet-stream)
2012-03-13 12:12 EDT, Nobody - feel free to take it CLA
no flags Details
test case for column widths bug (1.84 KB, patch)
2012-03-26 07:30 EDT, Nobody - feel free to take it CLA
christian.campo: iplog+
Details | Diff
fix (2.02 KB, patch)
2012-03-26 07:32 EDT, Nobody - feel free to take it CLA
christian.campo: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Ebert CLA 2010-02-03 06:16:54 EST
Create a view like this:

public class SomeView extends SubModuleView<SomeController> {

	@Override
	public void basicCreatePartControl(Composite parent) {
		parent.setLayout(new FillLayout());
		Table table = new Table(parent, SWT.NONE);		
	}
	
}

Try to setColumnWidths in the controller. This will have no effect.

This is because the TableColumnLayout rule "You can only add the Layout to a container whose only child is the Table control you want the Layout applied to". The TableColumnLayout seems to set the TableColumnLayout only if the parent composite has no layout (which is confusing if you don't know the TableColumnLayout class).

Instead, it should check if the Table is the only control in the parent Composite. If not, it should throw an Exception or be clever and create a Composite internally.
Comment 1 Yang Meyer CLA 2010-02-03 06:24:44 EST
I experienced the same problem because I had another control (Button) in the Table's parent Composite:

public class MyView extends SubModuleView<MyController> {

	@Override
	protected void basicCreatePartControl(Composite parent) {
		GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
		Table table = UIControlsFactory.createTable(parent, SWT.FULL_SELECTION, "myTable");
		GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(parent);
		UIControlsFactory.createButton(parent, "Öffne ausgewählte Adressen", "openButton");
	}
}

The column widths are calculated/set based on the width of the "packed" column (as wide as the button).
Comment 2 Elias Volanakis CLA 2010-02-05 02:14:17 EST
Created attachment 158271 [details]
Snippet

This snippet shows that it works. Details in the next comment.
Comment 3 Elias Volanakis CLA 2010-02-05 02:23:59 EST
ColumnUtils supports several different cases/layouts, including the two you mention:
- FillLayout (*)
- Table is child of a single composite, with no layout -> TableColumnLayout

The problem you experienced can be explained as follows: the only layout that supports resizing the column after the width is set is TableColumnLayout. That has two effects:
- if you don't use TCL and the table has not been layouted yet  (size=0,0), the result won't be what you expect
- if you don't use TCL and the table changes size later (resize, relayout), the column(s) will not resize until you invoke setColumnWidths(...) again

Since we are limited by SWT/JFace, we can only document this in #setColumnWidths.
Comment 4 Ralf Ebert CLA 2010-02-05 04:02:10 EST
Ah, I see, my assumption that a TCL is set automatically was wrong. Wouldn't it be possible to set the TCL / create a Composite automatically in UIControlFactory?
Comment 5 Elias Volanakis CLA 2011-08-03 14:35:12 EDT
Ressigning to default assignee. Not working on Riena right now.
Comment 6 Elias Volanakis CLA 2011-08-03 14:35:16 EDT
Reassigning to default assignee. Not working on Riena right now.
Comment 7 Nobody - feel free to take it CLA 2012-03-13 12:12:41 EDT
Created attachment 212570 [details]
Bug

I slightly modified your attachment to reproduce a bug in:
ColumnUtils.applyColumnWidths(ITableTreeWrapper, ColumnLayoutData[], int)

This behavior can be worked around by including this line in the snippet (which is currently commented out to show the bug):
// table.setLayout(new TableLayout());  // <========= ADDED THIS LINE


The explanation:
When the line is commented out (no layout on the TABLE), the last case in ColumnUtils.applyColumnWidths() is executed - starting with:
} else {
...
}
goes till the method end.

As mentioned, control.getClientArea().width is 0 when the table has not been layouted. Unfortunately this is also the case when the table is in a view and controller combination, that is contributed via the assembly2 extention point.


=== VIEW ====
@Override
protected void basicCreatePartControl(Composite parent) {
	parent.setLayout(new FillLayout());

	Table addresses = UIControlsFactory.createTable(parent, SWT.NONE,
			"addresses");
	addresses.setHeaderVisible(true);
	addresses.setLinesVisible(true);
}

=== CONTROLLER ===
@Override
public void configureRidgets() {
	ITableRidget table = getRidget(ITableRidget.class, "addresses");
	String[] columnPropertyNames = { "name", "street", "zip", "city" };
	String[] columnHeaders = { "Name", "Straße", "PLZ", "Ort" };
	table.bindToModel(addressService, "allAddresses", Address.class,
			columnPropertyNames, columnHeaders);
	table.setColumnWidths(new Object[] { new ColumnWeightData(1),
			new ColumnWeightData(1), new ColumnWeightData(1),
			new ColumnWeightData(1) });

	updateAllRidgetsFromModel();
}
Comment 8 Nobody - feel free to take it CLA 2012-03-26 07:30:57 EDT
Created attachment 213174 [details]
test case for column widths bug
Comment 9 Nobody - feel free to take it CLA 2012-03-26 07:32:33 EDT
Created attachment 213175 [details]
fix

Attached test case and a workaround, that fixes the problem with the column widths.
Comment 10 Nobody - feel free to take it CLA 2012-04-04 10:00:03 EDT
Pushed to GIT