开发者

Constructing a JFace TableViewer with EditingSupport for a mathematical matrix

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.

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.

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

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

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.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜