1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.event;
20
21 import net.sf.jameleon.data.DataDrivable;
22
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.LinkedList;
27 import java.util.List;
28
29 public class DataDrivableEventHandler{
30
31 private static DataDrivableEventHandler eventHandler;
32 private final List dataDrivableListeners = Collections.synchronizedList(new LinkedList());
33
34 private DataDrivableEventHandler(){}
35
36 public static DataDrivableEventHandler getInstance(){
37 if (eventHandler == null) {
38 eventHandler = new DataDrivableEventHandler();
39 }
40 return eventHandler;
41 }
42
43 public void clearInstance(){
44 eventHandler = null;
45 }
46
47 public void addDataDrivableListener(DataDrivableListener ddl){
48 if (ddl != null && !dataDrivableListeners.contains(ddl)){
49 dataDrivableListeners.add(ddl);
50 }
51 }
52
53 public List getDataDrivableListeners(){
54 return dataDrivableListeners;
55 }
56
57 public void removeDataDrivableListener(DataDrivableListener ddl){
58 dataDrivableListeners.remove(ddl);
59 }
60
61 public void openEvent(DataDrivable dd){
62 DataDrivableEvent dde = new DataDrivableEvent(dd);
63 synchronized(dataDrivableListeners){
64 Iterator it = dataDrivableListeners.iterator();
65 DataDrivableListener ddl;
66 while (it.hasNext()) {
67 ddl = (DataDrivableListener)it.next();
68 ddl.openEvent(dde);
69 }
70 }
71 }
72
73 public void closeEvent(DataDrivable dd){
74 DataDrivableEvent dde = new DataDrivableEvent(dd);
75 synchronized(dataDrivableListeners){
76 Iterator it = dataDrivableListeners.iterator();
77 DataDrivableListener ddl;
78 while (it.hasNext()) {
79 ddl = (DataDrivableListener)it.next();
80 ddl.closeEvent(dde);
81 }
82 }
83 }
84
85 public void executeRowEvent(Map vars, DataDrivable dd, int rowNum){
86 DataDrivableEvent dde = new DataDrivableEvent(dd);
87 dde.setRowData(vars);
88 synchronized(dataDrivableListeners){
89 Iterator it = dataDrivableListeners.iterator();
90 DataDrivableListener ddl;
91 while (it.hasNext()) {
92 ddl = (DataDrivableListener)it.next();
93 ddl.executeRowEvent(dde, rowNum);
94 }
95 }
96 }
97
98 }