Project

General

Profile

Revision 79295d9d

ID79295d9d0873bd78937eb2a4ae6ba46e255cfa06
Parent a50e3be7
Child cb4d176d

Added by Andreas Kohlbecker over 3 years ago

ref #6719 RegistrationItems with edit buttons for name and per typedesignationWorkingSet

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItemEditButtonGroup.java
9 9
package eu.etaxonomy.cdm.vaadin.component.registration;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.HashSet;
12 13
import java.util.List;
14
import java.util.Set;
13 15

  
14 16
import com.vaadin.server.FontAwesome;
15 17
import com.vaadin.ui.Button;
......
17 19
import com.vaadin.ui.themes.ValoTheme;
18 20

  
19 21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
23
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
24
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationConverter.TypeDesignationWorkingSet;
20 25
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
21 26
import eu.etaxonomy.vaadin.component.CompositeStyledComponent;
22 27

  
......
28 33
public class RegistrationItemEditButtonGroup extends CompositeStyledComponent {
29 34

  
30 35

  
36
    /**
37
     *
38
     */
39
    private static final String DEFAULT_BUTTON_STYLES = ""; // ValoTheme.BUTTON_LINK;
40

  
31 41
    private static final long serialVersionUID = -5059163772392864050L;
32 42

  
33
    public static final String STYLE_NAMES = "edit-button-group " + ValoTheme.LAYOUT_COMPONENT_GROUP;
43
    public static final String STYLE_NAMES = "edit-button-group  " + ValoTheme.LAYOUT_COMPONENT_GROUP;
34 44

  
35
    private IdButton nameButton = null;
45
    private IdButton<TaxonName> nameIdButton = null;
36 46

  
37
    private List<IdButton> typeDesignationButtons = new ArrayList<>();
47
    private List<IdSetButton<TypeDesignationWorkingSet>> typeDesignationButtons = new ArrayList<>();
38 48

  
39 49
    private List<Label> labels = new ArrayList<>();
40 50

  
51
    private Button addTypeDesignationButton;
52

  
41 53

  
42 54
    public RegistrationItemEditButtonGroup(RegistrationDTO regDto){
43 55

  
44 56
        setWidth(100, Unit.PERCENTAGE);
45 57

  
46 58
        if(regDto.getName() != null){
47
            nameButton = new IdButton(regDto.getName().getId(), new Button("Name:"));
59
            Button nameButton = new Button("Name:");
60
            nameIdButton = new IdButton<TaxonName>(TaxonName.class, regDto.getName().getId(), nameButton);
48 61
            Label nameLabel = new Label(regDto.getName().getLabel());
49 62
            nameLabel.setWidthUndefined();
50
            addComponents(nameButton.getButton(), nameLabel);
63
            addComponents(nameIdButton.getButton(), nameLabel);
51 64
        } else {
52 65
            // no name in the registration! we only show the typified name as label
53 66
            addComponent(new Label(regDto.getTypifiedName().getLabel()));
54 67
        }
55
        if(regDto.getOrderdTypeDesignationEntitiyReferences() != null){
56
            regDto.getOrderdTypeDesignationEntitiyReferences().keySet().iterator().forEachRemaining(baseEntityRef -> {
68
        if(regDto.getOrderdTypeDesignationWorkingSets() != null){
69
            for(TypedEntityReference baseEntityRef : regDto.getOrderdTypeDesignationWorkingSets().keySet()) {
70
                TypeDesignationWorkingSet typeDesignationWorkingSet = regDto.getOrderdTypeDesignationWorkingSets().get(baseEntityRef);
57 71
                String buttonLabel = SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ? "Type": "NameType";
58 72
                Button tdButton = new Button(buttonLabel + ":");
59 73
                addComponent(tdButton);
60
                typeDesignationButtons.add(new IdButton(baseEntityRef.getId(), tdButton));
74
                Set<Integer> idSet = new HashSet<>();
75
                typeDesignationWorkingSet.getTypeDesignations().forEach(td -> idSet.add(td.getId()));
76
                typeDesignationButtons.add(new IdSetButton<TypeDesignationWorkingSet>(TypeDesignationWorkingSet.class, idSet, tdButton));
77
                String labelText = typeDesignationWorkingSet.getRepresentation();
78
                labelText = labelText.replaceAll("^[^:]+:", ""); // remove Type:, NameType: from the beginning
79
                Label label = new Label(labelText);
61 80

  
62
                Label label = new Label(baseEntityRef.getLabel());
63 81
                label.setWidthUndefined();
64 82
                addComponent(label);
65 83
                labels.add(label);
66

  
67

  
68
            });
84
            }
69 85
        }
70
        Button addTypeDesignationButton = new Button(FontAwesome.PLUS);
86
        addTypeDesignationButton = new Button(FontAwesome.PLUS);
71 87
        addComponent(addTypeDesignationButton);
72 88

  
89

  
73 90
        iterator().forEachRemaining(c -> addStyledComponent(c));
74 91
        addDefaultStyles();
75 92

  
76 93
    }
77 94

  
78
    public IdButton getNameButton() {
79
        return nameButton;
95
    public IdButton<TaxonName> getNameButton() {
96
        return nameIdButton;
80 97
    }
81 98

  
82 99
    /**
......
85 102
    @Override
86 103
    protected void addDefaultStyles() {
87 104
        addStyleName(STYLE_NAMES);
105
        nameIdButton.getButton().addStyleName(DEFAULT_BUTTON_STYLES);
106
        typeDesignationButtons.forEach(idb -> idb.getButton().addStyleName(DEFAULT_BUTTON_STYLES));
107
        addTypeDesignationButton.addStyleName(DEFAULT_BUTTON_STYLES);
88 108
    }
89 109

  
90
    public class IdButton {
110
    public class IdButton<T> {
91 111
        private Integer id;
112
        private Class<T> type;
92 113
        private Button button;
93 114

  
94
        public IdButton(Integer id, Button button){
115
        public IdButton(Class<T> type, Integer id, Button button){
116
            this.type = type;
95 117
            this.id = id;
96 118
            this.button = button;
97 119
        }
......
110 132
            return button;
111 133
        }
112 134

  
135
        /**
136
         * @return the type
137
         */
138
        public Class<T> getType() {
139
            return type;
140
        }
141

  
142
    }
143

  
144
    public class IdSetButton<T> {
145
        private Set<Integer> ids;
146
        private Class<T> type;
147
        private Button button;
148

  
149
        public IdSetButton(Class<T> type, Set<Integer> ids, Button button){
150
            this.type = type;
151
            this.ids = ids;
152
            this.button = button;
153
        }
154

  
155
        /**
156
         * @return the id
157
         */
158
        public Set<Integer> getIds() {
159
            return ids;
160
        }
161

  
162
        /**
163
         * @return the button
164
         */
165
        public Button getButton() {
166
            return button;
167
        }
168

  
169
        /**
170
         * @return the type
171
         */
172
        public Class<T> getType() {
173
            return type;
174
        }
113 175

  
114 176
    }
115 177

  
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/TypeDesignationConverter.java
318 318
        return typeDesignations;
319 319
    }
320 320

  
321
    public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderedTypeDesignations() {
321
    public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderdTypeDesignationWorkingSets() {
322 322
        return orderedByTypesByBaseEntity;
323 323
    }
324 324

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationDTO.java
232 232
        return name;
233 233
    }
234 234

  
235
    public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderdTypeDesignationEntitiyReferences() {
236
        return typeDesignationConverter != null ? typeDesignationConverter.getOrderedTypeDesignations() : null;
235
    public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderdTypeDesignationWorkingSets() {
236
        return typeDesignationConverter != null ? typeDesignationConverter.getOrderdTypeDesignationWorkingSets() : null;
237 237
    }
238 238

  
239 239
    public Collection<TypeDesignationBase> getTypeDesignations() {
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowViewBean.java
87 87
    private String headerText = "-- empty --";
88 88
    private String subheaderText = SUBHEADER_DEEFAULT;
89 89

  
90
    private boolean addNameAndTypeEditButtons = false;
91

  
90 92

  
91 93
    public RegistrationWorkflowViewBean() {
92 94
        super();
......
254 256
            buttonGroup.addComponent(editRegistrationButton);
255 257
        }
256 258

  
257
        Button editNameButton = new Button(FontAwesome.TAG);
258
        editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
259
        editNameButton.setDescription("Edit name");
260
        if(dto.getName() != null){
261
            editNameButton.addClickListener(e -> {
262
                    Integer nameId = dto.getName().getId();
263
                    getEventBus().publishEvent(new TaxonNameEditorAction(
264
                        AbstractEditorAction.Action.EDIT,
265
                        nameId
266
                        )
267
                    );
268
                });
269
        } else {
270
            editNameButton.setEnabled(false);
271
        }
259
        if(addNameAndTypeEditButtons ){
260
            Button editNameButton = new Button(FontAwesome.TAG);
261
            editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
262
            editNameButton.setDescription("Edit name");
263
            if(dto.getName() != null){
264
                editNameButton.addClickListener(e -> {
265
                        Integer nameId = dto.getName().getId();
266
                        getEventBus().publishEvent(new TaxonNameEditorAction(
267
                            AbstractEditorAction.Action.EDIT,
268
                            nameId
269
                            )
270
                        );
271
                    });
272
            } else {
273
                editNameButton.setEnabled(false);
274
            }
272 275

  
273
        Button editTypesButton = new Button(FontAwesome.LEAF);
274
        editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
275
        editTypesButton.setDescription("Edit type designations");
276
        if(!dto.getOrderdTypeDesignationEntitiyReferences().isEmpty()){
277
            editTypesButton.addClickListener(e -> {
278
                int regId = dto.getId();
279
                    getEventBus().publishEvent(new TypedesignationsEditorAction(
280
                        AbstractEditorAction.Action.EDIT,
281
                        regId
282
                        )
283
                    );
284
                });
285
        } else {
286
            editTypesButton.setEnabled(false);
276
            Button editTypesButton = new Button(FontAwesome.LEAF);
277
            editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
278
            editTypesButton.setDescription("Edit type designations");
279
            if(dto.getOrderdTypeDesignationWorkingSets() != null && !dto.getOrderdTypeDesignationWorkingSets().isEmpty()){
280
                editTypesButton.addClickListener(e -> {
281
                    int regId = dto.getId();
282
                        getEventBus().publishEvent(new TypedesignationsEditorAction(
283
                            AbstractEditorAction.Action.EDIT,
284
                            regId
285
                            )
286
                        );
287
                    });
288
            } else {
289
                editTypesButton.setEnabled(false);
290
            }
291
            buttonGroup.addComponents(editNameButton, editTypesButton);
287 292
        }
288
        buttonGroup.addComponents(editNameButton, editTypesButton);
289 293

  
290 294
        Component regItem;
291 295
        if(REG_ITEM_AS_BUTTON_GROUP){
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss
414 414
        margin-top: round($v-unit-size/10);
415 415
        .v-button {
416 416
            padding: 0 round($v-unit-size/4);
417
            height: round(2 * $v-unit-size/3 )
417 418
            // margin: 0 round($v-unit-size/4);
418 419
        }
420
        .v-label {
421
            display: inline;
422
            white-space: normal;
423
        }
419 424
    }
420 425
    
421 426
    // ---------- popup editor windows ---------------------------------//
src/test/java/eu/etaxonomy/cdm/vaadin/util/converter/TypeDesignationConverterTest.java
134 134
                );
135 135

  
136 136
        LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> orderedTypeDesignations =
137
                typeDesignationConverter.getOrderedTypeDesignations();
137
                typeDesignationConverter.getOrderdTypeDesignationWorkingSets();
138 138
        Map<TypeDesignationStatusBase<?>, Collection<EntityReference>> byStatusMap = orderedTypeDesignations.values().iterator().next();
139 139
        Iterator<TypeDesignationStatusBase<?>> keyIt = byStatusMap.keySet().iterator();
140 140
        assertEquals("Holotype", keyIt.next().getLabel());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)