views:

30

answers:

1

I have 3 ArrayLists and a JTable.
I would like to be able to add/edit/remove elements from the selected (from one of the 3) ArrayList by selecting the elements in the JTable and for example clicking on a button.

I have this code for using only one ArrayList:

/* ... */
EventList<MyClass> eventList = GlazedLists.eventList(myFirstArrayList);
SortedList<MyClass> sortedList = new SortedList<MyClass>(eventList, null);
filterList = new FilterList<MyClass>(sortedList);
EventTableModel<MyClass> listModel = new EventTableModel<MyClass>(filterList,
        myTableFormat);
table.setModel(listModel);
TableComparatorChooser.install(table, sortedList,
        AbstractTableComparatorChooser.MULTIPLE_COLUMN_MOUSE);
selectionModel = new EventSelectionModel<MyClass>(filterList);
table.setSelectionModel(selectionModel);
/* ... */

How could I change the source of the EventList or the FilterList to the 2. or the 3. ArrayList so if I edit the EventList it will modify the source ArrayList too?

A: 

As far as I know, Glazed Lists will not handle propagating changes in your event lists back to your underlying ArrayLists. In fact, in your example your event list and array list are not linked in any way -- the event list just contains all the same items as the array list. See the javadoc for the GlazedLists.eventList static helper here

What you probably want to do is install a listener on your event list and propagate any changes to your array list. Also make sure that you manipulate the event list in response to GUI deletion events. If you modify the filter list the events won't propagate backwards to the event list.

Andy