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