Project

General

Profile

Revision c6db362d

IDc6db362dfc15d063b5111b04e0a4c0e683445e75
Parent c397c928
Child 67d3b70d

Added by Andreas Kohlbecker about 2 years ago

fix #7480 implementing school, institute and school fields in Reference editor

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferenceEditorPresenter.java
22 22

  
23 23
import eu.etaxonomy.cdm.api.service.IService;
24 24
import eu.etaxonomy.cdm.model.agent.AgentBase;
25
import eu.etaxonomy.cdm.model.agent.Institution;
25 26
import eu.etaxonomy.cdm.model.agent.Person;
26 27
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
27 28
import eu.etaxonomy.cdm.model.common.Annotation;
......
31 32
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
32 33
import eu.etaxonomy.cdm.service.UserHelperAccess;
33 34
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
35
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
34 36
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
37
import eu.etaxonomy.cdm.vaadin.event.InstitutionEditorAction;
35 38
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
36 39
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
37 40
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
41
import eu.etaxonomy.cdm.vaadin.view.common.InstitutionPopupEditor;
38 42
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityField;
39 43
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
40 44
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
45
import eu.etaxonomy.vaadin.mvp.BoundField;
46
import eu.etaxonomy.vaadin.ui.view.PopupView;
41 47

  
42 48
/**
43 49
 * @author a.kohlbecker
......
86 92
        getView().getAuthorshipField().setFilterableTeamPagingProvider(teamOrPersonPagingProvider, this);
87 93
        getView().getAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
88 94

  
95
        CdmFilterablePagingProvider<AgentBase, Institution> institutionPagingProvider = new CdmFilterablePagingProvider<AgentBase, Institution>(getRepo().getAgentService(), Institution.class);
96
        getView().getInstitutionCombobox().getSelect().loadFrom(institutionPagingProvider, institutionPagingProvider, institutionPagingProvider.getPageSize());
97
        getView().getInstitutionCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Institution>(getView().getInstitutionCombobox(), this));
98

  
99
        getView().getSchoolCombobox().getSelect().loadFrom(institutionPagingProvider, institutionPagingProvider, institutionPagingProvider.getPageSize());
100
        getView().getSchoolCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Institution>(getView().getSchoolCombobox(), this));
101

  
89 102
        getView().getAnnotationsField().setAnnotationTypeItemContainer(selectFieldFactory.buildTermItemContainer(
90 103
                AnnotationType.EDITORIAL().getUuid(), AnnotationType.TECHNICAL().getUuid()));
91 104
    }
......
152 165
    /**
153 166
    *
154 167
    * @param editorAction
155
     * @throws EditorEntityBeanException
168
    * @throws EditorEntityBeanException
156 169
    */
157 170
   @EventBusListenerMethod
158 171
   public void onReferenceEditorAction(ReferenceEditorAction editorAction) {
......
174 187
       }
175 188
   }
176 189

  
190
   @EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
191
   public void onInstitutionEditorActionEdit(InstitutionEditorAction event) {
192

  
193
       if(!checkFromOwnView(event)){
194
           return;
195
       }
196

  
197
       InstitutionPopupEditor institutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
198

  
199
       institutionPopuEditor.grantToCurrentUser(this.crud);
200
       institutionPopuEditor.withDeleteButton(true);
201
       institutionPopuEditor.loadInEditor(event.getEntityUuid());
202
   }
203

  
204
   @EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
205
   public void onInstitutionEditorActionAdd(InstitutionEditorAction event) {
206

  
207
       if(!checkFromOwnView(event)){
208
           return;
209
       }
210

  
211
       InstitutionPopupEditor institutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
212

  
213
       institutionPopuEditor.grantToCurrentUser(this.crud);
214
       institutionPopuEditor.withDeleteButton(false);
215
       institutionPopuEditor.loadInEditor(null);
216
   }
217

  
177 218
   @EventBusListenerMethod
178 219
   public void onEntityChangeEvent(EntityChangeEvent<?> event){
179 220

  
180
       if(event.getSourceView() == inReferencePopup){
181
           if(event.isCreateOrModifiedType()){
182
               getCache().load(event.getEntity());
183
               getView().getInReferenceCombobox().reload();
221
       BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
222

  
223
       if(boundTargetField != null){
224
           if(boundTargetField.matchesPropertyIdPath("inReference")){
225
               if(event.isCreateOrModifiedType()){
226
                   getCache().load(event.getEntity());
227
                   getView().getInReferenceCombobox().reload();
228
               }
229
               if(event.isRemovedType()){
230
                   getView().getInReferenceCombobox().selectNewItem(null);
231
               }
232
               inReferencePopup = null;
184 233
           }
185
           if(event.isRemovedType()){
186
               getView().getInReferenceCombobox().selectNewItem(null);
234
           else if(boundTargetField.matchesPropertyIdPath("institute")){
235
               if(event.isCreateOrModifiedType()){
236
                   Institution newInstitution = (Institution) event.getEntity();
237
                   getCache().load(newInstitution);
238
                   if(event.isCreatedType()){
239
                       getView().getInstitutionCombobox().setValue(newInstitution);
240
                   } else {
241
                       getView().getInstitutionCombobox().reload();
242
                   }
243
               }
244
           } else if(boundTargetField.matchesPropertyIdPath("school")){
245
               if(event.isCreateOrModifiedType()){
246
                   Institution newInstitution = (Institution) event.getEntity();
247
                   getCache().load(newInstitution);
248
                   if(event.isCreatedType()){
249
                       getView().getSchoolCombobox().setValue(newInstitution);
250
                   } else {
251
                       getView().getSchoolCombobox().reload();
252
                   }
253
               }
187 254
           }
188
           inReferencePopup = null;
189 255
       }
190 256

  
191 257
   }
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
28 28
import com.vaadin.ui.ListSelect;
29 29
import com.vaadin.ui.TextField;
30 30

  
31
import eu.etaxonomy.cdm.model.agent.Institution;
31 32
import eu.etaxonomy.cdm.model.common.AnnotationType;
32 33
import eu.etaxonomy.cdm.model.reference.Reference;
33 34
import eu.etaxonomy.cdm.model.reference.ReferencePropertyDefinitions;
......
37 38
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
38 39
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
39 40
import eu.etaxonomy.cdm.vaadin.component.common.VerbatimTimePeriodField;
41
import eu.etaxonomy.cdm.vaadin.event.InstitutionEditorAction;
40 42
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
41 43
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
42 44
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
45
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
43 46
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
44 47
import eu.etaxonomy.cdm.vaadin.util.converter.DoiConverter;
45 48
import eu.etaxonomy.cdm.vaadin.util.converter.UriConverter;
......
66 69

  
67 70
    private final static int GRID_COLS = 4; // 12 would fits for 2,3, and 4 Components per row
68 71

  
69
    private final static int GRID_ROWS = 11;
72
    private final static int GRID_ROWS = 14;
70 73

  
71 74
    private ListSelect typeSelect;
72 75

  
......
74 77

  
75 78
    private TeamOrPersonField authorshipField;
76 79

  
80
    private ToOneRelatedEntityCombobox<Institution> institutionCombobox;
81
    private ToOneRelatedEntityCombobox<Institution> schoolCombobox;
82

  
77 83
    private FilterableAnnotationsField annotationsListField;
78 84

  
79 85
    private AnnotationType[] editableAnotationTypes = RegistrationUIDefaults.EDITABLE_ANOTATION_TYPES;
......
187 193
            }
188 194
            });
189 195
        addField(inReferenceCombobox, "inReference", 0, row, GRID_COLS -1, row);
196

  
197
        institutionCombobox = new ToOneRelatedEntityCombobox<Institution>("Institution", Institution.class);
198
        institutionCombobox.getSelect().setCaptionGenerator(
199
                new CdmTitleCacheCaptionGenerator<Institution>()
200
                );
201
        institutionCombobox.setWidth(100, Unit.PERCENTAGE);
202
        institutionCombobox.addClickListenerAddEntity(e -> getViewEventBus().publish(this,
203
                new InstitutionEditorAction(EditorActionType.ADD, e.getButton(), institutionCombobox, this)
204
                ));
205
        institutionCombobox.addClickListenerEditEntity(e -> {
206
            if(institutionCombobox.getValue() != null){
207
                getViewEventBus().publish(this,
208
                    new InstitutionEditorAction(
209
                            EditorActionType.EDIT,
210
                            institutionCombobox.getValue().getUuid(),
211
                            e.getButton(),
212
                            institutionCombobox,
213
                            this)
214
                );
215
            }
216
         });
217

  
218
        schoolCombobox = new ToOneRelatedEntityCombobox<Institution>("School", Institution.class);
219
        schoolCombobox.getSelect().setCaptionGenerator(
220
                new CdmTitleCacheCaptionGenerator<Institution>()
221
                );
222
        schoolCombobox.addClickListenerAddEntity(e -> getViewEventBus().publish(this,
223
                new InstitutionEditorAction(EditorActionType.ADD, e.getButton(), schoolCombobox, this)
224
                ));
225
        schoolCombobox.addClickListenerEditEntity(e -> {
226
            if(schoolCombobox.getValue() != null){
227
                getViewEventBus().publish(this,
228
                    new InstitutionEditorAction(
229
                            EditorActionType.EDIT,
230
                            schoolCombobox.getValue().getUuid(),
231
                            e.getButton(),
232
                            schoolCombobox,
233
                            this)
234
                );
235
            }
236
         });
237
        row++;
238
        addField(institutionCombobox, "institution", 0, row, GRID_COLS -1, row);
239
        row++;
240
        addField(schoolCombobox, "school", 0, row, GRID_COLS -1, row);
190 241
        row++;
191 242

  
192 243
        variableGridStartRow = row;
244

  
245
        addTextField("Organization", "organization", 0, row).setWidth(100, Unit.PERCENTAGE);
246
        row++;
193 247
        addTextField("Series", "seriesPart", 0, row).setWidth(100, Unit.PERCENTAGE);
194 248
        addTextField("Volume", "volume", 1, row).setWidth(100, Unit.PERCENTAGE);
195 249
        addTextField("Pages", "pages", 2, row).setWidth(100, Unit.PERCENTAGE);
......
269 323
            getField("title").setVisible(fieldPropertyDefinition.containsKey("title"));
270 324

  
271 325
            EnumSet<ReferenceType> hideNomTitle = EnumSet.of(ReferenceType.Article, ReferenceType.Section, ReferenceType.BookSection, ReferenceType.InProceedings);
272
//            EnumSet<ReferenceType> hideTitle = EnumSet.of(ReferenceType.Section, ReferenceType.BookSection);
273 326
            getField("abbrevTitle").setVisible(!hideNomTitle.contains(referenceType));
327
            institutionCombobox.setVisible(fieldPropertyDefinition.containsKey("institution"));
328
            schoolCombobox.setVisible(fieldPropertyDefinition.containsKey("school"));
274 329

  
275 330
            for(String fieldName : adaptiveFields.keySet()){ // iterate over the LinkedHashMap to retain the original order of the fields
276 331
                if(fieldPropertyDefinition.containsKey(fieldName)){
......
416 471
        }
417 472
    }
418 473

  
474
    @Override
475
    public ToOneRelatedEntityCombobox<Institution> getInstitutionCombobox() {
476
        return institutionCombobox;
477
    }
478

  
479
    @Override
480
    public ToOneRelatedEntityCombobox<Institution> getSchoolCombobox() {
481
        return schoolCombobox;
482
    }
483

  
419 484

  
420 485
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditorView.java
10 10

  
11 11
import com.vaadin.ui.ListSelect;
12 12

  
13
import eu.etaxonomy.cdm.model.agent.Institution;
13 14
import eu.etaxonomy.cdm.model.reference.Reference;
14 15
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
15 16
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
......
29 30

  
30 31
    public TeamOrPersonField getAuthorshipField();
31 32

  
32
    /**
33
     * @return
34
     */
35
    FilterableAnnotationsField getAnnotationsField();
33
    public FilterableAnnotationsField getAnnotationsField();
36 34

  
35
    public ToOneRelatedEntityCombobox<Institution> getInstitutionCombobox();
36

  
37
    public ToOneRelatedEntityCombobox<Institution> getSchoolCombobox();
37 38

  
38 39
}
src/test/java/eu/etaxonomy/vaadin/mvp/CdmEditorPresenterTest.java
19 19
import com.vaadin.ui.ListSelect;
20 20

  
21 21
import eu.etaxonomy.cdm.api.application.CdmRepository;
22
import eu.etaxonomy.cdm.model.agent.Institution;
22 23
import eu.etaxonomy.cdm.model.reference.Reference;
23 24
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
24 25
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
......
91 92
            return null;
92 93
        }
93 94

  
95
        /**
96
         * {@inheritDoc}
97
         */
98
        @Override
99
        public ToOneRelatedEntityCombobox<Institution> getInstitutionCombobox() {
100
            return null;
101
        }
102

  
103
        /**
104
         * {@inheritDoc}
105
         */
106
        @Override
107
        public ToOneRelatedEntityCombobox<Institution> getSchoolCombobox() {
108
            return null;
109
        }
110

  
94 111

  
95 112

  
96 113
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)