Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 449da180c18fd67929eb46cd5894542ced8a95bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*****************************************************************************
 * Copyright (c) 2016 CEA LIST and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   CEA LIST - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.types.core.notification;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.papyrus.infra.types.core.notification.events.ITypesEvent;

/**
 * Singleton used to register eventsChains listeners ({@link ITypesEventsChainListener})
 */
public class TypesListenersRegistry {

	private static Set<ITypesEventsChainListener> eventChainListeners = null;

	private static Set<ITypesEventsListener> eventListeners = null;

	private static TypesListenersRegistry instance = null;

	private TypesListenersRegistry() {
	}

	public static synchronized TypesListenersRegistry getInstance() {
		if (instance == null) {
			instance = new TypesListenersRegistry();
			init();
		}
		return instance;
	}

	public static void init() {
		eventChainListeners = new HashSet<ITypesEventsChainListener>();
		eventListeners = new HashSet<ITypesEventsListener>();
	}

	public void addEventChainListener(ITypesEventsChainListener listener) {
		eventChainListeners.add(listener);
	}

	public void removeEventChainListener(ITypesEventsChainListener listener) {
		eventChainListeners.remove(listener);
	}

	public void addEventListener(ITypesEventsListener listener) {
		eventListeners.add(listener);
	}

	public void removeEventChainListener(ITypesEventsListener listener) {
		eventListeners.remove(listener);
	}

	public void notifyChain(TypesEventsChain chain) {
		for (ITypesEventsChainListener eventsChainListener : eventChainListeners) {
			eventsChainListener.notifyChain(chain);
		}
	}

	public void notifyEvent(ITypesEvent event) {
		for (ITypesEventsListener eventsListener : eventListeners) {
			eventsListener.notifyEvent(event);
		}
	}
}

Back to the top