Project

General

Profile

Revision f1573a7b

IDf1573a7bfd129cee7ea22b3c8fc3465ae591321e
Parent 458aa218
Child 51d6bc3c

Added by Andreas Kohlbecker almost 3 years ago

ref #6740 NameTypeDesignationEditor implemented

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationEditorView.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.name;
10

  
11
import com.vaadin.ui.ListSelect;
12

  
13
import eu.etaxonomy.cdm.model.name.TaxonName;
14
import eu.etaxonomy.cdm.model.reference.Reference;
15
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
16
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
17
import eu.etaxonomy.vaadin.mvp.ApplicationView;
18

  
19
/**
20
 * @author a.kohlbecker
21
 * @since Jan 26, 2018
22
 *
23
 */
24
public interface NameTypeDesignationEditorView extends ApplicationView<NameTypeDesignationPresenter> {
25

  
26
    ToOneRelatedEntityCombobox<Reference> getCitationCombobox();
27

  
28
    ListSelect getTypeStatusSelect();
29

  
30
    ToManyRelatedEntitiesComboboxSelect<TaxonName> getTypifiedNamesComboboxSelect();
31

  
32
    ToOneRelatedEntityCombobox<TaxonName> getTypeNameField();
33

  
34
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.name;
10

  
11
import com.vaadin.ui.Alignment;
12
import com.vaadin.ui.CheckBox;
13
import com.vaadin.ui.GridLayout;
14
import com.vaadin.ui.ListSelect;
15
import com.vaadin.ui.TextField;
16

  
17
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
18
import eu.etaxonomy.cdm.model.name.TaxonName;
19
import eu.etaxonomy.cdm.model.reference.Reference;
20
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
21
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
22
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
23
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
24

  
25
/**
26
 * @author a.kohlbecker
27
 * @since Jan 26, 2018
28
 *
29
 */
30
public class NameTypeDesignationPopupEditor extends AbstractCdmPopupEditor<NameTypeDesignation, NameTypeDesignationPresenter>
31
    implements NameTypeDesignationEditorView {
32

  
33
    private static final int GRID_COLS = 4;
34
    private static final int GRID_ROWS = 6;
35

  
36
    private CheckBox conservedTypeField;
37
    private CheckBox rejectedTypeField;
38
    private CheckBox notDesignatedField;
39

  
40
    private ToOneRelatedEntityCombobox<TaxonName> typeNameField;
41

  
42
    private ToManyRelatedEntitiesComboboxSelect<TaxonName> typifiedNamesComboboxSelect;
43

  
44
    private ListSelect typeStatusSelect;
45

  
46
    private ToOneRelatedEntityCombobox<Reference> citationCombobox;
47

  
48
    private TextField citationDetailField;
49

  
50

  
51
    /**
52
     * @param layout
53
     * @param dtoType
54
     */
55
    public NameTypeDesignationPopupEditor() {
56
        super(new GridLayout(GRID_COLS, GRID_ROWS), NameTypeDesignation.class);
57
    }
58

  
59
    /**
60
     * {@inheritDoc}
61
     */
62
    @Override
63
    public String getWindowCaption() {
64
        return "Name type designation editor";
65
    }
66

  
67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    public void focusFirst() {
72
        // TODO Auto-generated method stub
73
    }
74

  
75
    /**
76
     * {@inheritDoc}
77
     */
78
    @Override
79
    protected String getDefaultComponentStyles() {
80
        return "tiny";
81
    }
82

  
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    protected void initContent() {
88
        /*
89
            conservedType : boolean
90
            rejectedType : boolean
91
            typeName : TaxonName
92

  
93
            typifiedNames
94
            notDesignated : boolean
95
            registrations : Set<Registration>
96
            typeStatus : T
97

  
98
            citation : Reference
99
            citationMicroReference : String
100
            originalNameString : String
101
         */
102

  
103
        GridLayout grid = (GridLayout)getFieldLayout();
104
        // grid.setSizeFull();
105
        grid.setSpacing(true);
106
        grid.setColumnExpandRatio(0, 0.25f);
107
        grid.setColumnExpandRatio(1, 0.25f);
108
        grid.setColumnExpandRatio(2, 0.25f);
109
        grid.setColumnExpandRatio(3, 0.25f);
110

  
111
        int row = 0;
112

  
113
        conservedTypeField = addCheckBox("Conserved type", "conservedType", 0, row);
114

  
115
        rejectedTypeField = addCheckBox("Rejected type", "rejectedType", 1, row);
116

  
117
        notDesignatedField = addCheckBox("Not designated", "notDesignated", 2, row);
118

  
119
        row++;
120
        typeNameField = new ToOneRelatedEntityCombobox<TaxonName>("Type name", TaxonName.class);
121
        addField(typeNameField, "typeName", 0, row, 3, row);
122

  
123
        row++;
124
        typeStatusSelect = new ListSelect("Type status");
125
        typeStatusSelect.setNullSelectionAllowed(false);
126
        typeStatusSelect.setRows(1);
127
        typeStatusSelect.setWidth(100, Unit.PERCENTAGE);
128
        addField(typeStatusSelect, "typeStatus", 0, row, 1, row);
129
        grid.setComponentAlignment(typeStatusSelect, Alignment.TOP_RIGHT);
130

  
131
        row++;
132
        typifiedNamesComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Typified names");
133
        typifiedNamesComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
134
        addField(typifiedNamesComboboxSelect, "typifiedNames", 0, row, 3, row);
135

  
136
        row++;
137
        citationCombobox = new ToOneRelatedEntityCombobox<Reference>("Citation", Reference.class);
138
        addField(citationCombobox, "citation", 0, row, 2, row);
139
        citationDetailField = addTextField("Citation detail", "citationMicroReference", 3, row);
140
    }
141

  
142
    /**
143
     * @return the typeNameField
144
     */
145
    @Override
146
    public ToOneRelatedEntityCombobox<TaxonName> getTypeNameField() {
147
        return typeNameField;
148
    }
149

  
150
    /**
151
     * @return the typifiedNamesComboboxSelect
152
     */
153
    @Override
154
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getTypifiedNamesComboboxSelect() {
155
        return typifiedNamesComboboxSelect;
156
    }
157

  
158
    /**
159
     * @return the typeStatusSelect
160
     */
161
    @Override
162
    public ListSelect getTypeStatusSelect() {
163
        return typeStatusSelect;
164
    }
165

  
166
    /**
167
     * @return the citationCombobox
168
     */
169
    @Override
170
    public ToOneRelatedEntityCombobox<Reference> getCitationCombobox() {
171
        return citationCombobox;
172
    }
173

  
174

  
175

  
176
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.name;
10

  
11
import java.util.Arrays;
12
import java.util.List;
13

  
14
import eu.etaxonomy.cdm.api.service.IService;
15
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
16
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
17
import eu.etaxonomy.cdm.model.name.TaxonName;
18
import eu.etaxonomy.cdm.model.reference.Reference;
19
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
20
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
21
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
22
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
23
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
24
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
25

  
26
/**
27
 * @author a.kohlbecker
28
 * @since Jan 26, 2018
29
 *
30
 */
31
public class NameTypeDesignationPresenter
32
        extends AbstractCdmEditorPresenter<NameTypeDesignation, NameTypeDesignationEditorView> {
33

  
34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    protected NameTypeDesignation loadCdmEntityById(Integer identifier) {
39
        List<String> initStrategy = Arrays.asList(new String []{
40
                "$",
41
                "typifiedNames.typeDesignations", // important !!
42
                "typeName.$",
43
                "citation.authorship.$",
44
                }
45
        );
46

  
47
        NameTypeDesignation typeDesignation;
48
        if(identifier != null){
49
            typeDesignation = (NameTypeDesignation) getRepo().getNameService().loadTypeDesignation(identifier, initStrategy);
50
        } else {
51
            if(beanInstantiator != null){
52
                typeDesignation = beanInstantiator.createNewBean();
53
            } else {
54
                typeDesignation = NameTypeDesignation.NewInstance();
55
            }
56
        }
57
        return typeDesignation;
58
    }
59

  
60

  
61

  
62

  
63
    /**
64
     * {@inheritDoc}
65
     */
66
    @Override
67
    public void handleViewEntered() {
68

  
69
        CdmBeanItemContainerFactory selectFactory = new CdmBeanItemContainerFactory(getRepo());
70
        getView().getTypeStatusSelect().setContainerDataSource(selectFactory.buildBeanItemContainer(NameTypeDesignationStatus.class));
71

  
72
        CdmFilterablePagingProvider<Reference,Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference, Reference>(getRepo().getReferenceService());
73
        getView().getCitationCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
74
        getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getCitationCombobox()));
75
        getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getCitationCombobox(), this));
76

  
77
        CdmFilterablePagingProvider<TaxonName,TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService());
78
        getView().getTypeNameField().loadFrom(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize());
79
        getView().getTypeNameField().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<TaxonName>(getView().getTypeNameField()));
80
        getView().getTypeNameField().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getTypeNameField(), this));
81

  
82
        getView().getTypifiedNamesComboboxSelect().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize(), this);
83

  
84
    }
85

  
86

  
87
    /**
88
     * {@inheritDoc}
89
     */
90
    @Override
91
    protected void guaranteePerEntityCRUDPermissions(Integer identifier) {
92
        if(crud != null){
93
            newAuthorityCreated = UserHelper.fromSession().createAuthorityForCurrentUser(NameTypeDesignation.class, identifier, crud, null);
94
        }
95
    }
96

  
97
    /**
98
     * {@inheritDoc}
99
     */
100
    @Override
101
    protected void guaranteePerEntityCRUDPermissions(NameTypeDesignation bean) {
102
        // TODO Auto-generated method stub
103

  
104
    }
105

  
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    protected IService<NameTypeDesignation> getService() {
111
        // TODO Auto-generated method stub
112
        return null;
113
    }
114

  
115
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
139 139
    protected void initContent() {
140 140

  
141 141
        GridLayout grid = (GridLayout)getFieldLayout();
142
        grid.setSizeFull();
142
        // grid.setSizeFull();
143 143
        grid.setSpacing(true);
144 144
        grid.setColumnExpandRatio(0, 0.3f);
145 145
        grid.setColumnExpandRatio(1, 0.3f);
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.Arrays;
12 13
import java.util.EnumSet;
13 14
import java.util.List;
15
import java.util.UUID;
14 16

  
15 17
import org.springframework.beans.factory.annotation.Autowired;
16 18
import org.springframework.context.event.EventListener;
......
54 56
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
55 57
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
56 58
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
59
import eu.etaxonomy.cdm.vaadin.view.name.NameTypeDesignationPopupEditor;
57 60
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
58 61
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
59 62
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode;
......
93 96

  
94 97
    private RegistrationDTO newRegistrationDTOWithExistingName;
95 98

  
99
    private RegistrationDTO newNameTypeDesignationTarget;
100

  
96 101

  
97 102
    /**
98 103
     *
......
381 386
            popup.withDeleteButton(true);
382 387
            popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getEntityId()));
383 388
            if(event.getSourceComponent() != null){
389
                // TODO document this !!!!!!!!!!!
384 390
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
385 391
            }
386 392
        } else {
387
            // TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
388
            // FIXME implement NameTypeDesignationWorkingsetPopupEditor
393
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
394
            popup.withDeleteButton(true);
395
            popup.loadInEditor(event.getEntityId());
396
            if(event.getSourceComponent() != null){
397
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
398
            }
399
            newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
389 400
        }
390 401
    }
391 402

  
......
418 429
            popup.loadInEditor(identifierSet);
419 430
            popup.withDeleteButton(true);
420 431
        } else {
421
            // TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
422
            // FIXME implement NameTypeDesignationWorkingsetPopupEditor
432
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
433
            popup.withDeleteButton(true);
434
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
435
            popup.loadInEditor(null);
436
            if(event.getSourceComponent() != null){
437
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
438
            }
439
            newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
423 440
        }
424 441
    }
425 442

  
......
449 466
            }
450 467
            // set newRegistrationDTOWithExistingName NULL in any case
451 468
            newRegistrationDTOWithExistingName = null;
469
        } else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){
470
            if(event.getReason().equals(Reason.SAVE)){
471
                UUID uuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid();
472
                TypeDesignationBase<?> nameTypeDesignation = getRepo().getNameService().loadTypeDesignation(uuid, null);
473
                Registration registration = getRepo().getRegistrationService().load(newNameTypeDesignationTarget.getId(), Arrays.asList("$", "typeDesignations"));
474
                registration.getTypeDesignations().add(nameTypeDesignation);
475
                getRepo().getRegistrationService().saveOrUpdate(registration);
476
                newNameTypeDesignationTarget = null;
477
                refreshView(true);
478
            } else if(event.getReason().equals(Reason.CANCEL)){
479
                // noting to do
480
            }
452 481
        }
482
        // ignore other editors
453 483
    }
454 484

  
455 485

  
......
498 528
        } else
499 529
        if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
500 530
            if(workingset.getRegistrationDTOs().stream().anyMatch(
501
                    reg -> reg.getTypeDesignations().stream().anyMatch(
531
                    reg -> reg.getTypeDesignations() != null && reg.getTypeDesignations().stream().anyMatch(
502 532
                            td -> td.getId() == event.getEntityId()
503 533
                            )
504 534
                        )
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorksetViewBean.java
325 325
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
326 326
        Button newNameTypeDesignationButton = new Button("Name type designation",
327 327
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
328
        newNameTypeDesignationButton.setEnabled(false);
329 328

  
330 329
        VerticalLayout layout = new VerticalLayout(label, newSpecimenTypeDesignationButton, newNameTypeDesignationButton);
331 330
        layout.setMargin(true);
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
22 22
import com.vaadin.server.ErrorMessage.ErrorLevel;
23 23
import com.vaadin.server.FontAwesome;
24 24
import com.vaadin.server.UserError;
25
import com.vaadin.shared.ui.MarginInfo;
25 26
import com.vaadin.ui.AbstractField;
26 27
import com.vaadin.ui.AbstractLayout;
27 28
import com.vaadin.ui.AbstractOrderedLayout;
......
47 48
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
48 49
import eu.etaxonomy.vaadin.component.NestedFieldGroup;
49 50
import eu.etaxonomy.vaadin.component.SwitchableTextField;
51
import eu.etaxonomy.vaadin.mvp.event.EditorCancelEvent;
50 52
import eu.etaxonomy.vaadin.mvp.event.EditorDeleteEvent;
51 53
import eu.etaxonomy.vaadin.mvp.event.EditorPreSaveEvent;
52 54
import eu.etaxonomy.vaadin.mvp.event.EditorSaveEvent;
......
139 141

  
140 142
        mainLayout.addComponents(toolBar, fieldLayout, buttonLayout);
141 143
        mainLayout.setComponentAlignment(toolBar, Alignment.TOP_RIGHT);
144

  
145
        updateToolBarVisibility();
142 146
    }
143 147

  
144 148
    protected VerticalLayout getMainLayout() {
......
210 214
     *
211 215
     */
212 216
    private void updateToolBarVisibility() {
217
        boolean showToolbar = toolBarButtonGroup.getComponentCount() + toolBar.getComponentCount() > 1;
213 218
        toolBar.setVisible(toolBarButtonGroup.getComponentCount() + toolBar.getComponentCount() > 1);
219
        if(!showToolbar){
220
            mainLayout.setMargin(new MarginInfo(true, false, false, false));
221
        } else {
222
            mainLayout.setMargin(false);
223
        }
214 224

  
215 225
    }
216 226

  
......
269 279
    @Override
270 280
    public void cancel() {
271 281
        fieldGroup.discard();
282
        eventBus.publishEvent(new EditorCancelEvent<DTO>(this, getBean()));
272 283
        eventBus.publishEvent(new DoneWithPopupEvent(this, Reason.CANCEL));
273 284
    }
274 285

  
......
361 372
        return addField(new CheckBox(caption), propertyId);
362 373
    }
363 374

  
375
    protected CheckBox addCheckBox(String caption, String propertyId, int column, int row){
376
        return addField(new CheckBox(caption), propertyId, column, row);
377
    }
378

  
364 379
    protected <T extends Field> T addField(T field, String propertyId) {
365 380
        fieldGroup.bind(field, propertyId);
366 381
        if(NestedFieldGroup.class.isAssignableFrom(field.getClass())){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)