Project

General

Profile

« Previous | Next » 

Revision d9cb9015

Added by Andreas Kohlbecker over 6 years ago

enabling media reference edit and add buttons in SpecimenTypeDesignationDTORows

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
41 41
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
42 42
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
43 43
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
44
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
44 45
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
45 46
import eu.etaxonomy.cdm.vaadin.view.occurrence.CollectionPopupEditor;
47
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
46 48
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
47 49
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
48 50
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
......
82 84

  
83 85
    SpecimenTypeDesignationWorkingSetDTO<Registration> workingSetDto;
84 86

  
85
    private CollectionPopupEditor collectionPopuEditor;
87
    private CollectionPopupEditor collectionPopupEditor;
86 88

  
87 89
    private Set<CollectionRowItemCollection> collectionPopuEditorSourceRows = new HashSet<>();
88 90

  
91
    private ReferencePopupEditor referencePopupEditor;
92

  
89 93
    protected CdmStore<Registration, IRegistrationService> getStore() {
90 94
        if(store == null){
91 95
            store = new CdmStore<>(getRepo(), getRepo().getRegistrationService());
......
186 190
                row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Collection>(row.collection));
187 191
                row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(row.collection.getSelect(),
188 192
                        SpecimenTypeDesignationWorkingsetEditorPresenter.this));
189
                row.collection.addClickListenerAddEntity( e -> doCollectionEditorAdd());
193
                row.collection.addClickListenerAddEntity(e -> doCollectionEditorAdd());
190 194
                row.collection.addClickListenerEditEntity(e -> {
191 195
                        if(row.collection.getValue() != null){
192 196
                            doCollectionEditorEdit(row.collection.getValue().getId());
......
203 207
                row.mediaSpecimenReference.getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(row.mediaSpecimenReference));
204 208
                row.mediaSpecimenReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.mediaSpecimenReference.getSelect(),
205 209
                        SpecimenTypeDesignationWorkingsetEditorPresenter.this));
210
                row.mediaSpecimenReference.addClickListenerAddEntity(e -> doReferenceEditorAdd());
211
                row.mediaSpecimenReference.addClickListenerEditEntity(e -> {
212
                    if(row.mediaSpecimenReference.getValue() != null){
213
                        doReferenceEditorEdit(row.mediaSpecimenReference.getValue().getId());
214
                    }
215
                });
206 216

  
207 217
                getView().applyDefaultComponentStyle(row.components());
208 218

  
......
287 297

  
288 298
    public void doCollectionEditorAdd() {
289 299

  
290
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
300
        collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
291 301

  
292
        collectionPopuEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
293
        collectionPopuEditor.withDeleteButton(true);
294
        collectionPopuEditor.loadInEditor(null);
302
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
303
        collectionPopupEditor.withDeleteButton(true);
304
        collectionPopupEditor.loadInEditor(null);
295 305
    }
296 306

  
297 307
    public void doCollectionEditorEdit(int collectionId) {
298 308

  
299
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
309
        collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
300 310

  
301
        collectionPopuEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
302
        collectionPopuEditor.withDeleteButton(true);
303
        collectionPopuEditor.loadInEditor(collectionId);
311
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
312
        collectionPopupEditor.withDeleteButton(true);
313
        collectionPopupEditor.loadInEditor(collectionId);
304 314
    }
305 315

  
306 316
    @EventListener(condition = "#event.entityType == T(eu.etaxonomy.cdm.model.occurrence.Collection)")
......
315 325
        }
316 326
    }
317 327

  
328
    public void doReferenceEditorAdd() {
329

  
330
        referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class);
331

  
332
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
333
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
334
        referencePopupEditor.withDeleteButton(true);
335
        referencePopupEditor.loadInEditor(null);
336
    }
337

  
338
    public void doReferenceEditorEdit(int referenceId) {
339

  
340
        referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class);
341
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
342
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
343
        referencePopupEditor.withDeleteButton(true);
344
        referencePopupEditor.loadInEditor(referenceId);
345
    }
346

  
347
    @EventListener(condition = "#event.entityType == T(eu.etaxonomy.cdm.model.reference.Reference)")
348
    public void onReferenceEvent(EntityChangeEvent event){
349

  
350
        Reference newRef = getRepo().getReferenceService().load(event.getEntityId(), Arrays.asList(new String[]{"$"}));
351
        cache.findAndUpdate(newRef);
352

  
353
        for( CollectionRowItemCollection row : collectionPopuEditorSourceRows) {
354
            ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, 6);
355
            combobox.reload();
356
        }
357
    }
358

  
318 359

  
319 360

  
320 361
}

Also available in: Unified diff