用EditingSupport构建一个数学矩阵的JFace TableViewer。

时间:2022-06-01 20:34:43

Our application (Eclipse RCP-based, using a JFace/SWT-based interface) needs to support editing of mathematical matrices. The matrices are always square and can be any size from 2x2 to 11x11. Additionally, buttons will be placed on the interface to allow the user to grow or shrink the matrix.

我们的应用程序(基于Eclipse rcp,使用JFace/基于swing的接口)需要支持对数学矩阵的编辑。矩阵总是平方的,可以是任意大小从2x2到11x11。此外,按钮将被放置在界面上,以允许用户增长或缩小矩阵。

We use JFace TableViewers and TreeViewers throughout our code for editing the non-matrix data. If at all possible I'd like to use the same general structure for editing the matrices.

我们在代码中使用JFace tableviewer和treeviewer来编辑非矩阵数据。如果可能的话,我想使用相同的通用结构来编辑矩阵。

I persist the data in the MySQL database using one row per matrix element, as such:

我在MySQL数据库中使用一行每个矩阵元素来保存数据,如下所示:

+----------------------+------------+------+-----+---------+-------+
| Field                | Type       | Null | Key | Default | Extra |
+----------------------+------------+------+-----+---------+-------+
| id                   | bigint(20) | NO   | PRI | NULL    |       |
| rowNum               | bigint(20) | NO   |     | NULL    |       |
| columnNum            | bigint(20) | NO   |     | NULL    |       |
| value                | double     | NO   |     | NULL    |       |
| matrix_id            | bigint(20) | NO   | MUL | NULL    |       |
+----------------------+------------+------+-----+---------+-------+

The problem I'm running into is that the JFace "input" seems to correspond to a single table row in the rendered table. In my case, a single database row corresponds with a cell in the table, not an entire row.

我遇到的问题是JFace“输入”似乎对应于呈现表中的单个表行。在我的例子中,单个数据库行对应的是表中的单元格,而不是整个行。

The only thing I can think of is to somehow store an object behind the scenes that keeps the matrix-ified state and effectively translates database rows into an appropriately JFace-able model. (E.g., if I have a 3x3 matrix, pass in the nine rows into the proxy object and have it call viewer.setInput(Object) with a three-by-three array. This seems like a nightmare to support though, as I'll need to keep this object in sync with both the internal model and the database.

我能想到的唯一一件事就是在后台存储一个对象,它可以保持矩阵化的状态,并有效地将数据库行转换成一个合适的jface模型。(例如,如果我有一个3x3矩阵,在9行中传递到代理对象,并让它调用viewer.setInput(object),它有一个3×3的数组。这看起来像是一个噩梦,因为我需要保持这个对象与内部模型和数据库同步。

Does anyone here have experience with this kind of thing and could possibly lend me some suggestions?

在座有人有过这种经历吗?可以给我一些建议吗?

1 个解决方案

#1


1  

No answers after more than a week, so I ended up rolling my own on this one. I made a class that effectively served as the input for the JFace table which converted the rows and columns of the matrix into a List<List<Double>>; then had the ContentProvider, LabelProvider, and EditingSupport work with that. I was also able to add "Increase size" and "Decrease size" buttons to allow the user to grow or shrink the matrix as necessary.

一个多星期后,我没有得到答案,所以我只好在这个问题上自食其果。我创建了一个类,它有效地用作JFace表的输入,它将矩阵的行和列转换为列表 >;然后有了ContentProvider、LabelProvider和EditingSupport。我还可以添加“增大尺寸”和“减小尺寸”按钮,以允许用户在必要时增加或缩小矩阵。

#1


1  

No answers after more than a week, so I ended up rolling my own on this one. I made a class that effectively served as the input for the JFace table which converted the rows and columns of the matrix into a List<List<Double>>; then had the ContentProvider, LabelProvider, and EditingSupport work with that. I was also able to add "Increase size" and "Decrease size" buttons to allow the user to grow or shrink the matrix as necessary.

一个多星期后,我没有得到答案,所以我只好在这个问题上自食其果。我创建了一个类,它有效地用作JFace表的输入,它将矩阵的行和列转换为列表 >;然后有了ContentProvider、LabelProvider和EditingSupport。我还可以添加“增大尺寸”和“减小尺寸”按钮,以允许用户在必要时增加或缩小矩阵。