如何访问已附加到 TableViewer 的 TableEditor 或 EditingSupport?
我目前正在开发一个应用程序,该应用程序在多个位置使用 TableViewer 来显示格式化的表格数据。每个表必须具有导出功能,将其所有内容导出到 Excel 文件中。
为了避免不必要的代码重复,我认为依赖 SWT 的查看器框架并使用它通过注册的标签提供程序获取格式化的表格数据会很好。
这种方法适用于标准只读表,无论是表级还是列级标签提供程序。但是,当在桌子上设置 EditingSupport 或 TableEditors 时,我陷入困境。
在这种情况下,我们经常让标签提供程序返回空白值,并让 TableViewer 处理 EditingSupport 或 TableEditor 以获取单元格数据的表示形式。
有什么方法可以让我访问已附加到 TableViewer 的 TableEditor 或 EditingSupport (无需保留对所述对象的单独引用),以便我可以使用它们来检索单元格数据的正确表示形式?
使用 EditingSupport 处理列,但如果我们不必这样做,那就太好了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法找到从 TableViewer 检索 EditingSupport 或 TableEditor 对象的方法。我们单独存储 EditingSupport 对象供我们使用,但听起来这不适合您,因此您可以将给定列的 EditingSupport 对象存储在列本身的数据映射中。类似于:
这使您可以通过对 TableViewer 的单个引用来访问 EditingSupport 对象,当您想要检索它们时,您可以执行以下操作
:正如你所说,但如果你选择不这样做,这是一个选择。显然,如果您有权访问表或列列表,您可以绕过检索中的一些混乱,但核心思想保持不变。
There is no way, that I can find, to retrieve the EditingSupport or TableEditor objects from a TableViewer. We Store the EditingSupport objects separately for our uses but it sounds like this is not an option for you so you could store the EditingSupport object for a given column in the data map of the column itself. Something like:
This gives you access to the EditingSupport objects through a single reference to the TableViewer and when you wanted to retrieve them you could do something like:
Its fairly ugly and hacky and, depending on your circumstances, I would probably suggest rewriting the LabelProviders as you said but if you choose not to do that, this is an option. Obviously if you have access to either the table or the list of columns you can bypass some of the mess in retrieval but the core idea remains unchanged.