1 |
ec462234
|
Andreas Kohlbecker
|
/**
|
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.phycobank;
|
10 |
|
|
|
11 |
|
|
import java.util.Collection;
|
12 |
|
|
import java.util.Locale;
|
13 |
|
|
|
14 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
15 |
|
|
|
16 |
|
|
import com.vaadin.data.Item;
|
17 |
|
|
import com.vaadin.data.util.BeanContainer;
|
18 |
|
|
import com.vaadin.data.util.GeneratedPropertyContainer;
|
19 |
|
|
import com.vaadin.data.util.PropertyValueGenerator;
|
20 |
|
|
import com.vaadin.data.util.converter.Converter;
|
21 |
|
|
import com.vaadin.navigator.View;
|
22 |
|
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
23 |
|
|
import com.vaadin.server.FontAwesome;
|
24 |
af8569f7
|
Andreas Kohlbecker
|
import com.vaadin.shared.ui.grid.HeightMode;
|
25 |
ec462234
|
Andreas Kohlbecker
|
import com.vaadin.spring.annotation.SpringView;
|
26 |
|
|
import com.vaadin.ui.Alignment;
|
27 |
|
|
import com.vaadin.ui.Grid;
|
28 |
|
|
import com.vaadin.ui.Grid.Column;
|
29 |
|
|
import com.vaadin.ui.Grid.SelectionMode;
|
30 |
|
|
import com.vaadin.ui.Label;
|
31 |
|
|
import com.vaadin.ui.VerticalLayout;
|
32 |
|
|
import com.vaadin.ui.renderers.ButtonRenderer;
|
33 |
|
|
import com.vaadin.ui.renderers.DateRenderer;
|
34 |
|
|
import com.vaadin.ui.renderers.HtmlRenderer;
|
35 |
|
|
import com.vaadin.ui.themes.ValoTheme;
|
36 |
|
|
|
37 |
|
|
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.ListPresenter;
|
38 |
|
|
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.ListPresenter.RegistrationDTO;
|
39 |
|
|
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationType;
|
40 |
|
|
import eu.etaxonomy.cdm.vaadin.util.JodaDateTimeConverter;
|
41 |
|
|
import eu.etaxonomy.cdm.vaadin.util.UrlStringConverter;
|
42 |
|
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
43 |
|
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* @author a.kohlbecker
|
47 |
|
|
* @since Mar 2, 2017
|
48 |
|
|
*
|
49 |
|
|
*/
|
50 |
|
|
@SpringView(name=ListViewBean.NAME)
|
51 |
|
|
public class ListViewBean extends AbstractView<ListPresenter> implements ListView, View {
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* @author a.kohlbecker
|
55 |
|
|
* @since Mar 7, 2017
|
56 |
|
|
*
|
57 |
|
|
*/
|
58 |
|
|
protected final class RegistrationTypeConverter implements Converter<String, RegistrationType> {
|
59 |
|
|
@Override
|
60 |
|
|
public RegistrationType convertToModel(String value, Class<? extends RegistrationType> targetType,
|
61 |
|
|
Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException {
|
62 |
|
|
// not implemented
|
63 |
|
|
return null;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
@Override
|
67 |
|
|
public String convertToPresentation(RegistrationType value, Class<? extends String> targetType,
|
68 |
|
|
Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException {
|
69 |
|
|
if(value.equals(RegistrationType.name)) {
|
70 |
|
|
return FontAwesome.TAG.getHtml();
|
71 |
|
|
}
|
72 |
|
|
if(value.equals(RegistrationType.name)) {
|
73 |
|
|
return FontAwesome.TAGS.getHtml();
|
74 |
|
|
}
|
75 |
|
|
return FontAwesome.WARNING.getHtml();
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
@Override
|
79 |
|
|
public Class<RegistrationType> getModelType() {
|
80 |
|
|
return RegistrationType.class;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
@Override
|
84 |
|
|
public Class<String> getPresentationType() {
|
85 |
|
|
return String.class;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
private static final long serialVersionUID = 3543300933072824713L;
|
89 |
|
|
|
90 |
|
|
public static final String NAME = "list";
|
91 |
|
|
|
92 |
|
|
private VerticalLayout layout;
|
93 |
|
|
|
94 |
|
|
private Grid grid;
|
95 |
|
|
|
96 |
|
|
public ListViewBean() {
|
97 |
|
|
layout = new VerticalLayout();
|
98 |
|
|
layout.setSpacing(true);
|
99 |
af8569f7
|
Andreas Kohlbecker
|
layout.setSizeFull();
|
100 |
ec462234
|
Andreas Kohlbecker
|
|
101 |
|
|
Label title = new Label("Registrations");
|
102 |
|
|
title.setStyleName(ValoTheme.LABEL_HUGE);
|
103 |
af8569f7
|
Andreas Kohlbecker
|
title.setWidthUndefined();
|
104 |
ec462234
|
Andreas Kohlbecker
|
layout.addComponent(title);
|
105 |
|
|
layout.setComponentAlignment(title, Alignment.TOP_CENTER);
|
106 |
|
|
|
107 |
|
|
Label hint = new Label("This is the list of all your registrations in progress.");
|
108 |
af8569f7
|
Andreas Kohlbecker
|
hint.setWidthUndefined();
|
109 |
ec462234
|
Andreas Kohlbecker
|
layout.addComponent(hint);
|
110 |
|
|
layout.setComponentAlignment(hint, Alignment.MIDDLE_CENTER);
|
111 |
|
|
|
112 |
|
|
grid = buildGrid();
|
113 |
|
|
layout.addComponent(grid);
|
114 |
af8569f7
|
Andreas Kohlbecker
|
layout.setExpandRatio(grid, 1);
|
115 |
ec462234
|
Andreas Kohlbecker
|
|
116 |
|
|
setCompositionRoot(layout);
|
117 |
af8569f7
|
Andreas Kohlbecker
|
this.setSizeFull();
|
118 |
ec462234
|
Andreas Kohlbecker
|
}
|
119 |
|
|
|
120 |
|
|
private Grid buildGrid() {
|
121 |
|
|
Grid grid = new Grid();
|
122 |
|
|
grid.setSizeFull();
|
123 |
|
|
grid.setEditorEnabled(false);
|
124 |
|
|
grid.setId("registration-list");
|
125 |
|
|
grid.setCellStyleGenerator(cellRef -> cellRef.getPropertyId().toString());
|
126 |
|
|
grid.setSelectionMode(SelectionMode.NONE);
|
127 |
af8569f7
|
Andreas Kohlbecker
|
grid.setHeightMode(HeightMode.CSS);
|
128 |
ec462234
|
Andreas Kohlbecker
|
// add status as class attribute to the rows to allow styling with css
|
129 |
|
|
grid.setRowStyleGenerator(rowRef -> {return "status-" + rowRef.getItem().getItemProperty("status").getValue().toString();});
|
130 |
|
|
return grid;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
/**
|
134 |
|
|
* {@inheritDoc}
|
135 |
|
|
*/
|
136 |
|
|
@Override
|
137 |
|
|
public void enter(ViewChangeEvent event) {
|
138 |
|
|
getPresenter().onViewEnter();
|
139 |
|
|
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
/**
|
143 |
|
|
* {@inheritDoc}
|
144 |
|
|
*/
|
145 |
|
|
@Override
|
146 |
|
|
@Autowired
|
147 |
|
|
protected void injectPresenter(ListPresenter presenter) {
|
148 |
|
|
setPresenter(presenter);
|
149 |
|
|
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
static final String[] visiblCols = new String[]{"status, summary", "registrationId"};
|
153 |
|
|
/**
|
154 |
|
|
* {@inheritDoc}
|
155 |
|
|
*/
|
156 |
|
|
@Override
|
157 |
|
|
public void populateTable(Collection<RegistrationDTO> registrations) {
|
158 |
|
|
|
159 |
|
|
BeanContainer<String, RegistrationDTO> registrationItems = new BeanContainer<String, RegistrationDTO>(RegistrationDTO.class);
|
160 |
|
|
registrationItems.setBeanIdProperty("internalRegId");
|
161 |
|
|
registrationItems.addAll(registrations);
|
162 |
|
|
|
163 |
|
|
grid.setContainerDataSource(buildGeneratedProperties(registrationItems));
|
164 |
|
|
|
165 |
|
|
grid.removeAllColumns();
|
166 |
|
|
|
167 |
|
|
Column typeColumn = grid.addColumn("registrationType");
|
168 |
|
|
typeColumn.setRenderer(new HtmlRenderer(), new RegistrationTypeConverter());
|
169 |
|
|
typeColumn.setHeaderCaption("");
|
170 |
|
|
typeColumn.setExpandRatio(0);
|
171 |
|
|
|
172 |
|
|
Column statusColumn = grid.addColumn("status");
|
173 |
|
|
statusColumn.setExpandRatio(0);
|
174 |
|
|
|
175 |
|
|
Column summaryColumn = grid.addColumn("summary");
|
176 |
|
|
summaryColumn.setExpandRatio(1);
|
177 |
|
|
|
178 |
|
|
Column regidColumn = grid.addColumn("registrationId");
|
179 |
|
|
regidColumn.setHeaderCaption("Id");
|
180 |
|
|
regidColumn.setRenderer(new HtmlRenderer(), new UrlStringConverter());
|
181 |
|
|
|
182 |
|
|
Column createdColumn = grid.addColumn("created");
|
183 |
|
|
createdColumn.setRenderer(new DateRenderer(), new JodaDateTimeConverter());
|
184 |
|
|
createdColumn.setHidable(true);
|
185 |
|
|
createdColumn.setHidden(true);
|
186 |
|
|
|
187 |
|
|
Column regDateColumn = grid.addColumn("registrationDate");
|
188 |
|
|
// regDateColumn.setHeaderCaption("Date");
|
189 |
|
|
regDateColumn.setRenderer(new DateRenderer(), new JodaDateTimeConverter());
|
190 |
|
|
regDateColumn.setHidable(true);
|
191 |
|
|
regDateColumn.setHidden(true);
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
Column buttonColumn = grid.addColumn("operation");
|
195 |
|
|
buttonColumn.setRenderer(new ButtonRenderer(e -> eventBus.publishEvent(new NavigationEvent(
|
196 |
|
|
RegistrationWorkflowViewBean.NAME,
|
197 |
|
|
RegistrationWorkflowViewBean.ACTION_EDIT,
|
198 |
|
|
e.getItemId().toString()
|
199 |
|
|
))));
|
200 |
|
|
buttonColumn.setSortable(false);
|
201 |
|
|
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
/**
|
205 |
|
|
* @param registrationItems
|
206 |
|
|
* @return
|
207 |
|
|
*/
|
208 |
|
|
private GeneratedPropertyContainer buildGeneratedProperties(
|
209 |
|
|
BeanContainer<String, RegistrationDTO> registrationItems) {
|
210 |
|
|
GeneratedPropertyContainer gpContainer = new GeneratedPropertyContainer(registrationItems);
|
211 |
|
|
|
212 |
|
|
gpContainer.addGeneratedProperty("operation", new PropertyValueGenerator<String>() {
|
213 |
|
|
|
214 |
|
|
@Override
|
215 |
|
|
public String getValue(Item item, Object itemId, Object propertyId) {
|
216 |
89cff4b7
|
Andreas Kohlbecker
|
return "Open";
|
217 |
ec462234
|
Andreas Kohlbecker
|
}
|
218 |
|
|
|
219 |
|
|
@Override
|
220 |
|
|
public Class<String> getType() {
|
221 |
|
|
return String.class;
|
222 |
|
|
}
|
223 |
|
|
});
|
224 |
|
|
|
225 |
|
|
return gpContainer;
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
}
|