Project

General

Profile

Download (6.14 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.component.registration;
10

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

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

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

    
27
/**
28
 * @author a.kohlbecker
29
 * @since May 19, 2017
30
 *
31
 */
32
public class RegistrationItemEditButtonGroup extends CompositeStyledComponent {
33

    
34

    
35
    /**
36
     *
37
     */
38
    private static final String DEFAULT_BUTTON_STYLES = "";
39

    
40
    private static final long serialVersionUID = -5059163772392864050L;
41

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

    
44
    private IdButton<TaxonName> nameIdButton = null;
45

    
46
    private List<TypeDesignationWorkingSetButton> typeDesignationButtons = new ArrayList<>();
47

    
48
    private List<Label> labels = new ArrayList<>();
49

    
50
    private Button addTypeDesignationButton;
51

    
52

    
53
    public RegistrationItemEditButtonGroup(RegistrationDTO regDto){
54

    
55
        setWidth(100, Unit.PERCENTAGE);
56

    
57
        if(regDto.getName() != null){
58
            Button nameButton = new Button("Name:");
59
            nameButton.setDescription("Edit the Name");
60
            nameIdButton = new IdButton<TaxonName>(TaxonName.class, regDto.getName().getId(), nameButton);
61
            Label nameLabel = new Label(regDto.getName().getLabel());
62
            nameLabel.setWidthUndefined();
63
            addComponents(nameIdButton.getButton(), nameLabel);
64
        } else {
65
            // no name in the registration! we only show the typified name as label
66
            addComponent(new Label(regDto.getTypifiedName().getLabel()));
67
        }
68
        if(regDto.getOrderdTypeDesignationWorkingSets() != null){
69
            for(TypedEntityReference baseEntityRef : regDto.getOrderdTypeDesignationWorkingSets().keySet()) {
70
                TypeDesignationWorkingSet typeDesignationWorkingSet = regDto.getOrderdTypeDesignationWorkingSets().get(baseEntityRef);
71
                String buttonLabel = SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ? "Type": "NameType";
72
                Button tdButton = new Button(buttonLabel + ":");
73
                tdButton.setDescription("Edit the type designation working set");
74
                addComponent(tdButton);
75
//                Set<Integer> idSet = new HashSet<>();
76
//                typeDesignationWorkingSet.getTypeDesignations().forEach(td -> idSet.add(td.getId()));
77

    
78
                typeDesignationButtons.add(new TypeDesignationWorkingSetButton(
79
                        typeDesignationWorkingSet.getWorkingsetType(),
80
                        typeDesignationWorkingSet.getWorkingSetId(),
81
                        tdButton)
82
                        );
83
                String labelText = typeDesignationWorkingSet.getRepresentation();
84
                labelText = labelText.replaceAll("^[^:]+:", ""); // remove "Type:", "NameType:" from the beginning
85
                Label label = new Label(labelText);
86

    
87
                label.setWidthUndefined();
88
                addComponent(label);
89
                labels.add(label);
90
            }
91
        }
92
        addTypeDesignationButton = new Button(FontAwesome.PLUS);
93
        addTypeDesignationButton.setDescription("Add a new type designation");
94
        addComponent(addTypeDesignationButton);
95

    
96

    
97
        iterator().forEachRemaining(c -> addStyledComponent(c));
98
        addDefaultStyles();
99

    
100
    }
101

    
102
    public IdButton<TaxonName> getNameButton() {
103
        return nameIdButton;
104
    }
105

    
106
    public List<TypeDesignationWorkingSetButton> getTypeDesignationButtons() {
107
        return typeDesignationButtons;
108
    }
109

    
110
    public Button getAddTypeDesignationButton() {
111
        return addTypeDesignationButton;
112
    }
113

    
114
    /**
115
     * {@inheritDoc}
116
     */
117
    @Override
118
    protected void addDefaultStyles() {
119
        addStyleName(STYLE_NAMES);
120
        nameIdButton.getButton().addStyleName(DEFAULT_BUTTON_STYLES);
121
        typeDesignationButtons.forEach(idb -> idb.getButton().addStyleName(DEFAULT_BUTTON_STYLES));
122
        addTypeDesignationButton.addStyleName(DEFAULT_BUTTON_STYLES);
123
    }
124

    
125
    public class TypeDesignationWorkingSetButton {
126
        private Integer id;
127
        private TypeDesignationWorkingSetType type;
128
        private Button button;
129

    
130
        public TypeDesignationWorkingSetButton(TypeDesignationWorkingSetType type, Integer id, Button button){
131
            this.type = type;
132
            this.id = id;
133
            this.button = button;
134
        }
135

    
136
        /**
137
         * @return the id
138
         */
139
        public Integer getId() {
140
            return id;
141
        }
142

    
143
        /**
144
         * @return the button
145
         */
146
        public Button getButton() {
147
            return button;
148
        }
149

    
150
        /**
151
         * @return the type
152
         */
153
        public TypeDesignationWorkingSetType getType() {
154
            return type;
155
        }
156

    
157
    }
158

    
159
    public class IdButton<T> {
160
        private Integer id;
161
        private Class<T> entityType;
162
        private Button button;
163

    
164
        public IdButton(Class<T> type, Integer id, Button button){
165
            this.entityType = type;
166
            this.id = id;
167
            this.button = button;
168
        }
169

    
170
        /**
171
         * @return the id
172
         */
173
        public Integer getId() {
174
            return id;
175
        }
176

    
177
        /**
178
         * @return the button
179
         */
180
        public Button getButton() {
181
            return button;
182
        }
183

    
184
        /**
185
         * @return the type
186
         */
187
        public Class<T> getType() {
188
            return entityType;
189
        }
190

    
191
    }
192

    
193
}
(3-3/8)