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.view.reference;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.EnumSet;
|
13
|
|
14
|
import org.springframework.context.annotation.Scope;
|
15
|
import org.springframework.security.core.GrantedAuthority;
|
16
|
|
17
|
import com.vaadin.spring.annotation.SpringComponent;
|
18
|
import com.vaadin.ui.Alignment;
|
19
|
import com.vaadin.ui.GridLayout;
|
20
|
import com.vaadin.ui.ListSelect;
|
21
|
import com.vaadin.ui.TextField;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
24
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
25
|
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
|
26
|
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
|
27
|
import eu.etaxonomy.cdm.vaadin.component.common.TimePeriodField;
|
28
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
29
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
30
|
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
|
31
|
import eu.etaxonomy.cdm.vaadin.util.converter.DoiConverter;
|
32
|
import eu.etaxonomy.cdm.vaadin.util.converter.UriConverter;
|
33
|
import eu.etaxonomy.vaadin.component.SwitchableTextField;
|
34
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
35
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
36
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
|
37
|
|
38
|
/**
|
39
|
* @author a.kohlbecker
|
40
|
* @since Apr 4, 2017
|
41
|
*
|
42
|
*/
|
43
|
@SpringComponent
|
44
|
@Scope("prototype")
|
45
|
public class ReferencePopupEditor extends AbstractCdmPopupEditor<Reference, ReferenceEditorPresenter> implements ReferencePopupEditorView, AccessRestrictedView {
|
46
|
|
47
|
private static final long serialVersionUID = -4347633563800758815L;
|
48
|
|
49
|
private TextField titleField;
|
50
|
|
51
|
private final static int GRID_COLS = 4;
|
52
|
|
53
|
private final static int GRID_ROWS = 10;
|
54
|
|
55
|
private ListSelect typeSelect;
|
56
|
|
57
|
private ToOneRelatedEntityCombobox<Reference> inReferenceCombobox;
|
58
|
|
59
|
private TeamOrPersonField authorshipField;
|
60
|
|
61
|
private EnumSet<ReferenceType> referenceTypes = EnumSet.allOf(ReferenceType.class);
|
62
|
|
63
|
/**
|
64
|
* @param layout
|
65
|
* @param dtoType
|
66
|
*/
|
67
|
public ReferencePopupEditor() {
|
68
|
super(new GridLayout(GRID_COLS, GRID_ROWS), Reference.class);
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
protected void initContent() {
|
73
|
GridLayout grid = (GridLayout)getFieldLayout();
|
74
|
grid.setSpacing(true);
|
75
|
grid.setMargin(true);
|
76
|
|
77
|
/*
|
78
|
"type",
|
79
|
"uri",
|
80
|
"abbrevTitleCache",
|
81
|
"protectedAbbrevTitleCache",
|
82
|
"nomenclaturallyRelevant",
|
83
|
"authorship",
|
84
|
"referenceAbstract",
|
85
|
"title",
|
86
|
"abbrevTitle",
|
87
|
"editor",
|
88
|
"volume",
|
89
|
"pages",
|
90
|
"edition",
|
91
|
"isbn",
|
92
|
"issn",
|
93
|
"doi",
|
94
|
"seriesPart",
|
95
|
"datePublished",
|
96
|
"publisher",
|
97
|
"placePublished",
|
98
|
"institution",
|
99
|
"school",
|
100
|
"organization",
|
101
|
"inReference"
|
102
|
*/
|
103
|
int row = 0;
|
104
|
typeSelect = new ListSelect("Reference type");
|
105
|
typeSelect.addItems(referenceTypes);
|
106
|
typeSelect.setNullSelectionAllowed(false);
|
107
|
typeSelect.setRows(1);
|
108
|
typeSelect.addValueChangeListener(e -> updateFieldVisibility((ReferenceType)e.getProperty().getValue()));
|
109
|
addField(typeSelect, "type", 3, row);
|
110
|
grid.setComponentAlignment(typeSelect, Alignment.TOP_RIGHT);
|
111
|
row++;
|
112
|
SwitchableTextField titleCacheField = addSwitchableTextField("Reference cache", "titleCache", "protectedTitleCache", 0, row, GRID_COLS-1, row);
|
113
|
titleCacheField.setWidth(100, Unit.PERCENTAGE);
|
114
|
row++;
|
115
|
SwitchableTextField abbrevTitleCacheField = addSwitchableTextField("Abbrev. cache", "abbrevTitleCache", "protectedAbbrevTitleCache", 0, row, GRID_COLS-1, row);
|
116
|
abbrevTitleCacheField.setWidth(100, Unit.PERCENTAGE);
|
117
|
row++;
|
118
|
titleField = addTextField("Title", "title", 0, row, GRID_COLS-1, row);
|
119
|
titleField.setWidth(100, Unit.PERCENTAGE);
|
120
|
row++;
|
121
|
addTextField("Nomenclatural title", "abbrevTitle", 0, row, GRID_COLS-1, row).setWidth(100, Unit.PERCENTAGE);
|
122
|
row++;
|
123
|
authorshipField = new TeamOrPersonField("Author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.BIBLIOGRAPHIC_TITLE);
|
124
|
authorshipField.setWidth(100, Unit.PERCENTAGE);
|
125
|
addField(authorshipField, "authorship", 0, row, 3, row);
|
126
|
row++;
|
127
|
addTextField("Series", "seriesPart", 0, row);
|
128
|
addTextField("Volume", "volume", 1, row);
|
129
|
addTextField("Pages", "pages", 2, row);
|
130
|
addTextField("Editor", "editor", 3, row).setWidth(100, Unit.PERCENTAGE);
|
131
|
row++;
|
132
|
|
133
|
inReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("In-reference", Reference.class);
|
134
|
inReferenceCombobox.setWidth(100, Unit.PERCENTAGE);
|
135
|
inReferenceCombobox.addClickListenerAddEntity(e -> getViewEventBus().publish(this,
|
136
|
new ReferenceEditorAction(EditorActionType.ADD, null, inReferenceCombobox, this)
|
137
|
));
|
138
|
inReferenceCombobox.addClickListenerEditEntity(e -> {
|
139
|
if(inReferenceCombobox.getValue() != null){
|
140
|
getViewEventBus().publish(this,
|
141
|
new ReferenceEditorAction(
|
142
|
EditorActionType.EDIT,
|
143
|
inReferenceCombobox.getValue().getUuid(),
|
144
|
inReferenceCombobox,
|
145
|
this)
|
146
|
);
|
147
|
}
|
148
|
});
|
149
|
addField(inReferenceCombobox, "inReference", 0, row, 3, row);
|
150
|
row++;
|
151
|
addTextField("Place published", "placePublished", 0, row, 1, row).setWidth(100, Unit.PERCENTAGE);
|
152
|
TextField publisherField = addTextField("Publisher", "publisher", 2, row, 3, row);
|
153
|
publisherField.setWidth(100, Unit.PERCENTAGE);
|
154
|
TimePeriodField timePeriodField = new TimePeriodField("Date published");
|
155
|
addField(timePeriodField, "datePublished");
|
156
|
row++;
|
157
|
addTextField("ISSN", "issn", 0, row);
|
158
|
addTextField("ISBN", "isbn", 1, row);
|
159
|
TextFieldNFix doiField = new TextFieldNFix("DOI");
|
160
|
doiField.setConverter(new DoiConverter());
|
161
|
addField(doiField, "doi", 2, row);
|
162
|
TextFieldNFix uriField = new TextFieldNFix("Uri");
|
163
|
uriField.setConverter(new UriConverter());
|
164
|
addField(uriField, "uri", 3, row);
|
165
|
|
166
|
// titleField.setRequired(true);
|
167
|
// publisherField.setRequired(true);
|
168
|
|
169
|
setAdvancedModeEnabled(true);
|
170
|
registerAdvancedModeComponents(titleCacheField, abbrevTitleCacheField);
|
171
|
registerAdvancedModeComponents(authorshipField.getCachFields());
|
172
|
setAdvancedMode(false);
|
173
|
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* @param value
|
178
|
* @return
|
179
|
*/
|
180
|
private Object updateFieldVisibility(ReferenceType value) {
|
181
|
getField("volume").setVisible(value.isVolumeReference());
|
182
|
|
183
|
getField("placePublished").setVisible(value.isPublication());
|
184
|
getField("publisher").setVisible(value.isPublication());
|
185
|
|
186
|
getField("editor").setVisible(value.isPrintedUnit());
|
187
|
getField("seriesPart").setVisible(value.isPrintedUnit());
|
188
|
|
189
|
getField("inReference").setVisible(value.isPrintedUnit() || value.isSection());
|
190
|
getField("pages").setVisible(value.isSection());
|
191
|
|
192
|
EnumSet<ReferenceType> hideNomTitle = EnumSet.of(ReferenceType.Article, ReferenceType.Section, ReferenceType.BookSection, ReferenceType.InProceedings, ReferenceType.PrintSeries);
|
193
|
EnumSet<ReferenceType> hideTitle = EnumSet.of(ReferenceType.Section, ReferenceType.BookSection);
|
194
|
getField("abbrevTitle").setVisible(!hideNomTitle.contains(value));
|
195
|
getField("title").setVisible(!hideTitle.contains(value));
|
196
|
|
197
|
return null;
|
198
|
}
|
199
|
|
200
|
/**
|
201
|
* {@inheritDoc}
|
202
|
*/
|
203
|
@Override
|
204
|
public String getWindowCaption() {
|
205
|
return "Reference editor";
|
206
|
}
|
207
|
|
208
|
/**
|
209
|
* {@inheritDoc}
|
210
|
*/
|
211
|
@Override
|
212
|
protected String getDefaultComponentStyles() {
|
213
|
return "tiny";
|
214
|
}
|
215
|
|
216
|
/**
|
217
|
* {@inheritDoc}
|
218
|
*/
|
219
|
@Override
|
220
|
public void focusFirst() {
|
221
|
titleField.focus();
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* {@inheritDoc}
|
226
|
*/
|
227
|
@Override
|
228
|
public boolean isResizable() {
|
229
|
return false;
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* {@inheritDoc}
|
234
|
*/
|
235
|
@Override
|
236
|
public boolean allowAnonymousAccess() {
|
237
|
return false;
|
238
|
}
|
239
|
|
240
|
/**
|
241
|
* {@inheritDoc}
|
242
|
*/
|
243
|
@Override
|
244
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
245
|
return null;
|
246
|
}
|
247
|
|
248
|
@Override
|
249
|
public ListSelect getTypeSelect() {
|
250
|
return typeSelect;
|
251
|
}
|
252
|
|
253
|
/**
|
254
|
* {@inheritDoc}
|
255
|
*/
|
256
|
@Override
|
257
|
public ToOneRelatedEntityCombobox<Reference> getInReferenceCombobox() {
|
258
|
return inReferenceCombobox;
|
259
|
}
|
260
|
|
261
|
/**
|
262
|
* {@inheritDoc}
|
263
|
*/
|
264
|
@Override
|
265
|
public TeamOrPersonField getAuthorshipField() {
|
266
|
return authorshipField;
|
267
|
}
|
268
|
|
269
|
public void withReferenceTypes(EnumSet<ReferenceType> types){
|
270
|
this.referenceTypes = types;
|
271
|
if(typeSelect != null){
|
272
|
typeSelect.removeAllItems();
|
273
|
typeSelect.addItems(referenceTypes);
|
274
|
}
|
275
|
}
|
276
|
|
277
|
|
278
|
}
|