"ITableLabelProvider " interface has given two methods to implement out label provider, one of the methods is

     public String getColumnText(Object element, int columnIndex);

in this method element represents one entire row, based on the column index we will get data and set to table.

My requirement is , I want a method such that element represents one column, so based on column index I can access data.

有帮助吗?

解决方案

At the moment there is no label provider, which would provide element, representing just a column (even cell). It is actually quite logical, if you think about it. So, you should rely on column index to fetch the data (for example, having a switch by column index).

Another possibility would be to do it like this:

TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
tableViewerColumn.getColumn().setText("Column");
tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {
    @Override
    public String getText(Object element) {
        return ((RowRepresentingObject) element).getColumnValue();
    }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top