Problem with class listening to different EventLists

classic Classic list List threaded Threaded
3 messages 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);
                }
        }
Reply | Threaded
Open this post in threaded view
|

Re: Problem with class listening to different EventLists

Endre Stølsvik-8
Just a quick reply, possibly w/o any help!

Is your equals-method working for sure?

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:

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);
               }
       }

--
View this message in context: http://old.nabble.com/Problem-with-class-listening-to-different-EventLists-tp26160133p26160133.html
Sent from the GlazedLists - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Problem with class listening to different EventLists

Fabian Zeindl
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

fritzr wrote
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);
                }
        }