Home » Eclipse Projects » NatTable » column width
column width [message #902647] |
Thu, 16 August 2012 12:41  |
Eclipse User |
|
|
|
Hi,
I wonder how can I set the column width to autosize for all columns. Same what happen when double
clicking the header.
On the other hand how can I set the width column specific? I know I can set the default width in the
constructor of DataLayer but this applies to all columns. But I want the first 2 columns larger than
the rest of the table.
looking forward to any hints, Martin
|
|
| | | | |
Re: column width [message #946318 is a reply to message #902647] |
Tue, 16 October 2012 01:31   |
Eclipse User |
|
|
|
I noticed that the virtual nature of the table kind of gets in the way, so I had to leave this paint listener enabled. This works for me,but I wonder whether the calls will scale well. You add it as you add the other OverlayPainters in the examples. I'll take a look at the faq now...
import java.util.HashSet;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter;
import org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand;
import org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeRowsCommand;
import org.eclipse.nebula.widgets.nattable.util.GCFactory;
import org.eclipse.swt.graphics.GC;
public class ResizeOverlayPainter implements IOverlayPainter {
private NatTable table;
private HashSet<Integer> rowset;
private HashSet<Integer> colset;
ResizeOverlayPainter(NatTable tb){
table = tb;
rowset = new HashSet<Integer>(100);
colset = new HashSet<Integer>(100);
}
@Override
public synchronized void paintOverlay(GC gc, ILayer layer) {
int count = table.getColumnCount();
for (int i=0; i<count; i++) {
if (table.isColumnPositionResizable(i)==false){
continue;
}
int pos = table.getColumnIndexByPosition(i);
if (colset.contains(pos)) continue;
colset.add(pos);
InitializeAutoResizeColumnsCommand columnCommand = new InitializeAutoResizeColumnsCommand(
table, i, table.getConfigRegistry(), new GCFactory(table));
table.doCommand(columnCommand);
}
count = table.getRowCount();
for (int i=0; i<count; i++) {
if (table.isRowPositionResizable(i)==false){
continue;
}
int pos = table.getRowIndexByPosition(i);
if (rowset.contains(pos)) continue;
rowset.add(pos);
InitializeAutoResizeRowsCommand rowCommand = new InitializeAutoResizeRowsCommand(
table, i, table.getConfigRegistry(), new GCFactory(table));
table.doCommand(rowCommand);
}
}
}
|
|
| |
Re: column width [message #946893 is a reply to message #946425] |
Tue, 16 October 2012 11:59   |
Eclipse User |
|
|
|
ok for using it in the faq. I added your faq example code to the Big_data example and found a couple of problems ...
1. in your example you'd need to change natTable to final.
2. in your example you'd need to remove the override.
Then it builds ok.
The big_data example runs then, but is fairly unresponsive. I believe the time is being spent in getPreferredColumnWidth, which doesn't scale. It appears to look at all rows during execution of InitializeAutoResizeColumnsCommand, rather than just at the the viewed rows. A version of these which only considered the viewed cells might be more responsive. It currently takes on the order of 30 secs per column to resize.
The getPreferedRowHeights is doing the same, but the Big_data example only has 500 rows, and so its problems don't show up in my current test. But if I change the test to 10K rows and 10K columns I see even worse responsiveness due to getPreferedRowHeights calculation relative to getPreferredColumnWidth. So probably should have a more responsive version of both of these for large virtual tables, limiting to just the viewed columns and rows for the resize preferred heights and widths.
private static int getPreferredColumnWidth(ILayer layer, int columnPosition, IConfigRegistry configRegistry, GC gc) {
ICellPainter painter;
int maxWidth = 0;
ILayerCell cell;
for (int rowPosition = 0; rowPosition < layer.getRowCount(); rowPosition++) {
[Updated on: Tue, 16 October 2012 12:55] by Moderator
|
|
| |
Re: column width [message #947058 is a reply to message #941791] |
Tue, 16 October 2012 15:25   |
Eclipse User |
|
|
|
I tried your cellPainter example from the faq and added this code to the Big_data example. This works very much faster than the IOverlayPainter example that I experimented with. However, updates lag increasingly as you scroll to the right, and it seems to be related to the number of table columns. For example, if you change the Big_data example to have 1 Million rows and 1 Million columns, then scroll to the middle of the range on both horizontal and vertical, then scroll down single step takes on the order of 10 secs and scroll to right take on order of 5 secs. If you scroll to end of range on both, then scoll single step left takes about 11 seconds, and scroll single step up takes about 15 sec.
At the top of range on both bars, scroll single step down occurs immediately, scroll singe step right occurs immediately. So there is likely some code buried in there that is processing the whole table dimensions rather than just the viewed port.
final NatTable natTable = new NatTable(parent,layer,false);
ConfigRegistry configRegistry = new ConfigRegistry();
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
cellPainter = new LineBorderDecorator(
new TextPainter(false, true, 5, true));
}
});
natTable.configure();
|
|
| | |
Re: column width [message #948131 is a reply to message #947018] |
Wed, 17 October 2012 15:48   |
Eclipse User |
|
|
|
Another place where InitializeAutoResizeColumnsCommand is causing a problem:
The Big_Data example has a million rows, and has an AutoResizeColumnAction action bound to the header in DefaultColumnResizeBindings. That action calls InitializeAutoResizeColumnsCommand, which makes the example hang while it looks at all the rows if you happen to double click on one of the column header separators.
A reasonable fix might be to limit the range of the rows inspected to the view or to some reasonable sized range that includes the view.
DefaultColumnResizeBindings
uiBindingRegistry.registerDoubleClickBinding(new ColumnResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1), new AutoResizeColumnAction());
InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(natTable, column, natTable.getConfigRegistry(), new GCFactory(natTable));
The problem is because MaxCellBoundsHelper.getPreferedColumnWidths looks at all rows, which appears to hang on this million row example.
|
|
| | | |
Re: column width [message #1712658 is a reply to message #948583] |
Tue, 27 October 2015 05:32  |
Eclipse User |
|
|
|
Hello everyone,
If anyone is still concerned about this, It propably isn't related fully to this topic but very alike. The solution I propose in here is mostly describing the topic mentioned by Jose in here http://sourceforge.net/p/nattable/discussion/744994/thread/f94a6b96/ . I was inspired but what she proposed as a solution to find mine. Anyway, this is what I did:
In my class BodyLayerStack, I define the width percentage of each of my columns (of course making sure that the sum is 100%) and I have 3 columns in my nattable:
bodyDataLayer = new DataLayer(this.bodyDataProvider);
bodyDataLayer.setColumnPercentageSizing(true);
bodyDataLayer.setColumnWidthPercentageByPosition(0, 30);
bodyDataLayer.setColumnWidthPercentageByPosition(1, 30);
bodyDataLayer.setColumnWidthPercentageByPosition(2, 40);
Of course make sure that your table with is the same as its parent (if you want your nattable to have this size of course)
add this after you have defined you natTable, just after the natTable.configure() (it needs to be the last thing you do when creating your table)
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
return natTable;
I hope this will help others.
Best regards,
Ines
|
|
|
Goto Forum:
Current Time: Wed Jul 02 18:47:28 EDT 2025
Powered by FUDForum. Page generated in 0.05913 seconds
|