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 java.awt.BorderLayout; |
18 | |
19 | import javax.swing.JPanel; |
20 | import javax.swing.JScrollPane; |
21 | |
22 | import net.sourceforge.hiveboard.Board; |
23 | import net.sourceforge.hiveboard.docking.Views; |
24 | import net.sourceforge.hiveboard.event.EventsPriorities; |
25 | import net.sourceforge.hiveboard.util.Participant; |
26 | import net.sourceforge.hiveevents.Channel; |
27 | import net.sourceforge.hiveevents.PersistentConsumer; |
28 | import net.sourceforge.hivegui.table.BeanTable; |
29 | import net.sourceforge.hivegui.table.DataListModel; |
30 | import net.sourceforge.hiveutils.service.ObjectBuilder; |
31 | |
32 | public class ParticipantListPanel extends JPanel |
33 | { |
34 | public ParticipantListPanel(ObjectBuilder builder, |
35 | Channel<Board> selectedBoardChannel, |
36 | BeanTable<Participant> tblParticipants) |
37 | { |
38 | setLayout(new BorderLayout()); |
39 | _builder = builder; |
40 | _tblParticipants = tblParticipants; |
41 | _tblParticipants.setName(Views.PARTICIPANTS_LIST.id() + "-table"); |
42 | _emptyModel = _tblParticipants.getDataListModel(); |
43 | _participantsModel = _emptyModel; |
44 | |
45 | // Listen to changes in the current Selected Board (not necessarily drawing) |
46 | int priority = EventsPriorities.SELECTED_BOARD_GUI_REFRESH; |
47 | selectedBoardChannel.registerPushConsumer(priority, new PersistentConsumer<Board>() |
48 | { |
49 | public void push(Board board) |
50 | { |
51 | updateModel(board); |
52 | } |
53 | }); |
54 | |
55 | add(new JScrollPane(_tblParticipants), BorderLayout.CENTER); |
56 | } |
57 | |
58 | private void updateModel(Board board) |
59 | { |
60 | if (_board == board) |
61 | { |
62 | return; |
63 | } |
64 | _board = board; |
65 | if (board != null) |
66 | { |
67 | _participantsModel = _builder.create("ParticipantListModel", _board); |
68 | } |
69 | else |
70 | { |
71 | _participantsModel = _emptyModel; |
72 | } |
73 | _tblParticipants.setDataListModel(_participantsModel); |
74 | } |
75 | |
76 | final private ObjectBuilder _builder; |
77 | final private BeanTable<Participant> _tblParticipants; |
78 | final private DataListModel<Participant> _emptyModel; |
79 | private DataListModel<Participant> _participantsModel; |
80 | private Board _board = null; |
81 | } |