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