Project

General

Profile

« Previous | Next » 

Revision af10794f

Added by Andreas Kohlbecker almost 6 years ago

consistent popup opening, using boundTargetField to identify field to be updated

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;
22 21
import com.vaadin.spring.annotation.SpringComponent;
23
import com.vaadin.ui.Field;
24 22

  
25 23
import eu.etaxonomy.cdm.api.service.INameService;
26 24
import eu.etaxonomy.cdm.model.agent.AgentBase;
......
52 50
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOEditorPresenter;
53 51
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
54 52
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
53
import eu.etaxonomy.vaadin.mvp.BoundField;
54
import eu.etaxonomy.vaadin.ui.view.PopupView;
55
import eu.etaxonomy.vaadin.util.PropertyIdPath;
55 56

  
56 57
/**
57 58
 * @author a.kohlbecker
......
76 77

  
77 78
    private static final Logger logger = Logger.getLogger(TaxonNameEditorPresenter.class);
78 79

  
79
    private ReferencePopupEditor referenceEditorPopup = null;
80

  
81
    private TaxonNamePopupEditor basionymNamePopup = null;
82

  
83 80
    private CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider;
84 81

  
85 82
    private Reference publishedUnit;
......
259 256
            return;
260 257
        }
261 258

  
262
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), event.getTarget());
259
        ReferencePopupEditor referenceEditorPopup = openPopupEditor(ReferencePopupEditor.class, event);
263 260

  
264 261
        referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
265 262
        referenceEditorPopup.withDeleteButton(true);
......
280 277
        if(getView() == null || event.getSourceView() != getView() ){
281 278
            return;
282 279
        }
283
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView(), event.getTarget());
280
        ReferencePopupEditor referenceEditorPopup = openPopupEditor(ReferencePopupEditor.class, event);
284 281

  
285 282
        referenceEditorPopup.withDeleteButton(true);
286 283
        referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
......
298 295

  
299 296
        if(event.getSourceView() instanceof AbstractPopupEditor) {
300 297

  
301
            AbstractPopupEditor popupEditor = (AbstractPopupEditor) event.getSourceView();
302

  
303
            Field<?> targetField = getNavigationManager().targetFieldOf(popupEditor);
298
            BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
304 299

  
305
            if(targetField != null){
306

  
307
                Property ds = targetField.getPropertyDataSource();
308

  
309
                if(event.getSourceView() == referenceEditorPopup){
300
            if(boundTargetField != null){
301
                if(boundTargetField.matchesPropertyIdPath("nomenclaturalReference")){
310 302
                    if(event.isCreateOrModifiedType()){
311 303

  
312 304
                        getCache().load(event.getEntity());
......
318 310
                        getView().getCombinationAuthorshipField().discard(); //refresh from the datasource
319 311
                        getView().updateAuthorshipFields();
320 312
                    }
321

  
322
                    referenceEditorPopup = null;
323 313
                }
324
                if(event.getSourceView()  == basionymNamePopup){
325
                    ReloadableLazyComboBox basionymSourceField = (ReloadableLazyComboBox)targetField;
326

  
314
                if(boundTargetField.matchesPropertyIdPath("validationFor.otherName")){
315
                    ReloadableLazyComboBox<TaxonName> otherNameField = (ReloadableLazyComboBox<TaxonName>)boundTargetField.getField(TaxonName.class);
316
                    if(event.isCreateOrModifiedType()){
317
                        getCache().load(event.getEntity());
318
                        if(event.isCreatedType()){
319
                            otherNameField.setValue((TaxonName) event.getEntity());
320
                        } else {
321
                            otherNameField.reload();
322
                        }
323
                    } else
324
                    if(event.isRemovedType()){
325
                        otherNameField.setValue(null);
326
                    }
327
                } else
328
                if(boundTargetField.matchesPropertyIdPath("basionyms")){
329
                    ReloadableLazyComboBox<TaxonName> basionymSourceField = (ReloadableLazyComboBox<TaxonName>)boundTargetField.getField(TaxonName.class);
327 330
                    if(event.isCreateOrModifiedType()){
328

  
329 331
                        getCache().load(event.getEntity());
330 332
                        if(event.isCreatedType()){
331
                            basionymSourceField .setValue(event.getEntity());
333
                            basionymSourceField .setValue((TaxonName) event.getEntity());
332 334
                        } else {
333 335
                            basionymSourceField.reload();
334 336
                        }
335 337
                        getView().getBasionymAuthorshipField().discard(); //refresh from the datasource
336 338
                        getView().getExBasionymAuthorshipField().discard(); //refresh from the datasource
337 339
                        getView().updateAuthorshipFields();
338

  
339
                    }
340
                    } else
340 341
                    if(event.isRemovedType()){
341 342
                        basionymSourceField.setValue(null);
342 343
                        getView().updateAuthorshipFields();
343 344
                    }
344

  
345
                    basionymNamePopup = null;
346 345
                }
347 346

  
348 347
            }
349 348
        }
350 349
    }
351 350

  
351

  
352

  
352 353
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
353 354
    public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
354 355

  
355 356
        if(getView() == null || event.getSourceView() != getView() ){
356 357
            return;
357 358
        }
358
        ReloadableLazyComboBox<TaxonName> targetField = (ReloadableLazyComboBox<TaxonName>)event.getTarget();
359 359

  
360
        if(targetField == getView().getValidationField().getValidatedNameComboBox().getSelect()){
361
            // validatedNameSourceField .. this is awkward, better use a map to correlate fields to popup editors!!!!
360
        PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
362 361

  
363
        } else {
364
            basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), event.getTarget());
365
            basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
366
            basionymNamePopup.withDeleteButton(true);
367
            getView().getModesActive().stream()
362
        if(boundPropertyId != null){
363
            if(boundPropertyId.matches("validationFor.otherName")){
364
                TaxonNamePopupEditor validatedNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
365
                validatedNamePopup.withDeleteButton(true);
366
                getView().getModesActive().stream()
368 367
                    .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
369
                    .forEach(m -> basionymNamePopup.enableMode(m));
370
            basionymNamePopup.loadInEditor(event.getEntityUuid());
371
            basionymNamePopup.getBasionymToggle().setVisible(false);
368
                    .forEach(m -> validatedNamePopup.enableMode(m));
369
                validatedNamePopup.loadInEditor(event.getEntityUuid());
370
            } else if(boundPropertyId.matches("basionyms")) {
371
                TaxonNamePopupEditor basionymNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
372
                basionymNamePopup.withDeleteButton(true);
373
                getView().getModesActive().stream()
374
                        .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
375
                        .forEach(m -> basionymNamePopup.enableMode(m));
376
                basionymNamePopup.loadInEditor(event.getEntityUuid());
377
                basionymNamePopup.getBasionymToggle().setVisible(false);
378
            }
372 379
        }
373 380

  
374 381
    }
375 382

  
376 383
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
377
    public void oTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
384
    public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
378 385

  
379 386
        if(getView() == null || event.getSourceView() != getView() ){
380 387
            return;
381 388
        }
382 389

  
383
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView(), event.getTarget());
384
        basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
385
        basionymNamePopup.withDeleteButton(true);
386
        getView().getModesActive().stream()
387
                .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
388
                .forEach(m -> basionymNamePopup.enableMode(m));
389
        basionymNamePopup.loadInEditor(null);
390
        basionymNamePopup.getBasionymToggle().setVisible(false);
390
        PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
391

  
392
        if(boundPropertyId != null){
393
            if(boundPropertyId.matches("validationFor.otherName")){
394
                TaxonNamePopupEditor validatedNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
395
                validatedNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
396
                validatedNamePopup.withDeleteButton(true);
397
                getView().getModesActive().stream()
398
                        .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
399
                        .forEach(m -> validatedNamePopup.enableMode(m));
400
                validatedNamePopup.loadInEditor(null);
401
            } else if(boundPropertyId.matches("basionyms")) {
402
                TaxonNamePopupEditor basionymNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
403
                basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
404
                basionymNamePopup.withDeleteButton(true);
405
                getView().getModesActive().stream()
406
                        .filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
407
                        .forEach(m -> basionymNamePopup.enableMode(m));
408
                basionymNamePopup.loadInEditor(null);
409
                basionymNamePopup.getBasionymToggle().setVisible(false);
410
            }
411
        }
391 412
    }
392 413

  
393 414
    /**

Also available in: Unified diff