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.registration;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
|
17
|
import com.vaadin.data.Item;
|
18
|
import com.vaadin.data.util.BeanContainer;
|
19
|
import com.vaadin.data.util.GeneratedPropertyContainer;
|
20
|
import com.vaadin.data.util.PropertyValueGenerator;
|
21
|
import com.vaadin.navigator.View;
|
22
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
23
|
import com.vaadin.server.Page;
|
24
|
import com.vaadin.shared.ui.grid.HeightMode;
|
25
|
import com.vaadin.spring.annotation.SpringView;
|
26
|
import com.vaadin.ui.Button;
|
27
|
import com.vaadin.ui.Button.ClickEvent;
|
28
|
import com.vaadin.ui.Component;
|
29
|
import com.vaadin.ui.CssLayout;
|
30
|
import com.vaadin.ui.Grid;
|
31
|
import com.vaadin.ui.Grid.Column;
|
32
|
import com.vaadin.ui.Grid.SelectionMode;
|
33
|
import com.vaadin.ui.Notification;
|
34
|
import com.vaadin.ui.renderers.ButtonRenderer;
|
35
|
import com.vaadin.ui.renderers.DateRenderer;
|
36
|
import com.vaadin.ui.renderers.HtmlRenderer;
|
37
|
|
38
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
|
39
|
import eu.etaxonomy.cdm.vaadin.util.JodaDateTimeConverter;
|
40
|
import eu.etaxonomy.cdm.vaadin.util.UrlStringConverter;
|
41
|
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
|
42
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
43
|
|
44
|
/**
|
45
|
* @author a.kohlbecker
|
46
|
* @since Mar 2, 2017
|
47
|
*
|
48
|
*/
|
49
|
@SpringView(name=ListViewBean.NAME)
|
50
|
public class ListViewBean extends AbstractPageView<ListPresenter> implements ListView, View {
|
51
|
|
52
|
private static final long serialVersionUID = 3543300933072824713L;
|
53
|
|
54
|
public static final String NAME = "list";
|
55
|
|
56
|
private CssLayout listContainer;
|
57
|
|
58
|
private Grid grid;
|
59
|
|
60
|
private CssLayout toolBar;
|
61
|
|
62
|
public ListViewBean() {
|
63
|
|
64
|
super();
|
65
|
|
66
|
toolBar = new CssLayout();
|
67
|
toolBar.setWidth(100, Unit.PERCENTAGE);
|
68
|
toolBar.addComponent(new Button("As grid", e -> toggleListType(e)));
|
69
|
getLayout().addComponent(toolBar);
|
70
|
|
71
|
buildList();
|
72
|
buildGrid();
|
73
|
|
74
|
showList();
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
protected String getHeaderText() {
|
79
|
return "Registrations";
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
protected String getSubHeaderText() {
|
84
|
return "This is the list of all your registrations in progress.";
|
85
|
}
|
86
|
|
87
|
private void buildList() {
|
88
|
listContainer = new CssLayout();
|
89
|
listContainer.setId("registration-list");
|
90
|
listContainer.setWidth(100, Unit.PERCENTAGE);
|
91
|
}
|
92
|
|
93
|
private void buildGrid() {
|
94
|
grid = new Grid();
|
95
|
grid.setSizeFull();
|
96
|
grid.setEditorEnabled(false);
|
97
|
grid.setId("registration-list");
|
98
|
grid.setCellStyleGenerator(cellRef -> cellRef.getPropertyId().toString());
|
99
|
grid.setSelectionMode(SelectionMode.NONE);
|
100
|
grid.setHeightMode(HeightMode.CSS);
|
101
|
// add status as class attribute to the rows to allow styling with css
|
102
|
grid.setRowStyleGenerator(rowRef -> {return "status-" + rowRef.getItem().getItemProperty("status").getValue().toString();});
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* @param e
|
107
|
* @return
|
108
|
*/
|
109
|
private Object toggleListType(ClickEvent e) {
|
110
|
Button button = e.getButton();
|
111
|
if(button.getCaption().equals("As grid")){
|
112
|
button.setCaption("As list");
|
113
|
showGrid();
|
114
|
} else {
|
115
|
button.setCaption("As grid");
|
116
|
showList();
|
117
|
}
|
118
|
return null;
|
119
|
}
|
120
|
|
121
|
private void showList() {
|
122
|
if(grid != null){
|
123
|
getLayout().removeComponent(grid);
|
124
|
}
|
125
|
getLayout().addComponent(listContainer);
|
126
|
}
|
127
|
|
128
|
private void showGrid() {
|
129
|
if(listContainer != null){
|
130
|
getLayout().removeComponent(listContainer);
|
131
|
}
|
132
|
getLayout().addComponent(grid);
|
133
|
}
|
134
|
|
135
|
|
136
|
/**
|
137
|
* {@inheritDoc}
|
138
|
*/
|
139
|
@Override
|
140
|
public void enter(ViewChangeEvent event) {
|
141
|
getPresenter().onViewEnter();
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* {@inheritDoc}
|
146
|
*/
|
147
|
@Override
|
148
|
@Autowired
|
149
|
protected void injectPresenter(ListPresenter presenter) {
|
150
|
setPresenter(presenter);
|
151
|
}
|
152
|
|
153
|
@Override
|
154
|
public void populate(Collection<RegistrationDTO> registrations) {
|
155
|
|
156
|
registrations = new ArrayList<RegistrationDTO>(registrations).subList(0, 10);
|
157
|
|
158
|
populateGrid(registrations);
|
159
|
populateList(registrations);
|
160
|
}
|
161
|
|
162
|
|
163
|
public void populateGrid(Collection<RegistrationDTO> registrations) {
|
164
|
|
165
|
BeanContainer<String, RegistrationDTO> registrationItems = new BeanContainer<String, RegistrationDTO>(RegistrationDTO.class);
|
166
|
registrationItems.setBeanIdProperty("specificIdentifier");
|
167
|
registrationItems.addAll(registrations);
|
168
|
|
169
|
grid.setContainerDataSource(buildGeneratedProperties(registrationItems));
|
170
|
|
171
|
grid.removeAllColumns();
|
172
|
|
173
|
Column typeColumn = grid.addColumn("registrationType");
|
174
|
typeColumn.setRenderer(new HtmlRenderer(), new RegistrationTypeConverter());
|
175
|
typeColumn.setHeaderCaption("");
|
176
|
|
177
|
Column statusColumn = grid.addColumn("status");
|
178
|
|
179
|
Column citationColumn = grid.addColumn("citation");
|
180
|
citationColumn.setHeaderCaption("Publication");
|
181
|
|
182
|
|
183
|
Column summaryColumn = grid.addColumn("summary");
|
184
|
|
185
|
Column regidColumn = grid.addColumn("identifier");
|
186
|
regidColumn.setHeaderCaption("Id");
|
187
|
regidColumn.setRenderer(new HtmlRenderer(), new UrlStringConverter("http://pyhcobank.org/"));
|
188
|
|
189
|
Column createdColumn = grid.addColumn("created");
|
190
|
createdColumn.setRenderer(new DateRenderer(), new JodaDateTimeConverter());
|
191
|
createdColumn.setHidable(true);
|
192
|
createdColumn.setHidden(true);
|
193
|
|
194
|
Column regDateColumn = grid.addColumn("registrationDate");
|
195
|
// regDateColumn.setHeaderCaption("Date");
|
196
|
regDateColumn.setRenderer(new DateRenderer(), new JodaDateTimeConverter());
|
197
|
regDateColumn.setHidable(true);
|
198
|
regDateColumn.setHidden(true);
|
199
|
|
200
|
|
201
|
Column buttonColumn = grid.addColumn("operation");
|
202
|
buttonColumn.setRenderer(new ButtonRenderer(e -> eventBus.publishEvent(new NavigationEvent(
|
203
|
RegistrationWorkflowViewBean.NAME,
|
204
|
RegistrationWorkflowViewBean.ACTION_EDIT,
|
205
|
e.getItemId().toString()
|
206
|
))));
|
207
|
buttonColumn.setSortable(false);
|
208
|
|
209
|
grid.setFrozenColumnCount(1);
|
210
|
|
211
|
}
|
212
|
|
213
|
|
214
|
public void populateList(Collection<RegistrationDTO> registrations) {
|
215
|
|
216
|
for(RegistrationDTO regDto : registrations) {
|
217
|
Component item = new RegistrationItem(regDto, this);
|
218
|
item.setWidth(100, Unit.PERCENTAGE);
|
219
|
listContainer.addComponent(item);
|
220
|
}
|
221
|
}
|
222
|
|
223
|
@Override
|
224
|
public void openDetailsPopup(String caption, List<String> messages){
|
225
|
StringBuffer sb = new StringBuffer();
|
226
|
sb.append("<div class=\"details-popup-content\">");
|
227
|
messages.forEach(s -> sb.append(s).append("</br>"));
|
228
|
sb.append("</div>");
|
229
|
new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* @param registrationItems
|
234
|
* @return
|
235
|
*/
|
236
|
private GeneratedPropertyContainer buildGeneratedProperties(
|
237
|
BeanContainer<String, RegistrationDTO> registrationItems) {
|
238
|
GeneratedPropertyContainer gpContainer = new GeneratedPropertyContainer(registrationItems);
|
239
|
|
240
|
gpContainer.addGeneratedProperty("operation", new PropertyValueGenerator<String>() {
|
241
|
|
242
|
@Override
|
243
|
public String getValue(Item item, Object itemId, Object propertyId) {
|
244
|
return "Open";
|
245
|
}
|
246
|
|
247
|
@Override
|
248
|
public Class<String> getType() {
|
249
|
return String.class;
|
250
|
}
|
251
|
});
|
252
|
|
253
|
return gpContainer;
|
254
|
}
|
255
|
|
256
|
|
257
|
|
258
|
}
|