Problem with class listening to different EventLists

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problem with class listening to different EventLists

fritzr
Hi together,
I've got a component which must listen to different eventLists.
It is not possible to implement the ListEventListener typed via generics interface more than once.
Therefore I added just one method (without generics), ask the event for the eventListSource, compare it to the different eventLists and call specific methods which handle the specific events.

If my if-clause says that the eventListSource is the eventList A than I call handleAEvent(...) method. In this method I try to retrieve the object either via event.getOldObject or via getIndex and get(index). My problem is, that sometimes i get objects of other lists...

Is my problem described clearly? Can anyone help me?
Here a code snipped...

dataManager.getFsrs().addListEventListener(this);
dataManager.getFsrFunctions().addListEventListener(this);
dataManager.getElements().addListEventListener(this);
...

public void listChanged(ListEvent event) {
                //Iterate through all list changes
                while (event.hasNext()) {
                        event.next(); //get the next change event
                        if (event.getSourceList().equals(dataManager.getListA())){
                                handleFsrListEvent(event);
                        }else if (event.getSource().equals(dataManager.getListB())){
                                handleFsrFunctionListEvent(event);
                        }else if (event.getSource().equals(dataManager.getListC())){
                                handleElementListEvent(event);
                        }
                }
        }

...

        private void handleFunctionListEvent(ListEvent<Function> event) {
                if (event.getType() == ListEvent.INSERT){
                        Function function = event.getSourceList().get(event.getIndex());
                        ElementRow<Function> functionRow = new ElementRow<Function>(function);
                        ElementRow parentRow = findRow(function.getElement());
                        addRow(parentRow, functionRow);
                } else if (event.getType() == ListEvent.DELETE){
                        Function function = event.getOldValue();
                        //SOMETIMES HERE I GOT OTHER VALUES THAN FUNCTIONS...
                        Row row = findRow(function);
                        removeRow(row);
                }
        }