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.EnumSet;
|
13
|
import java.util.List;
|
14
|
|
15
|
import com.vaadin.server.FontAwesome;
|
16
|
import com.vaadin.ui.Button;
|
17
|
import com.vaadin.ui.Label;
|
18
|
import com.vaadin.ui.themes.ValoTheme;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
22
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
|
23
|
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
|
24
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSet;
|
25
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
|
26
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
|
27
|
import eu.etaxonomy.vaadin.component.CompositeStyledComponent;
|
28
|
|
29
|
/**
|
30
|
* @author a.kohlbecker
|
31
|
* @since May 19, 2017
|
32
|
*
|
33
|
*/
|
34
|
public class RegistrationItemEditButtonGroup extends CompositeStyledComponent {
|
35
|
|
36
|
|
37
|
/**
|
38
|
*
|
39
|
*/
|
40
|
private static final String DEFAULT_BUTTON_STYLES = "";
|
41
|
|
42
|
private static final long serialVersionUID = -5059163772392864050L;
|
43
|
|
44
|
public static final String STYLE_NAMES = "edit-button-group " + ValoTheme.LAYOUT_COMPONENT_GROUP;
|
45
|
|
46
|
private IdButton<TaxonName> nameIdButton = null;
|
47
|
|
48
|
private List<TypeDesignationWorkingSetButton> typeDesignationButtons = new ArrayList<>();
|
49
|
|
50
|
private List<Label> labels = new ArrayList<>();
|
51
|
|
52
|
private Button addTypeDesignationButton;
|
53
|
|
54
|
private Label nameLabel = null;
|
55
|
|
56
|
|
57
|
public RegistrationItemEditButtonGroup(RegistrationDTO regDto){
|
58
|
|
59
|
boolean isRegistrationLocked = EnumSet.of(
|
60
|
RegistrationStatus.PUBLISHED, RegistrationStatus.REJECTED)
|
61
|
.contains(regDto.getStatus());
|
62
|
|
63
|
setWidth(100, Unit.PERCENTAGE);
|
64
|
|
65
|
if(regDto.getName() != null){
|
66
|
Button nameButton = new Button("Name:");
|
67
|
nameButton.setDescription("Edit the Name");
|
68
|
nameIdButton = new IdButton<TaxonName>(TaxonName.class, regDto.getName().getId(), nameButton);
|
69
|
Label nameLabel = new Label(regDto.getName().getLabel());
|
70
|
nameLabel.setWidthUndefined();
|
71
|
nameButton.setEnabled(!isRegistrationLocked);
|
72
|
addComponents(nameIdButton.getButton(), nameLabel);
|
73
|
} else {
|
74
|
// no name in the registration! we only show the typified name as label
|
75
|
if(regDto.getTypifiedName() != null){
|
76
|
nameLabel = new Label(regDto.getTypifiedName().getLabel());
|
77
|
addComponent(nameLabel);
|
78
|
}
|
79
|
}
|
80
|
if(regDto.getOrderdTypeDesignationWorkingSets() != null){
|
81
|
for(TypedEntityReference baseEntityRef : regDto.getOrderdTypeDesignationWorkingSets().keySet()) {
|
82
|
TypeDesignationWorkingSet typeDesignationWorkingSet = regDto.getOrderdTypeDesignationWorkingSets().get(baseEntityRef);
|
83
|
String buttonLabel = SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType()) ? "Type": "NameType";
|
84
|
Button tdButton = new Button(buttonLabel + ":");
|
85
|
tdButton.setDescription("Edit the type designation working set");
|
86
|
tdButton.setEnabled(!isRegistrationLocked);
|
87
|
addComponent(tdButton);
|
88
|
// Set<Integer> idSet = new HashSet<>();
|
89
|
// typeDesignationWorkingSet.getTypeDesignations().forEach(td -> idSet.add(td.getId()));
|
90
|
|
91
|
typeDesignationButtons.add(new TypeDesignationWorkingSetButton(
|
92
|
typeDesignationWorkingSet.getWorkingsetType(),
|
93
|
typeDesignationWorkingSet.getWorkingSetId(),
|
94
|
tdButton)
|
95
|
);
|
96
|
String labelText = typeDesignationWorkingSet.getRepresentation();
|
97
|
labelText = labelText.replaceAll("^[^:]+:", ""); // remove "Type:", "NameType:" from the beginning
|
98
|
Label label = new Label(labelText);
|
99
|
|
100
|
label.setWidthUndefined();
|
101
|
addComponent(label);
|
102
|
labels.add(label);
|
103
|
}
|
104
|
}
|
105
|
addTypeDesignationButton = new Button(FontAwesome.PLUS);
|
106
|
addTypeDesignationButton.setDescription("Add a new type designation workingset");
|
107
|
addTypeDesignationButton.setVisible(!isRegistrationLocked);
|
108
|
addComponent(addTypeDesignationButton);
|
109
|
|
110
|
iterator().forEachRemaining(c -> addStyledComponent(c));
|
111
|
addDefaultStyles();
|
112
|
|
113
|
}
|
114
|
|
115
|
public IdButton<TaxonName> getNameButton() {
|
116
|
return nameIdButton;
|
117
|
}
|
118
|
|
119
|
public List<TypeDesignationWorkingSetButton> getTypeDesignationButtons() {
|
120
|
return typeDesignationButtons;
|
121
|
}
|
122
|
|
123
|
public Button getAddTypeDesignationButton() {
|
124
|
return addTypeDesignationButton;
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* {@inheritDoc}
|
129
|
*/
|
130
|
@Override
|
131
|
protected void addDefaultStyles() {
|
132
|
addStyleName(STYLE_NAMES);
|
133
|
if(nameIdButton != null){
|
134
|
nameIdButton.getButton().addStyleName(DEFAULT_BUTTON_STYLES);
|
135
|
}
|
136
|
if(nameLabel != null){
|
137
|
nameLabel.addStyleName("v-disabled");
|
138
|
}
|
139
|
typeDesignationButtons.forEach(idb -> idb.getButton().addStyleName(DEFAULT_BUTTON_STYLES));
|
140
|
addTypeDesignationButton.addStyleName(DEFAULT_BUTTON_STYLES);
|
141
|
}
|
142
|
|
143
|
public class TypeDesignationWorkingSetButton {
|
144
|
private Integer id;
|
145
|
private TypeDesignationWorkingSetType type;
|
146
|
private Button button;
|
147
|
|
148
|
public TypeDesignationWorkingSetButton(TypeDesignationWorkingSetType type, Integer id, Button button){
|
149
|
this.type = type;
|
150
|
this.id = id;
|
151
|
this.button = button;
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* @return the id
|
156
|
*/
|
157
|
public Integer getId() {
|
158
|
return id;
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* @return the button
|
163
|
*/
|
164
|
public Button getButton() {
|
165
|
return button;
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* @return the type
|
170
|
*/
|
171
|
public TypeDesignationWorkingSetType getType() {
|
172
|
return type;
|
173
|
}
|
174
|
|
175
|
}
|
176
|
|
177
|
public class IdButton<T> {
|
178
|
private Integer id;
|
179
|
private Class<T> entityType;
|
180
|
private Button button;
|
181
|
|
182
|
public IdButton(Class<T> type, Integer id, Button button){
|
183
|
this.entityType = type;
|
184
|
this.id = id;
|
185
|
this.button = button;
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* @return the id
|
190
|
*/
|
191
|
public Integer getId() {
|
192
|
return id;
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* @return the button
|
197
|
*/
|
198
|
public Button getButton() {
|
199
|
return button;
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* @return the type
|
204
|
*/
|
205
|
public Class<T> getType() {
|
206
|
return entityType;
|
207
|
}
|
208
|
|
209
|
}
|
210
|
|
211
|
}
|