B
Brian J. Sayatovic
I've found nearly every reference to sorting tablesin Java to be one
of two things: (1) using the delegating model presentign in the Swing
Tutorial or (2) sorting the actual data in the actual model.
Because a model is a model of data, it is not unexpected that one
would use their own custom model that more accurately represents their
data. This is the approach I'm taking. Thus, my model represents a
List of objects. Each row represents an object,and each c olumn in
the row represents the obejct's value for a certain property (i.e.
name, date, color, etc.).
When the system needs to delete one of those objects, I delete it from
the list in my model and fire a table model change event indiciating a
deleted row.
However, I think I'm encountering a problem when I wrap my model in a
SortableTableModel. The problem is that the deleted row could be
mapped through the sorted table model wrapper. Thus, if I delete
object 2 (located in row 2 in the real data model), the event fired
will be that row 2 was deleted. However, from the point of view of
the JTable, it may have been row 1 that was deleted (assuming teh
sortable table model had sorted such that row 2 was in the first row).
I don't believe Sun's example handles this. Perhaps they expect all
changes to the data model to happen through the model's
setValueAt(y,x) method. But in my case, the objects in the model
could be edited in another dialog, and when OK is pressed, I want the
changes reflected in the JTable representing the list of all objects.
So, the changes would not go through the sortable table model at all,
but rather, through the acutal underlying data model.
I'm guessing the solution is to intercept the table model change
events with a listener designed to re-map the row indices in the event
(which may have to be more than 1 event once mapped if the re-sorted
indices are not contiguous). But I'm concerned that I may be going
down the wrong path if Su themselves didn't forsee this for their
example.
Thoughts?
Regards,
Brian.
of two things: (1) using the delegating model presentign in the Swing
Tutorial or (2) sorting the actual data in the actual model.
Because a model is a model of data, it is not unexpected that one
would use their own custom model that more accurately represents their
data. This is the approach I'm taking. Thus, my model represents a
List of objects. Each row represents an object,and each c olumn in
the row represents the obejct's value for a certain property (i.e.
name, date, color, etc.).
When the system needs to delete one of those objects, I delete it from
the list in my model and fire a table model change event indiciating a
deleted row.
However, I think I'm encountering a problem when I wrap my model in a
SortableTableModel. The problem is that the deleted row could be
mapped through the sorted table model wrapper. Thus, if I delete
object 2 (located in row 2 in the real data model), the event fired
will be that row 2 was deleted. However, from the point of view of
the JTable, it may have been row 1 that was deleted (assuming teh
sortable table model had sorted such that row 2 was in the first row).
I don't believe Sun's example handles this. Perhaps they expect all
changes to the data model to happen through the model's
setValueAt(y,x) method. But in my case, the objects in the model
could be edited in another dialog, and when OK is pressed, I want the
changes reflected in the JTable representing the list of all objects.
So, the changes would not go through the sortable table model at all,
but rather, through the acutal underlying data model.
I'm guessing the solution is to intercept the table model change
events with a listener designed to re-map the row indices in the event
(which may have to be more than 1 event once mapped if the re-sorted
indices are not contiguous). But I'm concerned that I may be going
down the wrong path if Su themselves didn't forsee this for their
example.
Thoughts?
Regards,
Brian.