Revision 2b6b2b23
Added by Andreas Kohlbecker almost 6 years ago
src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManagerBean.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.vaadin.ui.navigation; |
2 | 2 |
|
3 | 3 |
import java.util.Arrays; |
4 |
import java.util.Collection; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.HashSet; |
|
7 | 4 |
import java.util.List; |
8 |
import java.util.Map; |
|
9 | 5 |
import java.util.Stack; |
10 | 6 |
|
11 | 7 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
22 | 18 |
import com.vaadin.spring.annotation.UIScope; |
23 | 19 |
import com.vaadin.spring.navigator.SpringNavigator; |
24 | 20 |
import com.vaadin.spring.navigator.SpringViewProvider; |
21 |
import com.vaadin.ui.Field; |
|
25 | 22 |
import com.vaadin.ui.UI; |
26 | 23 |
import com.vaadin.ui.Window; |
27 | 24 |
|
... | ... | |
87 | 84 |
@Autowired(required=false) |
88 | 85 |
private PermissionDebugUtils permissionDebugUtils; |
89 | 86 |
|
90 |
private Map<PopupView, Window> popupMap;
|
|
87 |
private PopupViewRegistration popupViewRegistration;
|
|
91 | 88 |
|
92 | 89 |
private String defaultViewName = null; |
93 | 90 |
|
... | ... | |
110 | 107 |
|
111 | 108 |
|
112 | 109 |
public NavigationManagerBean() { |
113 |
popupMap = new HashMap<>();
|
|
110 |
popupViewRegistration = new PopupViewRegistration();
|
|
114 | 111 |
} |
115 | 112 |
|
116 |
private Collection<PopupView> popupViews = new HashSet<>(); |
|
117 |
|
|
113 |
// private Collection<PopupView> popupViews = new HashSet<>(); |
|
118 | 114 |
// @Lazy |
119 | 115 |
// @Autowired(required=false) |
120 | 116 |
// private void popUpViews(Collection<PopupView> popupViews){ |
... | ... | |
147 | 143 |
} else { |
148 | 144 |
super.navigateTo(navigationState); |
149 | 145 |
} |
146 |
popupViewRegistration.removeOrphan(); |
|
150 | 147 |
} |
151 | 148 |
|
152 | 149 |
@Override |
... | ... | |
156 | 153 |
} |
157 | 154 |
super.navigateTo(navigationState); |
158 | 155 |
//eventBus.publishEvent(new NavigationEvent(navigationState)); |
156 |
popupViewRegistration.removeOrphan(); |
|
159 | 157 |
} |
160 | 158 |
|
161 | 159 |
@EventBusListenerMethod |
... | ... | |
164 | 162 |
} |
165 | 163 |
|
166 | 164 |
@Override |
167 |
public <T extends PopupView> T showInPopup(Class<T> popupType, ApplicationView parentView) { |
|
165 |
public <T extends PopupView> T showInPopup(Class<T> popupType, ApplicationView parentView, Field<?> targetField) {
|
|
168 | 166 |
|
169 | 167 |
PopupView popupView = findPopupView(popupType); |
170 | 168 |
|
... | ... | |
176 | 174 |
} |
177 | 175 |
} |
178 | 176 |
|
179 |
|
|
180 | 177 |
Window window = new Window(); |
181 | 178 |
window.setCaption(popupView.getWindowCaption()); |
182 | 179 |
window.center(); |
... | ... | |
197 | 194 |
popupView.focusFirst(); |
198 | 195 |
uiEventBus.publish(this, new PopEditorOpenedEvent(this, popupView)); |
199 | 196 |
|
200 |
popupMap.put(popupView, window);
|
|
197 |
popupViewRegistration.put(window, parentView, popupView, targetField);
|
|
201 | 198 |
|
202 | 199 |
return (T) popupView; |
203 | 200 |
} |
204 | 201 |
|
202 |
@Override |
|
203 |
public Field<?> targetFieldOf(ApplicationView parentView, PopupView popupView){ |
|
204 |
return popupViewRegistration.get(parentView, popupView); |
|
205 |
} |
|
206 |
|
|
205 | 207 |
@EventBusListenerMethod |
206 | 208 |
protected void onDoneWithTheEditor(DoneWithPopupEvent e) { |
207 | 209 |
|
208 | 210 |
PopupView popup = e.getPopup(); |
209 |
Window window = popupMap.get(popup);
|
|
211 |
Window window = popupViewRegistration.getWindow(popup);
|
|
210 | 212 |
if (window != null) { |
211 | 213 |
window.close(); |
212 |
popupMap.remove(popup);
|
|
214 |
popupViewRegistration.remove(popup);
|
|
213 | 215 |
} |
214 | 216 |
if(AbstractPopupEditor.class.isAssignableFrom(popup.getClass())){ |
215 | 217 |
((AbstractPopupEditor)popup).presenter().unsubscribeFromEventBuses(); |
Also available in: Unified diff
introducing PopupViewRegistration to manage view popupview and target field