Community
Participate
Working Groups
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.
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).
Created attachment 158271 [details] Snippet This snippet shows that it works. Details in the next comment.
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.
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?
Ressigning to default assignee. Not working on Riena right now.
Reassigning to default assignee. Not working on Riena right now.
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(); }
Created attachment 213174 [details] test case for column widths bug
Created attachment 213175 [details] fix Attached test case and a workaround, that fixes the problem with the column widths.
Pushed to GIT