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