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.common.pagelinks.api;
20
21 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
22 import com.vaadin.ui.Button.ClickEvent;
23 import com.vaadin.ui.Button.ClickListener;
24 import com.vaadin.ui.MenuBar.Command;
25 import com.vaadin.ui.MenuBar.MenuItem;
26 import com.vaadin.ui.UI;
27
28
29
30
31 public final class PageModeMenuCommand implements Command, ClickListener {
32
33
34 private static final Character PAGE_SEPARATOR = '/';
35
36
37 private static final long serialVersionUID = 1L;
38
39
40 private final String pageReference;
41
42
43 private final String page;
44
45
46
47
48
49
50
51
52
53
54 public PageModeMenuCommand(final String page, final PageMode pageMode) {
55 super();
56 this.page = page;
57 pageReference = pageMode.toString();
58 }
59
60
61
62
63
64
65
66
67
68 public PageModeMenuCommand(final String page, final String part) {
69 super();
70 this.page = page;
71 pageReference = part;
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 public PageModeMenuCommand(final String page, final PageMode pageMode,final String part) {
86 super();
87 this.page = page;
88 pageReference = new StringBuilder().append(pageMode).append(PAGE_SEPARATOR).append(part).toString();
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103 public PageModeMenuCommand(final String page, final String pageMode, final String part) {
104 this.page = page;
105 pageReference = pageMode + PAGE_SEPARATOR + part;
106 }
107
108
109
110
111
112
113 public String getPagePath() {
114 if (pageReference != null && !pageReference.isEmpty()) {
115 return page + PAGE_SEPARATOR + pageReference;
116 } else {
117 return page;
118 }
119 }
120
121 @Override
122 public void menuSelected(final MenuItem selectedItem) {
123 UI.getCurrent().getNavigator().navigateTo(page + PAGE_SEPARATOR + pageReference);
124 }
125
126 @Override
127 public void buttonClick(final ClickEvent event) {
128 UI.getCurrent().getNavigator().navigateTo(page + PAGE_SEPARATOR + pageReference);
129 }
130
131 }