|
|
Re: How do I remove columns after I've created TableViewer? [message #550635 is a reply to message #550338] |
Tue, 03 August 2010 23:45 |
Jon Svede Messages: 83 Registered: July 2009 |
Member |
|
|
Thanks! I have tried that, but I have this problem where no matter how I try to remove all the columns, 1 or more remain.
For example, when I do the following:
TableColumn[] columns = table.getColumns() ;
for( TableColumn tc : columns ) {
tc.dispose() ;
I have 1 column left over with no header, just the data. Additionally, from the behavior it appears it starts with the last column and works backwards toward the first (right to left).
When I try this:
int x = table.getColumnCount() ;
for( int y=0 ; y<x; y++ ) {
table.getColumn(y).dispose() ;
}
It gives me an IndexOutOfBoundsException after the second (of four) column. Then if I get the count again, it says there are still two columns left and if I do another loop it will blow up after the first column - and again if I call table.getColumnCount() it says 1 is left, which I can dispose of but still there is 1 column of data visible. Very strange.
Finally, if I do this:
int x = table.getColumnCount() ;
for( int y=x-1; y>-1; y-- ) {
table.getColumn(y).dispose() ;
}
It leaves me with 1 column of data (the first one) with no header.
I thought it might have to do with the indexing starting at 1 instead of 0 but it appears that the columns are zero based, so I don't think this is it either. If I change that last for loop to let y become negative it blows up.
Clearly I am doing something wrong. Any pointers will be gratefully accepted!
|
|
|
Re: How do I remove columns after I've created TableViewer? [message #550719 is a reply to message #550635] |
Wed, 04 August 2010 08:15 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
The problem you have is that a table without a column is a legal construct.
Am 04.08.10 01:45, schrieb Jon Svede:
> Thanks! I have tried that, but I have this problem where no matter how
> I try to remove all the columns, 1 or more remain.
>
> For example, when I do the following:
>
>
> TableColumn[] columns = table.getColumns() ;
>
> for( TableColumn tc : columns ) {
> tc.dispose() ;
>
That's correct.
>
> I have 1 column left over with no header, just the data. Additionally,
> from the behavior it appears it starts with the last column and works
> backwards toward the first (right to left).
>
> When I try this:
>
>
> int x = table.getColumnCount() ;
> for( int y=0 ; y<x; y++ ) {
> table.getColumn(y).dispose() ;
> }
>
If you think about this you should grasp why this is not working and
giving you exceptions, right?
>
> It gives me an IndexOutOfBoundsException after the second (of four)
> column. Then if I get the count again, it says there are still two
> columns left and if I do another loop it will blow up after the first
> column - and again if I call table.getColumnCount() it says 1 is left,
> which I can dispose of but still there is 1 column of data visible.
> Very strange.
>
> Finally, if I do this:
>
>
> int x = table.getColumnCount() ;
> for( int y=x-1; y>-1; y-- ) {
> table.getColumn(y).dispose() ;
> }
>
>
> It leaves me with 1 column of data (the first one) with no header.
>
> I thought it might have to do with the indexing starting at 1 instead of
> 0 but it appears that the columns are zero based, so I don't think this
> is it either. If I change that last for loop to let y become negative
> it blows up.
>
> Clearly I am doing something wrong. Any pointers will be gratefully
> accepted!
You are not - as outlined in my first paragraph a Table without columns
is perfectly legal construct at the very moment you'll add one new
column the single one vanishes.
Beside that as outlined also in my initial response if you are removing
all columns anyways it's a lot better to dispose the complete Table and
recreate it from scratch.
Tom
|
|
|
Re: How do I remove columns after I've created TableViewer? [message #550847 is a reply to message #550719] |
Wed, 04 August 2010 13:46 |
Jon Svede Messages: 83 Registered: July 2009 |
Member |
|
|
Thanks, Tom.
>> int x = table.getColumnCount() ;
>> for( int y=0 ; y<x; y++ ) {
>> table.getColumn(y).dispose() ;
>> }
>>
>If you think about this you should grasp why this is not working and
>giving you exceptions, right?
My conclusion is that the number of columns diminishes while the index of the for loop grows. After disposing 2 columns the loop is looking to get the column at index=2 or column 3 which is beyond the size of the current column array. In all seriousness, thanks for making me think about it rather than just giving it up.
>Beside that as outlined also in my initial response if you are removing
>all columns anyways it's a lot better to dispose the complete Table and
>recreate it from scratch.
I'm obviously being obtuse because I can't seem to make that work (though I like that idea, it's cleaner).
I have an IPartListener listening for the close event from an editor. When I receive that event from the particular editor, I've tried the following:
tableViewer.getTable().dispose() ; // this causes issues
Instead, I've tried this:
Table table = tableViewer.getTable() ;
table.dispose() ;
table = new Table( tableViewer.getControl().getParent(), SWT.NONE) ;
That doesn't work, but I think that it's related to the getControl() call since the underlying control has been disposed.
I've also tried caching the original Composite as a member variable and using it to re-create the TableViewer, but that doesn't seem to work either (though it doesn't throw any exceptions).
Any suggestions?
Thanks,
Jon
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03986 seconds