Project

General

Profile

« Previous | Next » 

Revision 2b6b2b23

Added by Andreas Kohlbecker about 4 years ago

introducing PopupViewRegistration to manage view popupview and target field

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
230 230
            return;
231 231
        }
232 232

  
233
        typeNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
233
        typeNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), null);
234 234
        typeNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
235 235
        typeNamePopup.withDeleteButton(true);
236 236
        // TODO configure Modes???
......
248 248

  
249 249
        //  basionymSourceField = (AbstractField<TaxonName>)event.getSourceComponent();
250 250

  
251
        typeNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
251
        typeNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), null);
252 252
        typeNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
253 253
        typeNamePopup.withDeleteButton(true);
254 254
        // TODO configure Modes???
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
309 309

  
310 310
    public void doCollectionEditorAdd(SpecimenTypeDesignationDTORow row) {
311 311

  
312
        CollectionPopupEditor collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
312
        CollectionPopupEditor collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView(), null);
313 313

  
314 314
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
315 315
        collectionPopupEditor.withDeleteButton(true);
......
320 320

  
321 321
    public void doCollectionEditorEdit(SpecimenTypeDesignationDTORow row) {
322 322

  
323
        CollectionPopupEditor collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
323
        CollectionPopupEditor collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView(), null);
324 324

  
325 325
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
326 326
        collectionPopupEditor.withDeleteButton(true);
......
351 351

  
352 352
    public void doReferenceEditorAdd(SpecimenTypeDesignationDTORow row) {
353 353

  
354
        ReferencePopupEditor referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
354
        ReferencePopupEditor referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
355 355

  
356 356
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
357 357
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
......
363 363

  
364 364
    public void doReferenceEditorEdit(SpecimenTypeDesignationDTORow row) {
365 365

  
366
        ReferencePopupEditor referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
366
        ReferencePopupEditor referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
367 367
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
368 368
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
369 369
        referencePopupEditor.withDeleteButton(true);
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
18 18
import org.springframework.context.annotation.Scope;
19 19
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
20 20

  
21
import com.vaadin.data.Property;
21 22
import com.vaadin.spring.annotation.SpringComponent;
22
import com.vaadin.ui.AbstractField;
23
import com.vaadin.ui.AbstractSelect;
24
import com.vaadin.ui.Field;
23 25

  
24 26
import eu.etaxonomy.cdm.api.service.INameService;
25 27
import eu.etaxonomy.cdm.model.agent.AgentBase;
......
50 52
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
51 53
import eu.etaxonomy.vaadin.component.ReloadableSelect;
52 54
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOEditorPresenter;
55
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
53 56
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
54 57

  
55 58
/**
......
85 88

  
86 89
    private BeanInstantiator<Reference> newReferenceInstantiator;
87 90

  
88
    private AbstractField<TaxonName> basionymSourceField;
89

  
90 91
    /**
91 92
     * {@inheritDoc}
92 93
     */
......
192 193

  
193 194
        if(getView().isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY)){
194 195
            if(taxonName.getNomenclaturalReference() != null){
195
                Reference nomRef = (Reference)taxonName.getNomenclaturalReference();
196
                Reference nomRef = taxonName.getNomenclaturalReference();
196 197
                //getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section));
197 198
                publishedUnit = nomRef;
198 199
                while(publishedUnit.isOfType(ReferenceType.Section) && publishedUnit.getInReference() != null){
......
260 261
            return;
261 262
        }
262 263

  
263
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
264
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
264 265

  
265 266
        referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
266 267
        referenceEditorPopup.withDeleteButton(true);
......
281 282
        if(getView() == null || event.getSourceView() != getView() ){
282 283
            return;
283 284
        }
284
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
285
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
285 286

  
286 287
        referenceEditorPopup.withDeleteButton(true);
287 288
        referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
......
297 298
    @EventBusListenerMethod
298 299
    public void onEntityChangeEvent(EntityChangeEvent<?> event){
299 300

  
300
        if(event.getSourceView() == referenceEditorPopup){
301
            if(event.isCreateOrModifiedType()){
301
        if(event.getSourceView() instanceof AbstractPopupEditor) {
302

  
303
            AbstractPopupEditor popupEditor = (AbstractPopupEditor) event.getSourceView();
304
            Field<?> targetField = getNavigationManager().targetFieldOf(getView(), popupEditor);
305

  
306
            Property ds = targetField.getPropertyDataSource();
307
            if(event.getSourceView() == referenceEditorPopup){
308
                if(event.isCreateOrModifiedType()){
302 309

  
303
                getCache().load(event.getEntity());
304
                if(event.isCreatedType()){
305
                    getView().getNomReferenceCombobox().setValue((Reference) event.getEntity());
306
                } else {
307
                    getView().getNomReferenceCombobox().reload(); // refreshSelectedValue(modifiedReference);
310
                    getCache().load(event.getEntity());
311
                    if(event.isCreatedType()){
312
                        getView().getNomReferenceCombobox().setValue((Reference) event.getEntity());
313
                    } else {
314
                        getView().getNomReferenceCombobox().reload(); // refreshSelectedValue(modifiedReference);
315
                    }
316
                    getView().getCombinationAuthorshipField().discard(); //refresh from the datasource
317
                    getView().updateAuthorshipFields();
308 318
                }
309
                getView().getCombinationAuthorshipField().discard(); //refresh from the datasource
310
                getView().updateAuthorshipFields();
319

  
320
                referenceEditorPopup = null;
311 321
            }
322
            if(event.getSourceView()  == basionymNamePopup){
323
                AbstractSelect basionymSourceField = (AbstractSelect) targetField;
324
                if(event.isCreateOrModifiedType()){
325

  
326
                    getCache().load(event.getEntity());
327
                    if(event.isCreatedType()){
328
                        basionymSourceField .setValue(event.getEntity());
329
                    } else {
330
                        ((ReloadableSelect)basionymSourceField).reload();
331
                    }
332
                    getView().getBasionymAuthorshipField().discard(); //refresh from the datasource
333
                    getView().getExBasionymAuthorshipField().discard(); //refresh from the datasource
334
                    getView().updateAuthorshipFields();
312 335

  
313
            referenceEditorPopup = null;
314
        }
315
        if(event.getSourceView()  == basionymNamePopup){
316
            if(event.isCreateOrModifiedType()){
317

  
318
                getCache().load(event.getEntity());
319
                if(event.isCreatedType()){
320
                    basionymSourceField.setValue((TaxonName) event.getEntity());
321
                } else {
322
                    ((ReloadableSelect)basionymSourceField).reload();
323 336
                }
324
                getView().getBasionymAuthorshipField().discard(); //refresh from the datasource
325
                getView().getExBasionymAuthorshipField().discard(); //refresh from the datasource
326
                getView().updateAuthorshipFields();
337
                if(event.isRemovedType()){
338
                    basionymSourceField.setValue(null);
339
                    getView().updateAuthorshipFields();
340
                }
327 341

  
328
            }
329
            if(event.isRemovedType()){
330
                basionymSourceField.setValue(null);
331
                getView().updateAuthorshipFields();
342
                basionymNamePopup = null;
332 343
            }
333 344

  
334
            basionymNamePopup = null;
335
            basionymSourceField = null;
336 345
        }
337 346
    }
338 347

  
......
342 351
        if(getView() == null || event.getSourceView() != getView() ){
343 352
            return;
344 353
        }
345
        ReloadableLazyComboBox<TaxonName> sourceField = (ReloadableLazyComboBox<TaxonName>)event.getTarget();
354
        ReloadableLazyComboBox<TaxonName> targetField = (ReloadableLazyComboBox<TaxonName>)event.getTarget();
346 355

  
347
        if(sourceField == getView().getValidationField().getValidatedNameComboBox().getSelect()){
356
        if(targetField == getView().getValidationField().getValidatedNameComboBox().getSelect()){
348 357
            // validatedNameSourceField .. this is awkward, better use a map to correlate fields to popup editors!!!!
349 358

  
350 359
        } else {
351
            basionymSourceField = sourceField;
352

  
353
            basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
360
            basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), event.getTarget());
354 361
            basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
355 362
            basionymNamePopup.withDeleteButton(true);
356 363
            getView().getModesActive().stream()
357
                    .filter(
358
                            m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
364
                    .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
359 365
                    .forEach(m -> basionymNamePopup.enableMode(m));
360 366
            basionymNamePopup.loadInEditor(event.getEntityUuid());
361 367
            basionymNamePopup.getBasionymToggle().setVisible(false);
......
370 376
            return;
371 377
        }
372 378

  
373
        basionymSourceField = (AbstractField<TaxonName>)event.getTarget();
374

  
375
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
379
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), event.getTarget());
376 380
        basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
377 381
        basionymNamePopup.withDeleteButton(true);
378 382
        getView().getModesActive().stream()
379
                .filter(
380
                        m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
383
                .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
381 384
                .forEach(m -> basionymNamePopup.enableMode(m));
382 385
        basionymNamePopup.loadInEditor(null);
383 386
        basionymNamePopup.getBasionymToggle().setVisible(false);
src/main/java/eu/etaxonomy/cdm/vaadin/view/occurrence/CollectionEditorPresenter.java
113 113
            return;
114 114
        }
115 115

  
116
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
116
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView(), null);
117 117

  
118 118
        collectionPopuEditor.grantToCurrentUser(this.crud);
119 119
        collectionPopuEditor.withDeleteButton(true);
......
127 127
            return;
128 128
        }
129 129

  
130
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
130
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView(), null);
131 131

  
132 132
        collectionPopuEditor.grantToCurrentUser(this.crud);
133 133
        collectionPopuEditor.withDeleteButton(true);
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferenceEditorPresenter.java
149 149

  
150 150
       if(ToOneRelatedEntityField.class.isAssignableFrom(editorAction.getTarget().getClass())){
151 151
           if(editorAction.isAddAction()){
152
               inReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
152
               inReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
153 153
               inReferencePopup.loadInEditor(null);
154 154
           }
155 155
           if(editorAction.isEditAction()){
156
               inReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
156
               inReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
157 157
               inReferencePopup.withDeleteButton(true);
158 158
               inReferencePopup.loadInEditor(editorAction.getEntityUuid());
159 159
           }
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
289 289
            return;
290 290
        }
291 291

  
292
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
292
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
293 293
        popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
294 294
        popup.loadInEditor(null);
295 295
    }
......
300 300
        if(!checkFromOwnView(event)){
301 301
            return;
302 302
        }
303
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
303
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
304 304
        popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
305 305
        popup.withDeleteButton(true);
306 306
        popup.loadInEditor(event.getEntityUuid());
......
331 331
            return;
332 332
        }
333 333

  
334
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class, getView());
334
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class, getView(), null);
335 335
        popup.loadInEditor(event.getEntityUuid());
336 336
    }
337 337

  
......
342 342
            return;
343 343
        }
344 344

  
345
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
345
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), null);
346 346
        popup.setParentEditorActionContext(event.getContext());
347 347
        popup.withDeleteButton(true);
348 348
        configureTaxonNameEditor(popup);
......
366 366
        newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationUuid()));
367 367
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration, (AbstractView) getView());
368 368
        newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityUuid());
369
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
369
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), null);
370 370
        popup.setParentEditorActionContext(event.getContext());
371 371
        popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE));
372 372
        popup.withDeleteButton(true);
......
463 463
        }
464 464

  
465 465
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
466
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView());
466
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView(), null);
467 467
            popup.setParentEditorActionContext(event.getContext());
468 468
            popup.withDeleteButton(true);
469 469
            popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationUuid(), event.getBaseEntityRef()));
......
472 472
                popup.setReadOnly(event.getSource().isReadOnly());
473 473
            }
474 474
        } else {
475
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView());
475
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView(), null);
476 476
            popup.setParentEditorActionContext(event.getContext());
477 477
            popup.withDeleteButton(true);
478 478
            popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationUuid(), event.getBaseEntityRef()));
......
496 496
        }
497 497

  
498 498
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
499
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView());
499
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView(), null);
500 500
            popup.setParentEditorActionContext(event.getContext());
501 501
            TypeDesignationWorkingsetEditorIdSet identifierSet;
502 502
            UUID typifiedNameUuid;
......
526 526
                popup.setReadOnly(event.getSource().isReadOnly());
527 527
            }
528 528
        } else {
529
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView());
529
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView(), null);
530 530
            popup.setParentEditorActionContext(event.getContext());
531 531
            popup.withDeleteButton(true);
532 532
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
......
679 679
            getView().setBlockingRegistrations(registrationUuid, blockingRegs);
680 680
        } else if(event.getProperty().equals(RegistrationItem.MESSAGES)){
681 681

  
682
            RegistrationMessagesPopup popup = getNavigationManager().showInPopup(RegistrationMessagesPopup.class, getView());
682
            RegistrationMessagesPopup popup = getNavigationManager().showInPopup(RegistrationMessagesPopup.class, getView(), null);
683 683
            popup.loadMessagesFor(regDto.getUuid());
684 684

  
685 685
        } else if(event.getProperty().equals(RegistrationItem.VALIDATION_PROBLEMS)){
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/StartRegistrationPresenter.java
94 94
            return;
95 95
        }
96 96

  
97
        newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
97
        newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), null);
98 98
        EnumSet<ReferenceType> refTypes = RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES.clone();
99 99
        refTypes.remove(ReferenceType.Section);
100 100
        newReferencePopup.withReferenceTypes(refTypes);
src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManager.java
3 3
import java.util.List;
4 4

  
5 5
import com.vaadin.navigator.View;
6
import com.vaadin.ui.Field;
6 7

  
7 8
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
8 9
import eu.etaxonomy.vaadin.mvp.ApplicationView;
......
18 19
	 *         Type of the popup to open
19 20
	 * @param parentView
20 21
	 *         The view from where the request to open the popup is being triggered
22
	 * @param targetField
23
	 *         The field which will needs to be updated after the popup view has been closed. Can be <code>null</code>.
21 24
	 * @return
22 25
	 */
23
	<T extends PopupView> T showInPopup(Class<T> popupType, ApplicationView parentView);
26
	<T extends PopupView> T showInPopup(Class<T> popupType, ApplicationView parentView, Field<?> targetField);
24 27

  
25 28
	public List<AbstractEditorPresenter<?,?>> getPopupEditorPresenters();
26 29

  
......
33 36
	 * @return
34 37
	 */
35 38
	public List<String> getCurrentViewParameters();
39

  
40
    Field<?> targetFieldOf(ApplicationView parentView, PopupView popupView);
36 41
}
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();
src/main/java/eu/etaxonomy/vaadin/ui/navigation/PopupViewRegistration.java
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
}

Also available in: Unified diff