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

COVERAGE SUMMARY FOR SOURCE FILE [BoardListModel.java]

nameclass, %method, %block, %line, %
BoardListModel.java100% (6/6)100% (17/17)96%  (291/302)95%  (60/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BoardListModel$BoardComparator100% (1/1)100% (3/3)73%  (16/22)80%  (4/5)
compare (Board, Board): int 100% (1/1)62%  (10/16)75%  (3/4)
BoardListModel$BoardComparator (): void 100% (1/1)100% (3/3)100% (1/1)
BoardListModel$BoardComparator (BoardListModel$1): void 100% (1/1)100% (3/3)100% (1/1)
     
class BoardListModel100% (1/1)100% (6/6)98%  (220/225)96%  (43/45)
boardModified (Board): void 100% (1/1)91%  (30/33)89%  (8/9)
findBoard (int): int 100% (1/1)91%  (21/23)86%  (6/7)
BoardListModel (BoardRepository, IdentityHolder, Channel): void 100% (1/1)100% (137/137)100% (21/21)
access$100 (BoardListModel, Board): void 100% (1/1)100% (4/4)100% (1/1)
access$200 (BoardListModel, int): void 100% (1/1)100% (4/4)100% (1/1)
accountModified (int): void 100% (1/1)100% (24/24)100% (7/7)
     
class BoardListModel$1100% (1/1)100% (2/2)100% (15/15)100% (4/4)
BoardListModel$1 (BoardListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (9/9)100% (3/3)
     
class BoardListModel$2100% (1/1)100% (2/2)100% (12/12)100% (3/3)
BoardListModel$2 (BoardListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (6/6)100% (2/2)
     
class BoardListModel$3100% (1/1)100% (2/2)100% (15/15)100% (3/3)
BoardListModel$3 (BoardListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (9/9)100% (2/2)
     
class BoardListModel$4100% (1/1)100% (2/2)100% (13/13)100% (3/3)
BoardListModel$4 (BoardListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (7/7)100% (2/2)

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.view;
16 
17import java.util.Comparator;
18 
19import net.sourceforge.hiveboard.Board;
20import net.sourceforge.hiveboard.Event;
21import net.sourceforge.hiveboard.EventType;
22import net.sourceforge.hiveboard.event.ConstraintEventFilter;
23import net.sourceforge.hiveboard.event.Constraints;
24import net.sourceforge.hiveboard.event.EventsPriorities;
25import net.sourceforge.hiveboard.event.PersistentDeferredConsumer;
26import net.sourceforge.hiveboard.main.IdentityHolder;
27import net.sourceforge.hiveboard.model.BoardRepository;
28import net.sourceforge.hiveevents.Channel;
29import net.sourceforge.hiveevents.Filter;
30import net.sourceforge.hivegui.table.DefaultDataListModel;
31 
32public class BoardListModel extends DefaultDataListModel<Board>
33{
34        public BoardListModel(        BoardRepository                repository,
35                                                        IdentityHolder                holder,
36                                                        Channel<Event>                eventChannel)
37        {
38                super(Board.class, new BoardComparator());
39                setRows(repository.getBoards());
40                _identity = holder;
41 
42                // Add events listeners
43                int priority = EventsPriorities.BOARD_LIST_UPDATE;
44                String constraint = Constraints.eventType(        EventType.EVT_CREATE_BOARD,
45                                                                                                        EventType.EVT_BOARD_ADD_PARTICIPANT);
46                Filter<Event> filter = new ConstraintEventFilter(constraint);
47                PersistentDeferredConsumer consumer = new PersistentDeferredConsumer()
48                {
49                        @Override protected void pushEvent(Event event)
50                        {
51                                if (event.getBoard() != null)
52                                {
53                                        addRow(event.getBoard());
54                                }
55                        }
56                };
57                eventChannel.registerPushConsumer(priority, filter, consumer);
58 
59                constraint = Constraints.eventType(EventType.EVT_MODIFY_BOARD);
60                filter = new ConstraintEventFilter(constraint);
61                consumer = new PersistentDeferredConsumer()
62                {
63                        @Override protected void pushEvent(Event event)
64                        {
65                                boardModified(event.getBoard());
66                        }
67                };
68                eventChannel.registerPushConsumer(priority, filter, consumer);
69 
70                constraint = Constraints.eventType(EventType.EVT_DESTROY_BOARD) +
71                                         " || (" +
72                                         Constraints.eventTypeWho(
73                                                         _identity.getId(), EventType.EVT_BOARD_DEL_PARTICIPANT) +
74                                         ")";
75                filter = new ConstraintEventFilter(constraint);
76                consumer = new PersistentDeferredConsumer()
77                {
78                        @Override protected void pushEvent(Event event)
79                        {
80                                removeRow(findBoard(event.getWhere()));
81                        }
82                };
83                eventChannel.registerPushConsumer(priority, filter, consumer);
84 
85                constraint = Constraints.eventType(EventType.EVT_MODIFY_ACCOUNT);
86                filter = new ConstraintEventFilter(constraint);
87                consumer = new PersistentDeferredConsumer()
88                {
89                        @Override protected void pushEvent(Event event)
90                        {
91                                accountModified(event.getAccount().getId());
92                        }
93                };
94                eventChannel.registerPushConsumer(priority, filter, consumer);
95        }
96        
97        private void        boardModified(Board board)
98        {
99                if (board.getParticipants().contains(_identity.getId()))
100                {
101                        int index = findBoard(board.getId());
102                        if (index >= 0)
103                        {
104                                // Normal modification on board to which self already participates
105                                // No need to use event.getBoard() which is a temporary object,
106                                // the right board is already updated by BoardRepository, so
107                                // we just need to notify the change to the model
108                                // NB: setRow(getRow()) is ugly but necessary currently because
109                                // it is the only way to make sure that the list is always sorted
110                                setRow(index, getRow(index));
111                        }
112                        else
113                        {
114                                // Modification includes adding self to list of participants
115                                addRow(board);
116                        }
117                }
118                else
119                {
120                        // Modification includes removal of self from participants
121                        removeRow(findBoard(board.getId()));
122                }
123        }
124 
125        private void        accountModified(int account)
126        {
127                int index = 0;
128                for (Board board: _items)
129                {
130                        if (board.getInitiator() == account)
131                        {
132                                fireRowsModified(index, index);
133                        }
134                        index++;
135                }
136        }
137        
138        public int        findBoard(int id)
139        {
140                int index = 0;
141                for (Board board: _items)
142                {
143                        if (board.getId() == id)
144                        {
145                                return index;
146                        }
147                        index++;
148                }
149                return -1;
150        }
151        
152        static private class BoardComparator implements Comparator<Board>
153        {
154                public int        compare(Board b1, Board b2)
155                {
156                        int diff = b1.getName().compareTo(b2.getName());
157                        if (diff != 0)
158                        {
159                                return diff;
160                        }
161                        return b1.getId() - b2.getId();
162                }
163        }
164 
165        final private IdentityHolder        _identity;
166}

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