0

I am currently working on an application that uses a TableViewer in several places to display formatted tabular data. Each table must have an export feature where all its content is exported in an Excel file.

In order to avoid unnecessery code duplication, I thought it would be nice to rely upon the viewer framework of SWT and use it to get the formatted tabular data using the registered label providers.

This approach works well with standard read-only tables, either with table-level and column-level label providers. However, I am stuck when an EditingSupport or TableEditors have been set on the table.

In such cases, we often had label providers to return blank values and let the TableViewer deal with the EditingSupport or the TableEditor to get the representation of the cell data.

Is there any way for me to access a TableEditor or an EditingSupport that has been attached to a TableViewer (without keeping a separate reference to said objects) so I can use them to retrieve a proper representation of the cell data ?

If not, we will probably rewrite our label providers so that they handle columns with EditingSupport as well, but it would be nice if we did not have to.

4

1 回答 1

1

我找不到从 TableViewer 中检索 EditingSupport 或 TableEditor 对象的方法。我们单独存储 EditingSupport 对象以供我们使用,但听起来这不是您的选择,因此您可以将给定列的 EditingSupport 对象存储在列本身的数据映射中。就像是:

TableColumn column = new TableColumn(table, SWT.RIGHT);
EditingSupport editingSupport = new TableEditingSupport();
column.setData("editing_support", editingSupport);

这使您可以通过对 TableViewer 的单个引用访问 EditingSupport 对象,当您想要检索它们时,您可以执行以下操作:

final Table table = tableViewer.getTable();
for(TableColumn column : table.getColumns())
{
    EditingSupport editingSupport = (EditingSupport)column.getData("editing_support");
}

它相当丑陋和hacky,根据您的情况,我可能会建议您按照您的说法重写LabelProviders,但如果您选择不这样做,这是一个选择。显然,如果您可以访问表或列列表,则可以绕过检索中的一些混乱,但核心思想保持不变。

于 2010-04-02T17:25:14.497 回答