01: /*
02: * EventNotifier.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import java.util.LinkedList;
15: import java.util.List;
16: import workbench.interfaces.EventDisplay;
17:
18: /**
19: *
20: * @author support@sql-workbench.net
21: */
22: public class EventNotifier {
23: private List<EventDisplay> displayClients = new LinkedList<EventDisplay>();
24: private NotifierEvent lastEvent = null;
25: private static EventNotifier instance = new EventNotifier();
26:
27: private EventNotifier() {
28: }
29:
30: public static EventNotifier getInstance() {
31: return instance;
32: }
33:
34: public synchronized void addEventDisplay(EventDisplay d) {
35: displayClients.add(d);
36: if (this .lastEvent != null) {
37: d.showAlert(lastEvent);
38: }
39: }
40:
41: public synchronized void removeEventDisplay(EventDisplay d) {
42: displayClients.remove(d);
43: }
44:
45: public synchronized void displayNotification(NotifierEvent e) {
46: this .lastEvent = e;
47: for (EventDisplay d : displayClients) {
48: d.showAlert(e);
49: }
50: }
51:
52: public synchronized void removeNotification() {
53: for (EventDisplay d : displayClients) {
54: d.removeAlert();
55: }
56: }
57:
58: }
|