1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.vaadin.session;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import com.vaadin.ui.UI;
|
16
|
|
17
|
/**
|
18
|
* @author cmathew
|
19
|
* @date 9 Apr 2015
|
20
|
*
|
21
|
*/
|
22
|
public class SelectionService {
|
23
|
|
24
|
public final static String KEY = "key_selectionService";
|
25
|
|
26
|
private final List<ISelectionListener> listeners;
|
27
|
|
28
|
private final List<SelectionEvent> currentEvents;
|
29
|
|
30
|
public SelectionService() {
|
31
|
listeners = new ArrayList<ISelectionListener>();
|
32
|
currentEvents = new ArrayList<SelectionEvent>();
|
33
|
}
|
34
|
|
35
|
public void register(ISelectionListener listener) {
|
36
|
listeners.add(listener);
|
37
|
}
|
38
|
|
39
|
public void addEvent(SelectionEvent event) {
|
40
|
currentEvents.add(event);
|
41
|
}
|
42
|
|
43
|
public void fireCurrentSelectionEvents(boolean async) {
|
44
|
for(SelectionEvent event : currentEvents) {
|
45
|
fireSelectionEvent(event,async);
|
46
|
}
|
47
|
currentEvents.clear();
|
48
|
}
|
49
|
|
50
|
public void fireSelectionEvent(final SelectionEvent event, boolean async) {
|
51
|
for(final ISelectionListener listener : listeners) {
|
52
|
if(async) {
|
53
|
UI.getCurrent().access(new Runnable() {
|
54
|
@Override
|
55
|
public void run() {
|
56
|
listener.onSelect(event);
|
57
|
}
|
58
|
});
|
59
|
} else {
|
60
|
listener.onSelect(event);
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
}
|