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.vaadin.view.registration.RegistrationDTO;
|
21
|
import eu.etaxonomy.vaadin.component.CompositeStyledComponent;
|
22
|
|
23
|
/**
|
24
|
* @author a.kohlbecker
|
25
|
* @since May 19, 2017
|
26
|
*
|
27
|
*/
|
28
|
public class RegistrationItemEditButtonGroup extends CompositeStyledComponent {
|
29
|
|
30
|
|
31
|
private static final long serialVersionUID = -5059163772392864050L;
|
32
|
|
33
|
public static final String STYLE_NAMES = "edit-button-group " + ValoTheme.LAYOUT_COMPONENT_GROUP;
|
34
|
|
35
|
private IdButton nameButton = null;
|
36
|
|
37
|
private List<IdButton> typeDesignationButtons = new ArrayList<>();
|
38
|
|
39
|
private List<Label> labels = new ArrayList<>();
|
40
|
|
41
|
|
42
|
public RegistrationItemEditButtonGroup(RegistrationDTO regDto){
|
43
|
|
44
|
setWidth(100, Unit.PERCENTAGE);
|
45
|
|
46
|
if(regDto.getName() != null){
|
47
|
nameButton = new IdButton(regDto.getName().getId(), new Button("Name:"));
|
48
|
Label nameLabel = new Label(regDto.getName().getLabel());
|
49
|
nameLabel.setWidthUndefined();
|
50
|
addComponents(nameButton.getButton(), nameLabel);
|
51
|
} else {
|
52
|
// no name in the registration! we only show the typified name as label
|
53
|
addComponent(new Label(regDto.getTypifiedName().getLabel()));
|
54
|
}
|
55
|
if(regDto.getOrderdTypeDesignationEntitiyReferences() != null){
|
56
|
regDto.getOrderdTypeDesignationEntitiyReferences().keySet().iterator().forEachRemaining(baseEntityRef -> {
|
57
|
String buttonLabel = SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ? "Type": "NameType";
|
58
|
Button tdButton = new Button(buttonLabel + ":");
|
59
|
addComponent(tdButton);
|
60
|
typeDesignationButtons.add(new IdButton(baseEntityRef.getId(), tdButton));
|
61
|
|
62
|
Label label = new Label(baseEntityRef.getLabel());
|
63
|
label.setWidthUndefined();
|
64
|
addComponent(label);
|
65
|
labels.add(label);
|
66
|
|
67
|
|
68
|
});
|
69
|
}
|
70
|
Button addTypeDesignationButton = new Button(FontAwesome.PLUS);
|
71
|
addComponent(addTypeDesignationButton);
|
72
|
|
73
|
iterator().forEachRemaining(c -> addStyledComponent(c));
|
74
|
addDefaultStyles();
|
75
|
|
76
|
}
|
77
|
|
78
|
public IdButton getNameButton() {
|
79
|
return nameButton;
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* {@inheritDoc}
|
84
|
*/
|
85
|
@Override
|
86
|
protected void addDefaultStyles() {
|
87
|
addStyleName(STYLE_NAMES);
|
88
|
}
|
89
|
|
90
|
public class IdButton {
|
91
|
private Integer id;
|
92
|
private Button button;
|
93
|
|
94
|
public IdButton(Integer id, Button button){
|
95
|
this.id = id;
|
96
|
this.button = button;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @return the id
|
101
|
*/
|
102
|
public Integer getId() {
|
103
|
return id;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @return the button
|
108
|
*/
|
109
|
public Button getButton() {
|
110
|
return button;
|
111
|
}
|
112
|
|
113
|
|
114
|
}
|
115
|
|
116
|
}
|