Project

General

Profile

« Previous | Next » 

Revision 2b6b2b23

Added by Andreas Kohlbecker almost 6 years ago

introducing PopupViewRegistration to manage view popupview and target field

View differences:

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);

Also available in: Unified diff