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