Project

General

Profile

Revision c02fc11a

IDc02fc11ae73482b118a48cfb4fca97e7302bda1f
Parent c609114c
Child 0abb074a, 7de1009c

Added by Andreas Kohlbecker 11 months ago

fix #8346 flexible editing of annotations for Curator and Admin roles

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/FilterableAnnotationsField.java
22 22
import com.vaadin.data.Validator.InvalidValueException;
23 23
import com.vaadin.data.fieldgroup.FieldGroup;
24 24
import com.vaadin.data.util.BeanItemContainer;
25
import com.vaadin.ui.Button;
25 26
import com.vaadin.ui.Component;
26 27
import com.vaadin.ui.CssLayout;
27 28
import com.vaadin.ui.DefaultFieldFactory;
......
35 36
import eu.etaxonomy.cdm.model.common.AnnotationType;
36 37
import eu.etaxonomy.cdm.model.common.Language;
37 38
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
39
import eu.etaxonomy.cdm.vaadin.component.ButtonFactory;
38 40
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
39 41
import eu.etaxonomy.cdm.vaadin.util.filter.CdmTermFilter;
40 42
import eu.etaxonomy.vaadin.component.CompositeCustomField;
......
52 54

  
53 55
    private Table table = new Table();
54 56

  
55
    private List<AnnotationType> typesFilter = null;
57
    private Button newButton = ButtonFactory.CREATE_NEW.createButton();
56 58

  
57
    private Annotation emptyDefaultAnnotation = Annotation.NewInstance(null, Language.DEFAULT());
59
    private List<AnnotationType> typesFilter = null;
58 60

  
59 61
    private BeanItemContainer<DefinedTermBase> typeSelectItemContainer;
60 62

  
61 63
    private FilterableListContainer<Annotation> container;
62 64

  
65
    private boolean withNewButton;
66

  
63 67
    public FilterableAnnotationsField() {
64 68
        this(null);
65 69
    }
......
172 176

  
173 177
    @Override
174 178
    protected void setInternalValue(List<Annotation> newValue) {
179

  
175 180
        boolean hasIncludeFilter = typesFilter != null && !typesFilter.isEmpty();
176 181
        boolean onlyOneType = hasIncludeFilter && typesFilter.size() == 1;
177 182

  
178 183
        if(newValue.isEmpty()){
179
            newValue.add(emptyDefaultAnnotation);
184
            Annotation emptyDefaultAnnotation = newInstance();
185
            newValue.add(emptyDefaultAnnotation );
180 186
            if(onlyOneType){
181 187
                emptyDefaultAnnotation.setAnnotationType(typesFilter.get(0));
182 188
            }
......
192 198
            table.setVisibleColumns("text", "annotationType");
193 199
        }
194 200
        table.setEditable(true);
201
        if(newValue.size() > 1){
202
            table.setPageLength(2);
203
        }
195 204
    }
196 205

  
197 206
    /**
......
199 208
     */
200 209
    @Override
201 210
    protected Component initContent() {
202
        root.addComponent(table);
211
        root.addComponentAsFirst(table);
212

  
213
        newButton.addClickListener(e -> addAnnotation());
214
        withNewButton(true);
203 215
        return root;
204 216
    }
205 217

  
206 218

  
207 219
    /**
220
     * @return
221
     */
222
    private void addAnnotation() {
223
        container.addItem(newInstance());
224
        if(container.size() > 1){
225
            table.setPageLength(2);
226
        }
227
    }
228

  
229
    /**
230
     * @return
231
     */
232
    private Annotation newInstance() {
233
        return Annotation.NewInstance(null, Language.DEFAULT());
234
    }
235

  
236
    /**
208 237
     * {@inheritDoc}
209 238
     */
210 239
    @Override
......
228 257
        setDeepReadOnly(readOnly, table, null);
229 258
    }
230 259

  
260
    public void withNewButton(boolean withNewButton) {
261
        if(this.withNewButton != withNewButton){
262
            if(!this.withNewButton){
263
                root.addComponent(newButton);
264
            } else {
265
                root.removeComponent(newButton);
266
            }
267
            this.withNewButton = withNewButton;
268
        }
269
    }
270

  
271

  
272

  
273

  
231 274

  
232 275

  
233 276
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java
17 17
import com.vaadin.ui.NativeSelect;
18 18
import com.vaadin.ui.TextField;
19 19

  
20
import eu.etaxonomy.cdm.api.utility.RoleProber;
20 21
import eu.etaxonomy.cdm.model.common.AnnotationType;
21 22
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
22 23
import eu.etaxonomy.cdm.model.name.TaxonName;
23 24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.service.UserHelperAccess;
24 26
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
25 27
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
26 28
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
29
import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
27 30
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
28 31
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
29 32
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
......
180 183
        row++;
181 184
        annotationsListField = new FilterableAnnotationsField("Editorial notes");
182 185
        annotationsListField.setWidth(100, Unit.PERCENTAGE);
183
        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
186
        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
187
        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
188
        if(isCurator || isAdmin){
189
            annotationsListField.withNewButton(true);
190
        } else {
191
            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
192
        }
184 193
        addField(annotationsListField, "annotations", 0, row, 3, row);
185 194
    }
186 195

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
29 29
import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter;
30 30
import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter.LabelType;
31 31
import eu.etaxonomy.cdm.model.common.Annotation;
32
import eu.etaxonomy.cdm.model.common.AnnotationType;
32 33
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
33 34
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
34 35
import eu.etaxonomy.cdm.model.name.TaxonName;
......
165 166

  
166 167
        getView().getTypifiedNamesComboboxSelect().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize(), this);
167 168

  
169
        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildBeanItemContainer(
170
                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
171

  
168 172
    }
169 173

  
170 174

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
30 30
import eu.etaxonomy.cdm.model.agent.AgentBase;
31 31
import eu.etaxonomy.cdm.model.agent.Person;
32 32
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
33
import eu.etaxonomy.cdm.model.common.AnnotationType;
33 34
import eu.etaxonomy.cdm.model.common.CdmBase;
34 35
import eu.etaxonomy.cdm.model.location.Country;
35 36
import eu.etaxonomy.cdm.model.name.Registration;
......
191 192
        getView().getTypeDesignationsCollectionField().addElementRemovedListener(e -> deleteTypeDesignation(e.getElement()));
192 193
        getView().getTypeDesignationsCollectionField().addElementAddedListener(e -> addTypeDesignation(e.getElement()));
193 194

  
195
        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildBeanItemContainer(
196
                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
197

  
194 198
        popuEditorTypeDesignationSourceRows.clear();
195 199
        CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
196 200
        collectionPagingProvider.getRestrictions().add(new Restriction<>("institute.titleCache", Operator.OR, MatchMode.ANYWHERE, CdmFilterablePagingProvider.QUERY_STRING_PLACEHOLDER));
197 201

  
198 202
        CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider = pagingProviderFactory.referencePagingProvider();
199 203

  
204

  
200 205
        getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
201 206

  
202 207
            @Override
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
27 27
import com.vaadin.ui.Panel;
28 28
import com.vaadin.ui.TextArea;
29 29

  
30
import eu.etaxonomy.cdm.api.utility.RoleProber;
30 31
import eu.etaxonomy.cdm.model.common.AnnotationType;
31 32
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
33
import eu.etaxonomy.cdm.service.UserHelperAccess;
32 34
import eu.etaxonomy.cdm.vaadin.component.CollectionRowRepresentative;
33 35
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
34 36
import eu.etaxonomy.cdm.vaadin.component.common.GeoLocationField;
......
38 40
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
39 41
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
40 42
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
43
import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
41 44
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
42 45
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
43 46
import eu.etaxonomy.cdm.vaadin.util.converter.DoubleConverter;
......
242 245
        row++;
243 246
        annotationsListField = new FilterableAnnotationsField("Editorial notes");
244 247
        annotationsListField.setWidth(100, Unit.PERCENTAGE);
245
        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
248
        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
249
        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
250
        if(isCurator || isAdmin){
251
            annotationsListField.withNewButton(true);
252
        } else {
253
            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
254
        }
246 255
        addField(annotationsListField, "annotations", 0, row, 2, row);
247 256

  
248 257
     }
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
234 234
        getView().getOrthographicVariantField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider, icbnCodesPagingProvider.getPageSize());
235 235
        getView().getOrthographicVariantField().getCitatonComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getOrthographicVariantField().getCitatonComboBox(), this));
236 236

  
237

  
238
        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildTermItemContainer(
239
                AnnotationType.EDITORIAL().getUuid(), AnnotationType.TECHNICAL().getUuid()));
237
        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildBeanItemContainer(
238
                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
240 239
    }
241 240

  
242 241
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
35 35
import com.vaadin.ui.Panel;
36 36
import com.vaadin.ui.TextField;
37 37

  
38
import eu.etaxonomy.cdm.api.utility.RoleProber;
38 39
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
39 40
import eu.etaxonomy.cdm.model.common.AnnotationType;
40 41
import eu.etaxonomy.cdm.model.common.CdmBase;
......
45 46
import eu.etaxonomy.cdm.model.name.RankClass;
46 47
import eu.etaxonomy.cdm.model.name.TaxonName;
47 48
import eu.etaxonomy.cdm.model.reference.Reference;
49
import eu.etaxonomy.cdm.service.UserHelperAccess;
48 50
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
49 51
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
50 52
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
......
55 57
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
56 58
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
57 59
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
60
import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
58 61
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
59 62
import eu.etaxonomy.cdm.vaadin.ui.UIMessages;
60 63
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
......
563 566
        row++;
564 567
        annotationsListField = new FilterableAnnotationsField("Editorial notes");
565 568
        annotationsListField.setWidth(100, Unit.PERCENTAGE);
566
        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
569
        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
570
        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
571
        if(isCurator || isAdmin){
572
            annotationsListField.withNewButton(true);
573
        } else {
574
            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
575
        }
576

  
567 577
        addField(annotationsListField, "annotations", 0, row, GRID_COLS-1, row);
568 578

  
569 579
        // -----------------------------------------------------------------------------
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
280 280
        row++;
281 281
        annotationsListField = new FilterableAnnotationsField("Editorial notes");
282 282
        annotationsListField.setWidth(100, Unit.PERCENTAGE);
283
        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
283
        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
284
        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
285
        if(isCurator || isAdmin){
286
            annotationsListField.withNewButton(true);
287
        } else {
288
            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
289
        }
284 290
        addField(annotationsListField, "annotations", 0, row, GRID_COLS-1, row);
285 291

  
286 292

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)