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 package info.magnolia.poc;
35
36 import info.magnolia.icons.MagnoliaIcons;
37 import info.magnolia.poc.customer.Customer;
38 import info.magnolia.poc.customer.CustomerStatusRenderer;
39 import info.magnolia.poc.customer.CustomerService;
40
41 import java.util.List;
42
43 import javax.servlet.annotation.WebServlet;
44
45 import org.jsoup.Jsoup;
46 import org.jsoup.safety.Whitelist;
47
48 import com.vaadin.annotations.Theme;
49 import com.vaadin.annotations.Title;
50 import com.vaadin.annotations.VaadinServletConfiguration;
51 import com.vaadin.annotations.Widgetset;
52 import com.vaadin.contextmenu.ContextMenu;
53 import com.vaadin.icons.VaadinIcons;
54 import com.vaadin.server.VaadinRequest;
55 import com.vaadin.server.VaadinServlet;
56 import com.vaadin.ui.Grid;
57 import com.vaadin.ui.Grid.SelectionMode;
58 import com.vaadin.ui.HorizontalLayout;
59 import com.vaadin.ui.UI;
60 import com.vaadin.ui.VerticalLayout;
61 import com.vaadin.ui.components.grid.ItemClickListener;
62 import com.vaadin.ui.renderers.HtmlRenderer;
63
64 @Theme("poctheme")
65 @Title("Magnolia 6 Resurface")
66 @Widgetset("info.magnolia.poc.Widgetset")
67 public class ListGridUI extends UI {
68
69 @WebServlet(value = "/list/*", asyncSupported = true)
70 @VaadinServletConfiguration(productionMode = false, ui = ListGridUI.class)
71 public static class Servlet extends VaadinServlet {
72 }
73
74 private Grid<Customer> listSelect = new Grid<>();
75 private CustomerService service = CustomerService.getInstance();
76
77 @Override
78 protected void init(VaadinRequest request) {
79 final VerticalLayout layout = new VerticalLayout();
80 layout.setSpacing(false);
81 HorizontalLayout main = new HorizontalLayout(listSelect);
82 main.setSizeFull();
83 listSelect.setSizeFull();
84
85 listSelect.addColumn(customer -> {
86 String iconHtml;
87 if (customer.isPersisted()) {
88 iconHtml = VaadinIcons.FOLDER_O.getHtml();
89 } else {
90 iconHtml = VaadinIcons.FILE_O.getHtml();
91 }
92 return iconHtml + " " + Jsoup.clean(customer.getLastName(), Whitelist.simpleText());
93 }, new HtmlRenderer()).setCaption("Last Name").setExpandRatio(5);
94 listSelect.addColumn(Customer::getFirstName).setCaption("First Name").setExpandRatio(2);
95 listSelect.addColumn(customer -> customer.getStatus().name(), new CustomerStatusRenderer()).setCaption("Status").setExpandRatio(0);
96 listSelect.addColumn(Customer::getBirthDate).setCaption("Date of Birth").setExpandRatio(2);
97 listSelect.addColumn(Customer::getEmail).setCaption("Email").setExpandRatio(2);
98
99 listSelect.setSelectionMode(SelectionMode.MULTI);
100
101 listSelect.addItemClickListener((ItemClickListener<Customer>) event -> {
102 if (event.getSource().getSelectionModel().isSelected(event.getItem())) {
103 event.getSource().getSelectionModel().deselect(event.getItem());
104 } else {
105 event.getSource().getSelectionModel().select(event.getItem());
106 }
107 });
108
109 main.setExpandRatio(listSelect, 1);
110 layout.addComponents(main);
111
112
113 updateList();
114
115 ContextMenu contextMenu = new ContextMenu(this, false);
116 contextMenu.setAsContextMenuOf(layout);
117 contextMenu.addItem("Upload asset", MagnoliaIcons.UPLOAD, null);
118 contextMenu.addItem("Upload Zip archive", MagnoliaIcons.UPLOAD, null);
119 contextMenu.addItem("Add folder", MagnoliaIcons.ADD_FOLDER, null);
120 contextMenu.addItem("Delete folder", MagnoliaIcons.DELETE, null);
121 contextMenu.addItem("Publish incl. subnodes", MagnoliaIcons.PUBLISH_INCL_SUB, null);
122 contextMenu.addItem("Move folder", MagnoliaIcons.MOVE, null);
123
124 setContent(layout);
125 }
126
127 public void updateList() {
128
129
130 List<Customer> customers = service.findAll();
131 listSelect.setItems(customers);
132 }
133
134 @Override
135 public boolean equals(Object obj) {
136 return super.equals(obj);
137 }
138
139 @Override
140 public int hashCode() {
141 return super.hashCode();
142 }
143 }