1
|
/**
|
2
|
* Copyright (C) 2018 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.view.name;
|
10
|
|
11
|
import org.springframework.context.annotation.Scope;
|
12
|
|
13
|
import com.vaadin.spring.annotation.SpringComponent;
|
14
|
import com.vaadin.ui.Alignment;
|
15
|
import com.vaadin.ui.CheckBox;
|
16
|
import com.vaadin.ui.GridLayout;
|
17
|
import com.vaadin.ui.NativeSelect;
|
18
|
import com.vaadin.ui.TextField;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.utility.RoleProber;
|
21
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
22
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
23
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
24
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
26
|
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
|
27
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
28
|
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
|
29
|
import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
|
30
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
31
|
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
|
32
|
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
|
33
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
34
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
35
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
|
36
|
|
37
|
/**
|
38
|
* @author a.kohlbecker
|
39
|
* @since Jan 26, 2018
|
40
|
*
|
41
|
*/
|
42
|
@SpringComponent
|
43
|
@Scope("prototype")
|
44
|
public class NameTypeDesignationPopupEditor extends AbstractCdmPopupEditor<NameTypeDesignation, NameTypeDesignationPresenter>
|
45
|
implements NameTypeDesignationEditorView {
|
46
|
|
47
|
private static final int GRID_COLS = 4;
|
48
|
private static final int GRID_ROWS = 7;
|
49
|
|
50
|
private CheckBox conservedTypeField;
|
51
|
private CheckBox rejectedTypeField;
|
52
|
private CheckBox notDesignatedField;
|
53
|
|
54
|
private ToOneRelatedEntityCombobox<TaxonName> typeNameField;
|
55
|
|
56
|
private ToManyRelatedEntitiesComboboxSelect<TaxonName> typifiedNamesComboboxSelect;
|
57
|
|
58
|
private NativeSelect typeStatusSelect;
|
59
|
|
60
|
private ToOneRelatedEntityCombobox<Reference> citationCombobox;
|
61
|
|
62
|
private TextField citationDetailField;
|
63
|
|
64
|
private boolean showTypeFlags = true;
|
65
|
|
66
|
|
67
|
private FilterableAnnotationsField annotationsListField;
|
68
|
|
69
|
private AnnotationType[] editableAnotationTypes = RegistrationUIDefaults.EDITABLE_ANOTATION_TYPES;
|
70
|
|
71
|
|
72
|
/**
|
73
|
* @param layout
|
74
|
* @param dtoType
|
75
|
*/
|
76
|
public NameTypeDesignationPopupEditor() {
|
77
|
super(new GridLayout(GRID_COLS, GRID_ROWS), NameTypeDesignation.class);
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* {@inheritDoc}
|
82
|
*/
|
83
|
@Override
|
84
|
public String getWindowCaption() {
|
85
|
return "Name type designation editor";
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* {@inheritDoc}
|
90
|
*/
|
91
|
@Override
|
92
|
public void focusFirst() {
|
93
|
// none
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* {@inheritDoc}
|
98
|
*/
|
99
|
@Override
|
100
|
protected String getDefaultComponentStyles() {
|
101
|
return "tiny";
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* {@inheritDoc}
|
106
|
*/
|
107
|
@Override
|
108
|
protected void initContent() {
|
109
|
/*
|
110
|
conservedType : boolean
|
111
|
rejectedType : boolean
|
112
|
typeName : TaxonName
|
113
|
|
114
|
typifiedNames
|
115
|
notDesignated : boolean
|
116
|
registrations : Set<Registration>
|
117
|
typeStatus : T
|
118
|
|
119
|
citation : Reference
|
120
|
citationMicroReference : String
|
121
|
originalNameString : String
|
122
|
*/
|
123
|
|
124
|
GridLayout grid = (GridLayout)getFieldLayout();
|
125
|
// grid.setSizeFull();
|
126
|
grid.setSpacing(true);
|
127
|
grid.setColumnExpandRatio(0, 0.25f);
|
128
|
grid.setColumnExpandRatio(1, 0.25f);
|
129
|
grid.setColumnExpandRatio(2, 0.25f);
|
130
|
grid.setColumnExpandRatio(3, 0.25f);
|
131
|
|
132
|
int row = 0;
|
133
|
|
134
|
if(showTypeFlags){
|
135
|
conservedTypeField = addCheckBox("Conserved type", "conservedType", 0, row);
|
136
|
rejectedTypeField = addCheckBox("Rejected type", "rejectedType", 1, row);
|
137
|
notDesignatedField = addCheckBox("Not designated", "notDesignated", 2, row);
|
138
|
row++;
|
139
|
}
|
140
|
|
141
|
typeStatusSelect = new NativeSelect("Type status");
|
142
|
typeStatusSelect.setNullSelectionAllowed(false);
|
143
|
typeStatusSelect.setWidth(100, Unit.PERCENTAGE);
|
144
|
addField(typeStatusSelect, "typeStatus", 0, row, 1, row);
|
145
|
grid.setComponentAlignment(typeStatusSelect, Alignment.TOP_RIGHT);
|
146
|
|
147
|
row++;
|
148
|
typeNameField = new ToOneRelatedEntityCombobox<TaxonName>("Type name", TaxonName.class);
|
149
|
addField(typeNameField, "typeName", 0, row, 3, row);
|
150
|
typeNameField.addClickListenerAddEntity(e -> getViewEventBus().publish(this,
|
151
|
new TaxonNameEditorAction(
|
152
|
EditorActionType.ADD,
|
153
|
e.getButton(),
|
154
|
typeNameField,
|
155
|
this))
|
156
|
);
|
157
|
typeNameField.addClickListenerEditEntity(e -> {
|
158
|
if(typeNameField.getValue() != null){
|
159
|
getViewEventBus().publish(this,
|
160
|
new TaxonNameEditorAction(
|
161
|
EditorActionType.EDIT,
|
162
|
typeNameField.getValue().getUuid(),
|
163
|
e.getButton(),
|
164
|
typeNameField,
|
165
|
this)
|
166
|
);
|
167
|
}
|
168
|
});
|
169
|
|
170
|
row++;
|
171
|
typifiedNamesComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Typified names");
|
172
|
typifiedNamesComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
|
173
|
typifiedNamesComboboxSelect.setEditPermissionTester(new CdmEditDeletePermissionTester());
|
174
|
addField(typifiedNamesComboboxSelect, "typifiedNames", 0, row, 3, row);
|
175
|
typifiedNamesComboboxSelect.setReadOnly(false); // FIXME this does not help, see #7389
|
176
|
|
177
|
row++;
|
178
|
citationCombobox = new ToOneRelatedEntityCombobox<Reference>("Citation", Reference.class);
|
179
|
addField(citationCombobox, "citation", 0, row, 2, row);
|
180
|
citationCombobox.setWidth(400, Unit.PIXELS);
|
181
|
citationDetailField = addTextField("Citation detail", "citationMicroReference", 3, row);
|
182
|
|
183
|
row++;
|
184
|
annotationsListField = new FilterableAnnotationsField("Editorial notes");
|
185
|
annotationsListField.setWidth(100, Unit.PERCENTAGE);
|
186
|
boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
|
187
|
boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
|
188
|
if(isCurator || isAdmin){
|
189
|
annotationsListField.withNewButton(true);
|
190
|
} else {
|
191
|
annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
|
192
|
}
|
193
|
addField(annotationsListField, "annotations", 0, row, 3, row);
|
194
|
}
|
195
|
|
196
|
/**
|
197
|
* @return the typeNameField
|
198
|
*/
|
199
|
@Override
|
200
|
public ToOneRelatedEntityCombobox<TaxonName> getTypeNameField() {
|
201
|
return typeNameField;
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* @return the typifiedNamesComboboxSelect
|
206
|
*/
|
207
|
@Override
|
208
|
public ToManyRelatedEntitiesComboboxSelect<TaxonName> getTypifiedNamesComboboxSelect() {
|
209
|
return typifiedNamesComboboxSelect;
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* @return the typeStatusSelect
|
214
|
*/
|
215
|
@Override
|
216
|
public NativeSelect getTypeStatusSelect() {
|
217
|
return typeStatusSelect;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* @return the citationCombobox
|
222
|
*/
|
223
|
@Override
|
224
|
public ToOneRelatedEntityCombobox<Reference> getCitationCombobox() {
|
225
|
return citationCombobox;
|
226
|
}
|
227
|
|
228
|
|
229
|
/**
|
230
|
* @return the showTypeFlags
|
231
|
*/
|
232
|
@Override
|
233
|
public boolean isShowTypeFlags() {
|
234
|
return showTypeFlags;
|
235
|
}
|
236
|
|
237
|
/**
|
238
|
* @param showTypeFlags the showTypeFlags to set
|
239
|
*/
|
240
|
@Override
|
241
|
public void setShowTypeFlags(boolean showTypeFlags) {
|
242
|
this.showTypeFlags = showTypeFlags;
|
243
|
}
|
244
|
|
245
|
/**
|
246
|
* {@inheritDoc}
|
247
|
*/
|
248
|
@Override
|
249
|
public AnnotationType[] getEditableAnotationTypes() {
|
250
|
return editableAnotationTypes;
|
251
|
}
|
252
|
|
253
|
/**
|
254
|
* {@inheritDoc}
|
255
|
*/
|
256
|
@Override
|
257
|
public void setEditableAnotationTypes(AnnotationType... editableAnotationTypes) {
|
258
|
this.editableAnotationTypes = editableAnotationTypes;
|
259
|
}
|
260
|
|
261
|
/**
|
262
|
* {@inheritDoc}
|
263
|
*/
|
264
|
@Override
|
265
|
public FilterableAnnotationsField getAnnotationsField() {
|
266
|
return annotationsListField;
|
267
|
}
|
268
|
}
|