views:

83

answers:

1

Hi,

I use a JTable to display data sourced from a streaming data feed.

Each data point is represented as an object of type X, which has one field of interest, lets call it valueField. My implementation of the TableModel interface has a HashMap of objects X keyed on X.getId().

The users of the GUI are able to change the values using a JSpinner set as the custom editor for each cell in the relevant columns.

However, the value is also dependent on values of X.valueField in other rows.

For example, my table represents 3 objects X1, X2 and X3. Their relation is:

X1.valueField = X2.valueField + X3.valueField

If the user changes X1, one of X2 and X3 is kept constant (depending on business logic), and the other value is changed to keep the relationship consistent. Similarly, the user may also be able to change X2 or X3.

Should I encapsulate the relationship in my implementation of the TableModel, or should I extend my custom table editor to take into account the ways the value can change?

I think both approaches would work, but I am not sure which one is the correct one to take. The documentation from Sun and other forums suggests extending the custom editor to control the value of the field, but it doesn't take into account the relationship of that value with other members of the underlying data model.

Any thoughts much appreciated.

00rush

+2  A: 

I would suggest that if the mods that the users perform are permanent, ie once the mod is made, the backing data is updated - then having the table model maintain the modified data is correct. On the other hand, if there is an edit mode, where the user can work with the data and commit once finished, I would suggest that the editor maintain the mods until such a time as the user triggers the commit process.

akf