Project

General

Profile

« Previous | Next » 

Revision 21c1abac

Added by Andreas Kohlbecker over 6 years ago

ref #7171 TaxonNameEditor nomenclaturalReferenceSectionEditingOnly mode

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
14 14
import java.util.Set;
15 15

  
16 16
import org.apache.log4j.Logger;
17
import org.hibernate.criterion.Restrictions;
17 18
import org.springframework.context.event.EventListener;
18 19

  
19 20
import eu.etaxonomy.cdm.api.service.INameService;
......
25 26
import eu.etaxonomy.cdm.model.name.TaxonName;
26 27
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
27 28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.model.reference.ReferenceType;
28 31
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
29 32
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
30 33
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
......
34 37
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
35 38
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
36 39
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
40
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
37 41
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
38 42
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
39 43

  
......
50 54

  
51 55
    ReferencePopupEditor newReferencePopup = null;
52 56

  
57
    private CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider;
58

  
59
    private Reference publishedUnit;
60

  
61
    private BeanInstantiator<Reference> newReferenceInstantiator;
62

  
53 63
    /**
54 64
     * {@inheritDoc}
55 65
     */
......
78 88
        getView().getExBasionymAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
79 89

  
80 90
        getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
81
        CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference, Reference>(getRepo().getReferenceService());
91
        referencePagingProvider = new CdmFilterablePagingProvider<Reference, Reference>(getRepo().getReferenceService());
82 92
        getView().getNomReferenceCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
83 93
        getView().getNomReferenceCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getNomReferenceCombobox()));
84 94

  
85

  
86 95
        getView().getBasionymCombobox().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
87 96
        CdmFilterablePagingProvider<TaxonName, TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService());
88 97

  
......
125 134
                }
126 135
        );
127 136

  
128
        TaxonName bean;
137
        TaxonName taxonName;
129 138
        if(identifier != null){
130
            bean = getRepo().getNameService().load(identifier, initStrategy);
139
            taxonName = getRepo().getNameService().load(identifier, initStrategy);
131 140
        } else {
132
            bean = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
141
            taxonName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
133 142
        }
134
        return bean;
143

  
144
        if(getView().isModeEnabled(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly)){
145
            if(taxonName.getNomenclaturalReference() != null){
146
                Reference nomRef = (Reference)taxonName.getNomenclaturalReference();
147
                //getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section));
148
                publishedUnit = nomRef;
149
                while(publishedUnit.isOfType(ReferenceType.Section) && publishedUnit.getInReference() != null){
150
                    publishedUnit = nomRef.getInReference();
151
                }
152
                // reduce available references to those which are sections of the publishedUnit and the publishedUnit itself
153
                // referencePagingProvider
154
                referencePagingProvider.getCriteria().add(Restrictions.or(
155
                        Restrictions.and(Restrictions.eq("inReference", publishedUnit), Restrictions.eq("type", ReferenceType.Section)),
156
                        Restrictions.idEq(publishedUnit.getId())
157
                        )
158
                );
159
                // and remove the empty option
160
                getView().getNomReferenceCombobox().getSelect().setNullSelectionAllowed(false);
161

  
162
                // new Reference only a sub sections of the publishedUnit
163
                newReferenceInstantiator = new BeanInstantiator<Reference>() {
164
                    @Override
165
                    public Reference createNewBean() {
166
                        Reference newRef = ReferenceFactory.newSection();
167
                        newRef.setInReference(publishedUnit);
168
                        return newRef;
169
                    }
170
                };
171

  
172
            }
173
        }
174

  
175
        return taxonName;
135 176
    }
136 177

  
137 178
    /**
......
204 245

  
205 246
        newReferencePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
206 247
        newReferencePopup.withDeleteButton(true);
248
        newReferencePopup.setBeanInstantiator(newReferenceInstantiator);
207 249
        newReferencePopup.loadInEditor(null);
250
        if(newReferenceInstantiator != null){
251
            // this is a bit clumsy, we actually need to inject something like a view configurer
252
            // which can enable, disable fields
253
            newReferencePopup.getInReferenceCombobox().setEnabled(false);
254
            newReferencePopup.getTypeSelect().setEnabled(false);
255
        }
208 256
    }
209 257

  
210 258
    @EventListener
......
216 264

  
217 265
                // TODO the bean contained in the popup editor is not yet updated at this point.
218 266
                //      so re reload it using the uuid since new beans will not have an Id at this point.
219
                newReference = getRepo().getReferenceService().find(newReference.getUuid());
267
                newReference = getRepo().getReferenceService().load(newReference.getUuid(), Arrays.asList("inReference"));
220 268
                getView().getNomReferenceCombobox().setValue(newReference);
221 269
            }
222 270

  

Also available in: Unified diff