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
|
private IdButton nameButton = null;
|
35
|
|
36
|
private List<IdButton> typeDesignationButtons = new ArrayList<>();
|
37
|
|
38
|
private List<Label> labels = new ArrayList<>();
|
39
|
|
40
|
|
41
|
public RegistrationItemEditButtonGroup(RegistrationDTO regDto){
|
42
|
|
43
|
setWidth(100, Unit.PERCENTAGE);
|
44
|
|
45
|
if(regDto.getName() != null){
|
46
|
nameButton = new IdButton(regDto.getName().getId(), new Button("Name:"));
|
47
|
Label nameLabel = new Label(regDto.getName().getLabel());
|
48
|
nameLabel.setWidthUndefined();
|
49
|
addComponents(nameButton.getButton(), nameLabel);
|
50
|
} else {
|
51
|
// no name in the registration! we only show the typified name as label
|
52
|
addComponent(new Label(regDto.getTypifiedName().getLabel()));
|
53
|
}
|
54
|
if(regDto.getTypeDesignations() != null){
|
55
|
regDto.getTypeDesignations().keySet().iterator().forEachRemaining(key -> {
|
56
|
Label label = new Label(key + ":");
|
57
|
label.setWidthUndefined();
|
58
|
addComponent(label);
|
59
|
labels.add(label);
|
60
|
|
61
|
regDto.getTypeDesignations().get(key).forEach(value -> {
|
62
|
Button tdButton = new Button(value.getLabel());
|
63
|
addComponent(tdButton);
|
64
|
typeDesignationButtons.add(new IdButton(value.getId(), tdButton));
|
65
|
}) ;
|
66
|
});
|
67
|
}
|
68
|
Button addTypeDesignationButton = new Button(FontAwesome.PLUS);
|
69
|
addComponent(addTypeDesignationButton);
|
70
|
|
71
|
iterator().forEachRemaining(c -> addStyledComponent(c));
|
72
|
addDefaultStyles();
|
73
|
|
74
|
}
|
75
|
|
76
|
public IdButton getNameButton() {
|
77
|
return nameButton;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* {@inheritDoc}
|
82
|
*/
|
83
|
@Override
|
84
|
protected void addDefaultStyles() {
|
85
|
addStyleName(STYLE_NAMES);
|
86
|
}
|
87
|
|
88
|
public class IdButton {
|
89
|
private Integer id;
|
90
|
private Button button;
|
91
|
|
92
|
public IdButton(Integer id, Button button){
|
93
|
this.id = id;
|
94
|
this.button = button;
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* @return the id
|
99
|
*/
|
100
|
public Integer getId() {
|
101
|
return id;
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* @return the button
|
106
|
*/
|
107
|
public Button getButton() {
|
108
|
return button;
|
109
|
}
|
110
|
|
111
|
|
112
|
}
|
113
|
|
114
|
}
|