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