Question

"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.

Était-ce utile?

La solution

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();
    }
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top