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.occurrence;
|
10
|
|
11
|
import org.springframework.context.annotation.Scope;
|
12
|
import org.springframework.security.core.GrantedAuthority;
|
13
|
|
14
|
import com.vaadin.spring.annotation.SpringComponent;
|
15
|
import com.vaadin.ui.GridLayout;
|
16
|
import com.vaadin.ui.TextField;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.utility.RoleProber;
|
19
|
import eu.etaxonomy.cdm.api.utility.UserHelper;
|
20
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
22
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
23
|
import eu.etaxonomy.cdm.vaadin.event.CollectionEditorAction;
|
24
|
import eu.etaxonomy.cdm.vaadin.event.InstitutionEditorAction;
|
25
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
|
26
|
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
|
27
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
28
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
29
|
import eu.etaxonomy.cdm.vaadin.util.CollectionCaptionGenerator;
|
30
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
31
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
32
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
|
33
|
|
34
|
/**
|
35
|
* @author a.kohlbecker
|
36
|
* @since Dec 21, 2017
|
37
|
*
|
38
|
*/
|
39
|
@SpringComponent
|
40
|
@Scope("prototype")
|
41
|
public class CollectionPopupEditor extends AbstractCdmPopupEditor<Collection, CollectionEditorPresenter> implements CollectionPopupEditorView, AccessRestrictedView {
|
42
|
|
43
|
private static final long serialVersionUID = 2019724189877425882L;
|
44
|
|
45
|
private static final int GRID_COLS = 3;
|
46
|
|
47
|
private static final int GRID_ROWS = 4;
|
48
|
|
49
|
TextField codeField;
|
50
|
TextField codeStandardField;
|
51
|
TextField townOrLocationField;
|
52
|
ToOneRelatedEntityCombobox<Collection> superCollectionCombobox;
|
53
|
ToOneRelatedEntityCombobox<Institution> institutionCombobox;
|
54
|
|
55
|
|
56
|
/**
|
57
|
* @param layout
|
58
|
* @param dtoType
|
59
|
*/
|
60
|
public CollectionPopupEditor() {
|
61
|
super(new GridLayout(GRID_COLS, GRID_ROWS), Collection.class);
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* {@inheritDoc}
|
66
|
*/
|
67
|
@Override
|
68
|
public String getWindowCaption() {
|
69
|
return "Collection editor";
|
70
|
}
|
71
|
|
72
|
|
73
|
|
74
|
/**
|
75
|
* {@inheritDoc}
|
76
|
*/
|
77
|
@Override
|
78
|
public int getWindowWidth() {
|
79
|
return 500;
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* {@inheritDoc}
|
84
|
*/
|
85
|
@Override
|
86
|
public void focusFirst() {
|
87
|
codeField.focus();
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* {@inheritDoc}
|
92
|
*/
|
93
|
@Override
|
94
|
public boolean allowAnonymousAccess() {
|
95
|
return false;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* {@inheritDoc}
|
100
|
*/
|
101
|
@Override
|
102
|
public java.util.Collection<java.util.Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
103
|
return null;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* {@inheritDoc}
|
108
|
*/
|
109
|
@Override
|
110
|
protected String getDefaultComponentStyles() {
|
111
|
return "tiny";
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* {@inheritDoc}
|
116
|
*/
|
117
|
@Override
|
118
|
protected void initContent() {
|
119
|
/*
|
120
|
code : String
|
121
|
codeStandard : String
|
122
|
name : String
|
123
|
townOrLocation : String
|
124
|
institute : Institution
|
125
|
superCollection : Collection
|
126
|
*/
|
127
|
GridLayout grid = (GridLayout)getFieldLayout();
|
128
|
grid.setSizeFull();
|
129
|
grid.setSpacing(true);
|
130
|
// grid.setColumnExpandRatio(0, 0.3f);
|
131
|
// grid.setColumnExpandRatio(1, 0.3f);
|
132
|
// grid.setColumnExpandRatio(2, 0.3f);
|
133
|
// grid.setColumnExpandRatio(3, 0.0f);
|
134
|
|
135
|
int row = 0;
|
136
|
codeField = addTextField("Code", "code", 0, row, 0, row);
|
137
|
codeField.setWidth(100, Unit.PIXELS);
|
138
|
|
139
|
codeStandardField = addTextField("Code standard", "codeStandard", 1, row, 1, row);
|
140
|
codeStandardField.setWidth(100, Unit.PIXELS);
|
141
|
|
142
|
townOrLocationField = addTextField("Town or location", "townOrLocation", 2, row, 2, row);
|
143
|
townOrLocationField.setWidth(100, Unit.PIXELS);
|
144
|
|
145
|
row++;
|
146
|
superCollectionCombobox = new ToOneRelatedEntityCombobox<Collection>("Super-collection", Collection.class);
|
147
|
|
148
|
|
149
|
superCollectionCombobox.setWidth(300, Unit.PIXELS);
|
150
|
addField(superCollectionCombobox, "superCollection", 0, row, 1, row);
|
151
|
|
152
|
superCollectionCombobox.getSelect().setCaptionGenerator(
|
153
|
new CollectionCaptionGenerator()
|
154
|
);
|
155
|
superCollectionCombobox.setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater<Collection>(superCollectionCombobox));
|
156
|
|
157
|
superCollectionCombobox.addClickListenerAddEntity( e -> getViewEventBus().publish(this,
|
158
|
new CollectionEditorAction(
|
159
|
EditorActionType.ADD,
|
160
|
null,
|
161
|
superCollectionCombobox,
|
162
|
this)
|
163
|
));
|
164
|
superCollectionCombobox.addClickListenerEditEntity(e -> {
|
165
|
if(superCollectionCombobox.getValue() != null){
|
166
|
getViewEventBus().publish(this,
|
167
|
new CollectionEditorAction(
|
168
|
EditorActionType.EDIT,
|
169
|
superCollectionCombobox.getValue().getUuid(),
|
170
|
e.getButton(),
|
171
|
superCollectionCombobox,
|
172
|
this
|
173
|
)
|
174
|
);
|
175
|
}
|
176
|
});
|
177
|
|
178
|
UserHelper userHelper = UserHelperAccess.userHelper();
|
179
|
superCollectionCombobox.setVisible(RegistrationUIDefaults.COLLECTION_EDITOR_SUB_COLLECTION_VISIBILITY_RESTRICTION.stream().anyMatch( role -> userHelper.userIs(new RoleProber(role))));
|
180
|
|
181
|
row++;
|
182
|
institutionCombobox = new ToOneRelatedEntityCombobox<Institution>("Institute", Institution.class);
|
183
|
addField(institutionCombobox, "institute", 0, row, 1, row);
|
184
|
|
185
|
institutionCombobox.getSelect().setCaptionGenerator(
|
186
|
new CdmTitleCacheCaptionGenerator<Institution>()
|
187
|
);
|
188
|
institutionCombobox.setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater<Institution>(institutionCombobox));
|
189
|
|
190
|
institutionCombobox.addClickListenerAddEntity( e -> getViewEventBus().publish(this,
|
191
|
new InstitutionEditorAction(
|
192
|
EditorActionType.ADD,
|
193
|
null,
|
194
|
institutionCombobox,
|
195
|
this)
|
196
|
));
|
197
|
institutionCombobox.addClickListenerEditEntity(e -> {
|
198
|
if(institutionCombobox.getValue() != null){
|
199
|
getViewEventBus().publish(this,
|
200
|
new InstitutionEditorAction(
|
201
|
EditorActionType.EDIT,
|
202
|
institutionCombobox.getValue().getUuid(),
|
203
|
e.getButton(),
|
204
|
institutionCombobox,
|
205
|
this
|
206
|
)
|
207
|
);
|
208
|
}
|
209
|
});
|
210
|
|
211
|
}
|
212
|
|
213
|
/* ------------------ View Interface methods -------------------- */
|
214
|
@Override
|
215
|
public ToOneRelatedEntityCombobox<Collection> getSuperCollectionCombobox() {
|
216
|
return superCollectionCombobox;
|
217
|
}
|
218
|
|
219
|
@Override
|
220
|
public ToOneRelatedEntityCombobox<Institution> getInstitutionCombobox() {
|
221
|
return institutionCombobox;
|
222
|
}
|
223
|
|
224
|
}
|