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); } } |
Just a quick reply, possibly w/o any help! You could user inner classes for the problem you have, instead of doing this more hackish "routing"-stuff you do. Either anonymous classes, like directly in the code do 'new ListEventListener<Type>() { .. body ..}', or make inner classes (possibly "non-static", so that they have direct access to the enclosing class).
Kind regards, Endre. On Tue, Nov 3, 2009 at 14:55, fritzr <[hidden email]> wrote:
|
In reply to this post by fritzr
What are you trying to do? I think you have to refactor at some greater scope in your code.
Can't you divide the Handlers for the ListEvents in different classes? fabian
|
Free forum by Nabble | Edit this page |