/
AdminViewImpl.java
77 lines (63 loc) · 2.34 KB
/
AdminViewImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.vaadin.cdidemo.views.admin;
import java.util.stream.Stream;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.vaadin.cdidemo.VersionLabel;
import org.vaadin.cdidemo.data.User;
import com.vaadin.cdi.CDIView;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Label;
import com.vaadin.ui.UIDetachedException;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
@CDIView(AdminView.VIEW)
public class AdminViewImpl extends VerticalLayout implements AdminView, View {
@Inject
private AdminPresenter presenter;
@Inject
private VersionLabel versionLabel;
@Inject
private Logger logger;
private VerticalLayout userContainer = new VerticalLayout();
public AdminViewImpl() {
setSizeFull();
}
@PostConstruct
private void init() {
presenter.setView(this);
userContainer.setSizeFull();
Label loading = new Label();
loading.setStyleName(ValoTheme.LABEL_SPINNER);
userContainer.addComponent(loading);
userContainer.setComponentAlignment(loading, Alignment.MIDDLE_CENTER);
addComponents(userContainer, versionLabel);
setComponentAlignment(versionLabel, Alignment.BOTTOM_RIGHT);
}
// Update users in ui.access() since this method will be called from
// background thread, we will avoid using threads in View classes and
// use them in Presenter or Model instead
public void updateUsers(Stream<User> users) {
try {
getUI().access(() -> {
userContainer.removeAllComponents();
users.forEach(user -> {
UserForm userForm = new UserForm(user);
userContainer.addComponent(userForm);
userContainer.setComponentAlignment(userForm,
Alignment.MIDDLE_CENTER);
});
});
} catch (UIDetachedException e) {
logger.info("Browser was closed, updates not pushed");
}
}
@Override
public void enter(ViewChangeEvent event) {
presenter.handlePrivilegesAndLoggedIn();
// Ask presenter to start process of updating user list
presenter.requestUpdateUsers();
}
}