Project

General

Profile

Download (6.27 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
            if(regDto.getTypifiedName() != null){
67
                addComponent(new Label(regDto.getTypifiedName().getLabel()));
68
            }
69
        }
70
        if(regDto.getOrderdTypeDesignationWorkingSets() != null){
71
            for(TypedEntityReference baseEntityRef : regDto.getOrderdTypeDesignationWorkingSets().keySet()) {
72
                TypeDesignationWorkingSet typeDesignationWorkingSet = regDto.getOrderdTypeDesignationWorkingSets().get(baseEntityRef);
73
                String buttonLabel = SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ? "Type": "NameType";
74
                Button tdButton = new Button(buttonLabel + ":");
75
                tdButton.setDescription("Edit the type designation working set");
76
                addComponent(tdButton);
77
//                Set<Integer> idSet = new HashSet<>();
78
//                typeDesignationWorkingSet.getTypeDesignations().forEach(td -> idSet.add(td.getId()));
79

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

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

    
98

    
99
        iterator().forEachRemaining(c -> addStyledComponent(c));
100
        addDefaultStyles();
101

    
102
    }
103

    
104
    public IdButton<TaxonName> getNameButton() {
105
        return nameIdButton;
106
    }
107

    
108
    public List<TypeDesignationWorkingSetButton> getTypeDesignationButtons() {
109
        return typeDesignationButtons;
110
    }
111

    
112
    public Button getAddTypeDesignationButton() {
113
        return addTypeDesignationButton;
114
    }
115

    
116
    /**
117
     * {@inheritDoc}
118
     */
119
    @Override
120
    protected void addDefaultStyles() {
121
        addStyleName(STYLE_NAMES);
122
        if(nameIdButton != null){
123
            nameIdButton.getButton().addStyleName(DEFAULT_BUTTON_STYLES);
124
        }
125
        typeDesignationButtons.forEach(idb -> idb.getButton().addStyleName(DEFAULT_BUTTON_STYLES));
126
        addTypeDesignationButton.addStyleName(DEFAULT_BUTTON_STYLES);
127
    }
128

    
129
    public class TypeDesignationWorkingSetButton {
130
        private Integer id;
131
        private TypeDesignationWorkingSetType type;
132
        private Button button;
133

    
134
        public TypeDesignationWorkingSetButton(TypeDesignationWorkingSetType type, Integer id, Button button){
135
            this.type = type;
136
            this.id = id;
137
            this.button = button;
138
        }
139

    
140
        /**
141
         * @return the id
142
         */
143
        public Integer getId() {
144
            return id;
145
        }
146

    
147
        /**
148
         * @return the button
149
         */
150
        public Button getButton() {
151
            return button;
152
        }
153

    
154
        /**
155
         * @return the type
156
         */
157
        public TypeDesignationWorkingSetType getType() {
158
            return type;
159
        }
160

    
161
    }
162

    
163
    public class IdButton<T> {
164
        private Integer id;
165
        private Class<T> entityType;
166
        private Button button;
167

    
168
        public IdButton(Class<T> type, Integer id, Button button){
169
            this.entityType = type;
170
            this.id = id;
171
            this.button = button;
172
        }
173

    
174
        /**
175
         * @return the id
176
         */
177
        public Integer getId() {
178
            return id;
179
        }
180

    
181
        /**
182
         * @return the button
183
         */
184
        public Button getButton() {
185
            return button;
186
        }
187

    
188
        /**
189
         * @return the type
190
         */
191
        public Class<T> getType() {
192
            return entityType;
193
        }
194

    
195
    }
196

    
197
}
(3-3/8)