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.admincentral;
35
36 import static info.magnolia.admincentral.ViewportLayout.VIEW.*;
37
38 import com.vaadin.ui.Component;
39 import com.vaadin.ui.CssLayout;
40 import com.vaadin.ui.Layout;
41 import com.vaadin.ui.Panel;
42 import com.vaadin.ui.VerticalLayout;
43
44 import lombok.Getter;
45
46
47
48
49 public class ViewportLayout extends CssLayout {
50
51 private static final String MOVE_DOWN = "viewportLayout-move-down";
52 private static final String MOVE_LEFT = "viewportLayout-move-left";
53
54 private static final String SLIDE_DOWN = "viewportLayout-slide-down";
55 private static final String SLIDE_UP = "viewportLayout-slide-up";
56 private static final String SLIDE_LEFT = "viewportLayout-slide-left";
57 private static final String SLIDE_RIGHT = "viewportLayout-slide-right";
58
59 private VIEW activeView;
60
61 private final Component findBarAndAppLauncher;
62 private final CssLayout appView;
63
64 @Getter
65 private final VerticalLayout appLauncherLayout = new VerticalLayout();
66
67 @Getter
68 private final Layout findBarResultsLayout = new CssLayout();
69 @Getter
70 private final Panel appLayout = new Panel();
71
72 public ViewportLayout() {
73
74 findBarResultsLayout.setWidth(100, Unit.PERCENTAGE);
75 findBarResultsLayout.addStyleName("findbar-results");
76
77 appLauncherLayout.addStyleName("v-app-launcher");
78 findBarAndAppLauncher = new CssLayout(findBarResultsLayout, appLauncherLayout);
79 findBarAndAppLauncher.setWidth(100, Unit.PERCENTAGE);
80 findBarAndAppLauncher.addStyleName("findbarAndApplauncher");
81
82 appLayout.setSizeFull();
83 appLayout.addStyleName("apps-viewport");
84 CssLayout appOverlay = new CssLayout();
85 appOverlay.addStyleName("app-overlay");
86 appOverlay.setSizeFull();
87 appOverlay.addLayoutClickListener(event -> {
88 if (appLayout.getContent() != null) {
89 updateView(APP_LAUNCHER, APP);
90 }
91 });
92 appView = new CssLayout(appLayout, appOverlay) {
93 @Override
94 protected String getCss(Component c) {
95 return "z-index: " + (c == appLayout && (activeView == APP || appLayout.getContent() == null) ? 2 : 1);
96 }
97 };
98 appView.addStyleNames("apps-viewport");
99
100
101 addComponents(findBarAndAppLauncher, appView);
102 addStyleName("viewportLayout");
103 setSizeFull();
104
105 updateView(null, FIND_BAR);
106 }
107
108 public void toggleAppLauncher() {
109 if (activeView == APP_LAUNCHER) {
110 if (appLayout.getContent() != null) {
111 updateView(activeView, APP);
112 }
113 } else {
114 updateView(activeView, APP_LAUNCHER);
115 }
116 }
117
118 public void toggleFindBar() {
119 if (activeView == FIND_BAR) {
120 if (appLayout.getContent() != null) {
121 updateView(activeView, APP);
122 }
123 } else {
124 showFindBar();
125 }
126 }
127
128 public void showFindBar() {
129 if (activeView != FIND_BAR) {
130 updateView(activeView, FIND_BAR);
131 }
132 }
133
134 public void showApp() {
135 if (activeView != APP) {
136 updateView(activeView, APP);
137 }
138 }
139
140 public void hideApp() {
141 updateView(APP, findBarAndAppLauncher.getStyleName().contains(MOVE_LEFT) ? APP_LAUNCHER : FIND_BAR);
142 }
143
144 private void updateView(VIEW from, VIEW to) {
145 disableAnimations();
146
147 if (from == APP_LAUNCHER) {
148 if (to == APP) {
149 appView.removeStyleName(MOVE_DOWN);
150 appView.addStyleName(SLIDE_UP);
151 } else if (to == FIND_BAR) {
152 findBarAndAppLauncher.removeStyleName(MOVE_LEFT);
153 findBarAndAppLauncher.addStyleName(SLIDE_RIGHT);
154 }
155 } else if (from == APP) {
156 if (to == APP_LAUNCHER) {
157 findBarAndAppLauncher.addStyleName(MOVE_LEFT);
158 } else if (to == FIND_BAR) {
159 findBarAndAppLauncher.removeStyleNames(MOVE_LEFT);
160 }
161 appView.addStyleName(SLIDE_DOWN);
162 appView.addStyleName(MOVE_DOWN);
163 } else if (from == FIND_BAR) {
164 if (to == APP) {
165 appView.removeStyleName(MOVE_DOWN);
166 appView.addStyleName(SLIDE_UP);
167 } else if (to == APP_LAUNCHER) {
168 findBarAndAppLauncher.addStyleName(SLIDE_LEFT);
169 findBarAndAppLauncher.addStyleName(MOVE_LEFT);
170 }
171 } else {
172 appView.addStyleName(SLIDE_DOWN);
173 appView.addStyleName(MOVE_DOWN);
174 }
175 activeView = to;
176 }
177
178 public void disableAnimations() {
179 findBarAndAppLauncher.removeStyleNames(SLIDE_LEFT, SLIDE_RIGHT);
180 appView.removeStyleNames(SLIDE_DOWN, SLIDE_UP);
181 }
182
183 public VIEW getActiveView() {
184 return activeView;
185 }
186
187
188
189
190 public enum VIEW {
191 APP, FIND_BAR, APP_LAUNCHER
192 }
193 }