1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.views.admin.system.pagemode;
20
21 import com.hack23.cia.web.impl.ui.application.views.common.pagemode.AbstractPageModContentFactoryImpl;
22 import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
23 import com.vaadin.ui.AbstractOrderedLayout;
24 import com.vaadin.ui.HorizontalLayout;
25 import com.vaadin.ui.Label;
26 import com.vaadin.ui.Link;
27
28
29
30
31 abstract class AbstractAdminSystemPageModContentFactoryImpl extends AbstractPageModContentFactoryImpl {
32
33
34 private static final int LIMIT_FOR_DISPLAYING_START_END_LINKS = 5;
35
36
37 private static final int PAGE_ONE = 1;
38
39
40 private static final char PAGE_SEPARATOR = '/';
41
42
43 private static final String SHOW = " :: Show ";
44
45
46 private static final String RESULTS_PER_PAGE = " results per page:";
47
48
49 private static final String PAGES_TOTAL_RESULTS = " pages. Total results:";
50
51
52 private static final String PAGE_HEADER = "Page: ";
53
54
55 private static final String NEXT_PAGE = "next page";
56
57
58 private static final String FIRST_PAGE = "first page";
59
60
61 private static final String LAST_PAGE = "last page";
62
63
64 private static final String PREVIOUS_PAGE = "previous page";
65
66
67 public static final int DEFAULT_RESULTS_PER_PAGE=250;
68
69
70
71
72 AbstractAdminSystemPageModContentFactoryImpl() {
73 super();
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 protected final void createPagingControls(final AbstractOrderedLayout content,final String name,final String pageId, final Long size, final int pageNr, final int resultPerPage) {
93 final HorizontalLayout pagingControls = new HorizontalLayout();
94 pagingControls.setSpacing(true);
95 pagingControls.setMargin(true);
96
97 final int maxPages = (int) ((size +(resultPerPage-1)) / resultPerPage);
98
99 final StringBuilder stringBuilder = new StringBuilder();
100 stringBuilder.append(PAGE_HEADER)
101 .append(pageNr)
102 .append(PAGE_SEPARATOR)
103 .append(maxPages)
104 .append(PAGES_TOTAL_RESULTS)
105 .append(size)
106 .append(RESULTS_PER_PAGE)
107 .append(resultPerPage)
108 .append(SHOW);
109 final Label pageInfo = new Label(stringBuilder.toString());
110 pagingControls.addComponent(pageInfo);
111 pagingControls.setExpandRatio(pageInfo, ContentRatio.SMALL);
112
113
114 if (pageNr > PAGE_ONE) {
115 addPagingLink(PREVIOUS_PAGE,name, pageId, pageNr -1,pagingControls);
116 }
117
118 if (maxPages > PAGE_ONE && pageNr < maxPages) {
119 addPagingLink(NEXT_PAGE,name, pageId, pageNr +1,pagingControls);
120 }
121
122 if (maxPages > LIMIT_FOR_DISPLAYING_START_END_LINKS && pageNr > PAGE_ONE) {
123 addPagingLink(FIRST_PAGE,name, pageId, 1,pagingControls);
124 }
125
126 if (maxPages > LIMIT_FOR_DISPLAYING_START_END_LINKS && pageNr < maxPages) {
127 addPagingLink(LAST_PAGE,name, pageId, maxPages,pagingControls);
128 }
129
130 content.addComponent(pagingControls);
131 content.setExpandRatio(pagingControls, ContentRatio.SMALL2);
132
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 private void addPagingLink(final String label,final String name, final String pageId, final int pageNr, final HorizontalLayout pagingControls) {
151 final Link previousPageLink = getPageLinkFactory().createAdminPagingLink(label,name, pageId, String.valueOf(pageNr));
152 pagingControls.addComponent(previousPageLink);
153 pagingControls.setExpandRatio(previousPageLink, ContentRatio.SMALL);
154 }
155
156 }