| 1 | //  Copyright 2004-2007 Jean-Francois Poilpret | 
| 2 | // | 
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
| 4 | // you may not use this file except in compliance with the License. | 
| 5 | // You may obtain a copy of the License at | 
| 6 | // | 
| 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
| 8 | // | 
| 9 | // Unless required by applicable law or agreed to in writing, software | 
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 12 | // See the License for the specific language governing permissions and | 
| 13 | // limitations under the License. | 
| 14 |   | 
| 15 | package net.sourceforge.hiveboard.view; | 
| 16 |   | 
| 17 | import net.sourceforge.hiveboard.Event; | 
| 18 | import net.sourceforge.hiveboard.EventType; | 
| 19 | import net.sourceforge.hiveboard.event.DeferredConsumer; | 
| 20 | import net.sourceforge.hiveboard.event.EventsPriorities; | 
| 21 | import net.sourceforge.hiveboard.main.IdentityHolder; | 
| 22 | import net.sourceforge.hiveboard.model.BoardRepository; | 
| 23 | import net.sourceforge.hiveevents.Channel; | 
| 24 | import net.sourceforge.hiveevents.Filter; | 
| 25 | import net.sourceforge.hivegui.table.DefaultDataListModel; | 
| 26 |   | 
| 27 | public class NotificationListModel extends DefaultDataListModel<Event> | 
| 28 | { | 
| 29 |         public NotificationListModel(        Channel<Event>                        eventChannel, | 
| 30 |                                                                         final BoardRepository        repository, | 
| 31 |                                                                         IdentityHolder                        holder) | 
| 32 |         { | 
| 33 |                 super(Event.class, new EventComparator()); | 
| 34 |                 final int self = holder.getId(); | 
| 35 |   | 
| 36 |                 // Add events listeners | 
| 37 |                 int priority = EventsPriorities.NOTIFICATION_LIST_UPDATE; | 
| 38 |                 _consumer = new DeferredConsumer() | 
| 39 |                 { | 
| 40 |                         @Override protected void pushEvent(Event event) | 
| 41 |                         { | 
| 42 |                                 addRow(event); | 
| 43 |                         } | 
| 44 |                 }; | 
| 45 |                 Filter<Event> filter = new Filter<Event>() | 
| 46 |                 { | 
| 47 |                         public boolean        passEvent(Event event) | 
| 48 |                         { | 
| 49 |                                 if (        event.getType() == EventType.EVT_GIVE_TOKEN | 
| 50 |                                         &&        event.getWho() == self) | 
| 51 |                                 { | 
| 52 |                                         return true; | 
| 53 |                                 } | 
| 54 |                                 if (        event.getType() == EventType.EVT_REQUEST_TOKEN | 
| 55 |                                         &&        repository.getBoard(event.getWhere()).getInitiator() == self) | 
| 56 |                                 { | 
| 57 |                                         return true; | 
| 58 |                                 } | 
| 59 |                                 return false; | 
| 60 |                         } | 
| 61 |                 }; | 
| 62 |                 eventChannel.registerPushConsumer(priority, filter, _consumer); | 
| 63 |         } | 
| 64 |   | 
| 65 |         private final DeferredConsumer        _consumer; | 
| 66 | } |