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.vaadin.view.registration.RegistrationDTO;
|
20
|
import eu.etaxonomy.vaadin.component.CompositeStyledComponent;
|
21
|
|
22
|
/**
|
23
|
* @author a.kohlbecker
|
24
|
* @since May 19, 2017
|
25
|
*
|
26
|
*/
|
27
|
public class RegistrationItemEditButtonGroup extends CompositeStyledComponent {
|
28
|
|
29
|
|
30
|
private static final long serialVersionUID = -5059163772392864050L;
|
31
|
|
32
|
public static final String STYLE_NAMES = "edit-button-group " + ValoTheme.LAYOUT_COMPONENT_GROUP;
|
33
|
|
34
|
/**
|
35
|
* Either the id of the name in the Registration or the id of the typifying name
|
36
|
* of the first type designation.
|
37
|
*/
|
38
|
private Integer nameId = null;
|
39
|
|
40
|
private Button nameButton = null;
|
41
|
|
42
|
private List<Button> typeDesignationButtons = new ArrayList<>();
|
43
|
|
44
|
private List<Label> labels = new ArrayList<>();
|
45
|
|
46
|
|
47
|
|
48
|
public RegistrationItemEditButtonGroup(RegistrationDTO regDto){
|
49
|
|
50
|
setWidth(100, Unit.PERCENTAGE);
|
51
|
|
52
|
if(regDto.getName() != null){
|
53
|
nameButton = new Button(regDto.getName().getLabel());
|
54
|
addComponent(nameButton);
|
55
|
} else {
|
56
|
// no name in the registration! we only show the typified name as label
|
57
|
addComponent(new Label(regDto.getTypifiedName().getLabel()));
|
58
|
}
|
59
|
regDto.getTypeDesignations().keySet().iterator().forEachRemaining(key -> {
|
60
|
Label label = new Label(key + ":");
|
61
|
label.setWidthUndefined();
|
62
|
addComponent(label);
|
63
|
labels.add(label);
|
64
|
|
65
|
regDto.getTypeDesignations().get(key).forEach(value -> {
|
66
|
Button tdButton = new Button(value.getLabel());
|
67
|
addComponent(tdButton);
|
68
|
typeDesignationButtons.add(tdButton);
|
69
|
}) ;
|
70
|
});
|
71
|
Button addTypeDesignationButton = new Button(FontAwesome.PLUS);
|
72
|
addComponent(addTypeDesignationButton);
|
73
|
|
74
|
iterator().forEachRemaining(c -> addStyledComponent(c));
|
75
|
addDefaultStyles();
|
76
|
|
77
|
}
|
78
|
|
79
|
public Button getNameButton() {
|
80
|
return nameButton;
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* {@inheritDoc}
|
85
|
*/
|
86
|
@Override
|
87
|
protected void addDefaultStyles() {
|
88
|
addStyleName(STYLE_NAMES);
|
89
|
}
|
90
|
|
91
|
}
|