Which approach to use to have ability to hide/delete columns in the table in SWT (in Eclipse plugin in particular)?
So should I
We do that on many of our tables here.
First, we make sure the user does not see what we're doing.
table.setRedraw( false );
Then we remove all columns.
while ( table.getColumnCount() > 0 ) {
table.getColumns()[ 0 ].dispose();
}
And then we add the needed ones.
ArrayList<Column> columns = getShownColumns();
for ( Column column : columns ) {
TableColumn tableColumn = new TableColumn( table, column.getStyle() );
tableColumn.setText( column.getTitle() );
tableColumn.setWidth( column.getWidth() );
}
And finally we let the user see what we did.
table.setRedraw( true );
I'd recreate the table columns each time with the visible columns only. If you use the SWT.VIRTUAL style bit, this will be reasonably fast. Set table.setRedraw(false), remove the data from your Table, dispose all TableColumns, recreate the neccessary ones and set your data again. Then set table.setRedraw(true). This minimizes flickering.
I did all this, it worked fine, the disposal of the TableColumns worked as expected.
Using SWT.VIRTUAL is not for the faint-hearted, though. It implicates a different handling of your Table. You might try without that first, to see if it is fast enough.
Having a table with thousands of columns and only showing a few to the user sounds very strange to me. With the native Table implementations I expect issues with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With