EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.util]

COVERAGE SUMMARY FOR SOURCE FILE [AbstractParticipantListModel.java]

nameclass, %method, %block, %line, %
AbstractParticipantListModel.java100% (3/3)100% (10/10)100% (166/166)100% (40/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractParticipantListModel100% (1/1)100% (6/6)100% (127/127)100% (32/32)
AbstractParticipantListModel (Board, AccountRepository): void 100% (1/1)100% (13/13)100% (4/4)
createParticipant (int): Participant 100% (1/1)100% (16/16)100% (4/4)
findParticipant (int): int 100% (1/1)100% (24/24)100% (7/7)
installConsumers (Channel): void 100% (1/1)100% (42/42)100% (7/7)
registerConsumer (Channel, String, DeferredConsumer): void 100% (1/1)100% (12/12)100% (3/3)
updateParticipant (int, boolean): void 100% (1/1)100% (20/20)100% (7/7)
     
class AbstractParticipantListModel$1100% (1/1)100% (2/2)100% (13/13)100% (3/3)
AbstractParticipantListModel$1 (AbstractParticipantListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (7/7)100% (2/2)
     
class AbstractParticipantListModel$2100% (1/1)100% (2/2)100% (26/26)100% (5/5)
AbstractParticipantListModel$2 (AbstractParticipantListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (20/20)100% (4/4)

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 
15package net.sourceforge.hiveboard.util;
16 
17import net.sourceforge.hiveboard.Account;
18import net.sourceforge.hiveboard.Board;
19import net.sourceforge.hiveboard.Event;
20import net.sourceforge.hiveboard.EventType;
21import net.sourceforge.hiveboard.event.ConstraintEventFilter;
22import net.sourceforge.hiveboard.event.Constraints;
23import net.sourceforge.hiveboard.event.DeferredConsumer;
24import net.sourceforge.hiveboard.event.EventsPriorities;
25import net.sourceforge.hiveboard.model.AccountRepository;
26import net.sourceforge.hiveevents.Channel;
27import net.sourceforge.hiveevents.Filter;
28import net.sourceforge.hivegui.table.DefaultDataListModel;
29 
30public abstract class AbstractParticipantListModel extends DefaultDataListModel<Participant>
31{
32        protected AbstractParticipantListModel(Board board, AccountRepository repository)
33        {
34                super(Participant.class, new ParticipantComparator());
35                _repository = repository;
36                _board = board;
37        }
38        
39        protected void        installConsumers(Channel<Event> eventChannel)
40        {
41                String constraint;
42 
43                // account modifications
44                _consumerModifyAccount = new DeferredConsumer()
45                {
46                        @Override protected void pushEvent(Event event)
47                        {
48                                updateParticipant(event.getWho(), true);
49                        }
50                };
51                constraint = Constraints.eventType(EventType.EVT_MODIFY_ACCOUNT);
52                registerConsumer(eventChannel, constraint, _consumerModifyAccount);
53 
54                // writer
55                _consumerGive = new DeferredConsumer()
56                {
57                        @Override protected void pushEvent(Event event)
58                        {
59                                // First update the previous writer
60                                updateParticipant(_writer, false);
61                                // Then set new writer
62                                _writer = event.getWho();
63                                updateParticipant(_writer, false);
64                        }
65                };
66                constraint = Constraints.eventTypeWhere(_board.getId(), EventType.EVT_GIVE_TOKEN);
67                registerConsumer(eventChannel, constraint, _consumerGive);
68        }
69        
70        static protected void        registerConsumer(        Channel<Event>                channel, 
71                                                                                                String                                constraint, 
72                                                                                                DeferredConsumer        consumer)
73        {
74                Filter<Event> filter = new ConstraintEventFilter(constraint);
75                channel.registerPushConsumer(        EventsPriorities.PARTICIPANTS_LIST_UPDATE, 
76                                                                                filter, 
77                                                                                consumer);
78        }
79 
80        protected void        updateParticipant(int who, boolean refresh)
81        {
82                int index = findParticipant(who);
83                if (index >= 0)
84                {
85                        if (refresh)
86                        {
87                                setRow(index, createParticipant(who));
88                        }
89                        else
90                        {
91                                fireRowsModified(index, index);
92                        }
93                }
94        }
95 
96        protected Participant        createParticipant(int id)
97        {
98                Account account = _repository.getAccount(id);
99                if (account == null)
100                {
101                        return null;
102                }
103                else
104                {
105                        return new Participant(account, _board);
106                }
107        }
108        
109        protected int        findParticipant(int id)
110        {
111                int index = 0;
112                for (Participant participant: _items)
113                {
114                        if (participant.getAccount().getId() == id)
115                        {
116                                return index;
117                        }
118                        index++;
119                }
120                return -1;
121        }
122 
123        protected final AccountRepository        _repository;
124        protected final Board                                _board;
125        protected int                                                _writer;
126        protected DeferredConsumer                        _consumerModifyAccount;
127        protected DeferredConsumer                        _consumerGive;
128}

[all classes][net.sourceforge.hiveboard.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov