EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hivegui.table]

COVERAGE SUMMARY FOR SOURCE FILE [TableSelectionHandler.java]

nameclass, %method, %block, %line, %
TableSelectionHandler.java0%   (0/4)0%   (0/15)0%   (0/231)0%   (0/50)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TableSelectionHandler0%   (0/1)0%   (0/8)0%   (0/99)0%   (0/27)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/1)
TableSelectionHandler (BeanTable, TableContribution): void 0%   (0/1)0%   (0/31)0%   (0/9)
access$200 (TableSelectionHandler): BeanTable 0%   (0/1)0%   (0/3)0%   (0/1)
access$300 (TableSelectionHandler): Channel 0%   (0/1)0%   (0/3)0%   (0/1)
access$400 (): Object [] 0%   (0/1)0%   (0/2)0%   (0/1)
addSelectionConsumer (int, Consumer): void 0%   (0/1)0%   (0/9)0%   (0/3)
createSelectionChannel (): void 0%   (0/1)0%   (0/16)0%   (0/4)
initSelectionChannel (): void 0%   (0/1)0%   (0/31)0%   (0/9)
     
class TableSelectionHandler$10%   (0/1)0%   (0/1)0%   (0/26)0%   (0/1)
<static initializer> 0%   (0/1)0%   (0/26)0%   (0/1)
     
class TableSelectionHandler$MultipleSelectionListener0%   (0/1)0%   (0/3)0%   (0/63)0%   (0/13)
TableSelectionHandler$MultipleSelectionListener (TableSelectionHandler): void 0%   (0/1)0%   (0/10)0%   (0/2)
TableSelectionHandler$MultipleSelectionListener (TableSelectionHandler, Table... 0%   (0/1)0%   (0/4)0%   (0/1)
valueChanged (ListSelectionEvent): void 0%   (0/1)0%   (0/49)0%   (0/11)
     
class TableSelectionHandler$SingleSelectionListener0%   (0/1)0%   (0/3)0%   (0/43)0%   (0/10)
TableSelectionHandler$SingleSelectionListener (TableSelectionHandler): void 0%   (0/1)0%   (0/9)0%   (0/2)
TableSelectionHandler$SingleSelectionListener (TableSelectionHandler, TableSe... 0%   (0/1)0%   (0/4)0%   (0/1)
valueChanged (ListSelectionEvent): void 0%   (0/1)0%   (0/30)0%   (0/8)

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.hivegui.table;
16 
17import java.util.Arrays;
18 
19import javax.swing.event.ListSelectionEvent;
20import javax.swing.event.ListSelectionListener;
21 
22import net.sourceforge.hiveevents.Channel;
23import net.sourceforge.hiveevents.ChannelImpl;
24import net.sourceforge.hiveevents.Consumer;
25 
26/**
27 * @author Jean-Francois Poilpret
28 */
29public class TableSelectionHandler<T>
30{
31        public TableSelectionHandler(BeanTable<T> table, TableContribution contrib)
32        {
33                _table = table;
34                _beanClass = _table.getDataListModel().getRowClass();
35                _selectionMode = contrib.getSelectionMode();
36                _table.setSelectionMode(_selectionMode.value());
37                _selection = contrib.getSelectionEvent();
38                if (_selection != null)
39                {
40                        initSelectionChannel();
41                }
42        }
43        
44        @SuppressWarnings("unchecked")
45        public void        addSelectionConsumer(int priority, Consumer consumer)
46        {
47                createSelectionChannel();
48                _selection.registerPushConsumer(priority, consumer);
49        }
50        
51        @SuppressWarnings("unchecked")
52        private void        createSelectionChannel()
53        {
54                if (_selection == null)
55                {
56                        _selection = new ChannelImpl(        "BeanTable.SelectionChannel",
57                                                                                        Integer.MAX_VALUE,
58                                                                                        _beanClass,
59                                                                                        false);
60                        initSelectionChannel();
61                }
62        }
63        
64        private void        initSelectionChannel()
65        {
66                if (_selection != null)
67                {
68                        ListSelectionListener listener = null;
69                        switch (_selectionMode)
70                        {
71                                case Single:
72                                listener = new SingleSelectionListener();
73                                break;
74 
75                                case Interval:
76                                case Multiple:
77                                listener = new MultipleSelectionListener();
78                                break;
79                                
80                                default:
81                                // No other possible value
82                                break;
83                        }
84                        _table.getSelectionModel().addListSelectionListener(listener);
85                }
86        }
87        
88        private class SingleSelectionListener implements ListSelectionListener
89        {
90                @SuppressWarnings("unchecked")
91                public void        valueChanged(ListSelectionEvent e)
92                {
93                        int selected = _table.getSelectedRow();
94                        if (selected != _lastSelection)
95                        {
96                                Object row = null;
97                                if (selected > -1)
98                                {
99                                        row = _table.getDataListModel().getRow(selected);
100                                }
101                                _lastSelection = selected;
102                                _selection.push(row);
103                        }
104                }
105                
106                private int        _lastSelection = -1;
107        }
108        
109        private class MultipleSelectionListener implements ListSelectionListener
110        {
111                @SuppressWarnings("unchecked")
112                public void        valueChanged(ListSelectionEvent e)
113                {
114                        int[] selected = _table.getSelectedRows();
115                        if (!Arrays.equals(selected, _lastSelection))
116                        {
117                                Object[] rows = EMPTY;
118                                if (selected.length > 0)
119                                {
120                                        DataListModel<T> model = _table.getDataListModel();
121                                        rows = new Object[selected.length];
122                                        for (int i = 0; i < selected.length; i++)
123                                        {
124                                                rows[i] = model.getRow(selected[i]);
125                                        }
126                                }
127                                _lastSelection = selected;
128                                _selection.push(rows);
129                        }
130                }
131 
132                private int[]        _lastSelection = new int[0];
133        }
134        
135        private Channel                                        _selection;
136        private final Class<T>                        _beanClass;
137        private final SelectionMode                _selectionMode;
138        private final BeanTable<T>                _table;
139 
140        static final private Object[]        EMPTY = new Object[0];
141}

[all classes][net.sourceforge.hivegui.table]
EMMA 2.0.5312 (C) Vladimir Roubtsov