1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.vaadin.ui.navigation;
|
10
|
|
11
|
import java.util.HashMap;
|
12
|
import java.util.Map;
|
13
|
|
14
|
import com.vaadin.ui.Field;
|
15
|
import com.vaadin.ui.Window;
|
16
|
|
17
|
import eu.etaxonomy.vaadin.mvp.ApplicationView;
|
18
|
import eu.etaxonomy.vaadin.ui.view.PopupView;
|
19
|
|
20
|
/**
|
21
|
* @author a.kohlbecker
|
22
|
* @since May 16, 2018
|
23
|
*
|
24
|
*/
|
25
|
public class PopupViewRegistration {
|
26
|
|
27
|
private Map<PopupView, Window> popupWindowMap = new HashMap<>();
|
28
|
|
29
|
private Map<ApplicationView<?>, Map<PopupView, Field<?>>> popupViewFieldMap = new HashMap<>();
|
30
|
|
31
|
/**
|
32
|
* @param view
|
33
|
* @param popup
|
34
|
* @param field can be <code>null</code>
|
35
|
* @return the previous Field associated with the popup that has been opened in the view
|
36
|
*/
|
37
|
public Field<?> put(Window window, ApplicationView parentView, PopupView popup, Field<?> field){
|
38
|
|
39
|
popupWindowMap.put(popup, window);
|
40
|
|
41
|
|
42
|
if(!popupViewFieldMap.containsKey(parentView)){
|
43
|
popupViewFieldMap.put(parentView, new HashMap<>());
|
44
|
}
|
45
|
Map<PopupView, Field<?>> popupFieldMap = popupViewFieldMap.get(parentView);
|
46
|
return popupFieldMap.put(popup, field);
|
47
|
}
|
48
|
|
49
|
public Field<?> get(ApplicationView view, PopupView popup){
|
50
|
if(!popupViewFieldMap.containsKey(view)){
|
51
|
popupViewFieldMap.get(view).get(popup);
|
52
|
}
|
53
|
return null;
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* @param popup
|
58
|
*/
|
59
|
public void remove(PopupView popup) {
|
60
|
|
61
|
popupWindowMap.remove(popup);
|
62
|
|
63
|
for(Map<PopupView, Field<?>> popupFieldMap : popupViewFieldMap.values()){
|
64
|
if(popupFieldMap.containsKey(popup)){
|
65
|
popupFieldMap.remove(popup);
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* @param popup
|
72
|
* @return
|
73
|
*/
|
74
|
public Window getWindow(PopupView popup) {
|
75
|
return popupWindowMap.get(popup);
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
*
|
80
|
*/
|
81
|
public void removeOrphan() {
|
82
|
// unimplemented, only needed in case of memory leaks due to lost popups
|
83
|
}
|
84
|
|
85
|
}
|