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