|
Re: Row numbering in TableViewer [message #463080 is a reply to message #463079] |
Tue, 06 February 2007 08:23 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
In 3.2 that's not really easy. But in 3.3 it's very simple:
TableViewer viewer = new TableViewer(parent);
TableViewerColumn column = new TableViewerColumn(viewer,SWT.NONE);
column.getColumn().setText("Row");
column.setLabelProvider(new ColumnLabelProvider() {
public void update(ViewerCell cell) {
cell.setText(table.indexOf((TableItem)cell.getItem())+"")
}
});
TableViewerColumn column = new TableViewerColumn(viewer,SWT.NONE);
column.getColumn().setText("Column 1");
....
If you want to know more about the new API you can read my blog at
http://tom-eclipse-dev.blogspot.com/
Tom
Daniel Krügler schrieb:
> Hello,
>
> I noticed that the controller ("content provider") of a TableViewer
> does not allow access to the current row, only access to the column
> is provided. This approach has the disadvantage, that its really hard
> to realize an often occuring user request to provide a static
> line numbering for the table (typically the first column).
>
> Besides the fact, that such a numbering is generic and I would hate to
> add an artifical row number to my model data (such that I would use the
> current element data available from the ITableLabelProvider interface),
> this ansatz would also lead to the problem, that any sorting by the
> table columns would also sort the row numbers, which it shouldn't.
>
> Any ideas how to solve this issue with TableViewer?
>
> Thanks and Greetings from Bremen,
>
> Daniel Krügler
|
|
|
Re: Row numbering in TableViewer [message #463087 is a reply to message #463080] |
Tue, 06 February 2007 12:23 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
One more note for 3.2 you simply need to traverse the table your own
something like:
------------------8<------------------
public void getText(Object element)
// Maybe cache the last index and start searching from there!
for( int i = 0; i < table.getItems(); i++ ) {
if( element.equals(item.getData()) ) {
return table.indexOf(item)+"";
}
}
------------------8<------------------
The problem this might cause is that you'll loose a lot of performance
because you always have to traverse the whole table so you need to think
about other possibilities the best one might be to use a counter and
always reset this counter before refresh(*) is called which you can
easily achieve by subclassing TableViewer and overloading
refresh-methods (those are called internally even when you set a sorted
but this is an implementation detail you can not rely on 100%).
Tom
Tom Schindl schrieb:
> In 3.2 that's not really easy. But in 3.3 it's very simple:
>
> TableViewer viewer = new TableViewer(parent);
> TableViewerColumn column = new TableViewerColumn(viewer,SWT.NONE);
> column.getColumn().setText("Row");
>
> column.setLabelProvider(new ColumnLabelProvider() {
> public void update(ViewerCell cell) {
> cell.setText(table.indexOf((TableItem)cell.getItem())+"")
> }
> });
>
> TableViewerColumn column = new TableViewerColumn(viewer,SWT.NONE);
> column.getColumn().setText("Column 1");
>
> ....
>
> If you want to know more about the new API you can read my blog at
> http://tom-eclipse-dev.blogspot.com/
>
> Tom
>
> Daniel Krügler schrieb:
>> Hello,
>>
>> I noticed that the controller ("content provider") of a TableViewer
>> does not allow access to the current row, only access to the column
>> is provided. This approach has the disadvantage, that its really hard
>> to realize an often occuring user request to provide a static
>> line numbering for the table (typically the first column).
>>
>> Besides the fact, that such a numbering is generic and I would hate to
>> add an artifical row number to my model data (such that I would use the
>> current element data available from the ITableLabelProvider interface),
>> this ansatz would also lead to the problem, that any sorting by the
>> table columns would also sort the row numbers, which it shouldn't.
>>
>> Any ideas how to solve this issue with TableViewer?
>>
>> Thanks and Greetings from Bremen,
>>
>> Daniel Krügler
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03857 seconds