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.ui.contentapp.browser;
35
36 import info.magnolia.ui.actionbar.ActionbarView;
37 import info.magnolia.ui.api.view.View;
38 import info.magnolia.ui.vaadin.actionbar.ActionPopup;
39 import info.magnolia.ui.workbench.WorkbenchView;
40
41 import com.vaadin.contextmenu.MenuItem;
42 import com.vaadin.server.Resource;
43 import com.vaadin.ui.Component;
44 import com.vaadin.ui.CssLayout;
45 import com.vaadin.ui.HorizontalLayout;
46 import com.vaadin.ui.VerticalLayout;
47
48
49
50
51 public class BrowserViewImpl extends VerticalLayout implements BrowserView {
52
53 private ActionbarView actionBar;
54
55 private ActionPopup actionPopup;
56
57 private final CssLayout actionBarWrapper = new CssLayout();
58
59 private final HorizontalLayout workbenchWapper = new HorizontalLayout();
60
61 private WorkbenchView workbench;
62
63 private BrowserView.Listener listener;
64
65 public BrowserViewImpl() {
66 setSizeFull();
67 setMargin(false);
68 setSpacing(false);
69 addStyleName("browser");
70
71 workbenchWapper.setSizeFull();
72 workbenchWapper.setMargin(false);
73 workbenchWapper.setSpacing(true);
74
75 actionBarWrapper.setHeight(100, Unit.PERCENTAGE);
76 actionBarWrapper.addStyleName("actionbar");
77 workbenchWapper.addComponent(actionBarWrapper);
78 workbenchWapper.setExpandRatio(actionBarWrapper, 0);
79
80 addComponent(workbenchWapper);
81 setExpandRatio(workbenchWapper, 1);
82 createActionPopup();
83
84 }
85
86 @Override
87 public void setActionbarView(final ActionbarView actionBar) {
88 Component c = actionBar.asVaadinComponent();
89 Component old = actionBarWrapper.getComponentCount() != 0 ? actionBarWrapper.getComponent(0) : null;
90 if (old == null) {
91 actionBarWrapper.addComponent(c);
92 } else {
93 actionBarWrapper.replaceComponent(old, c);
94 }
95 this.actionBar = actionBar;
96 }
97
98 @Override
99 public Component asVaadinComponent() {
100 return this;
101 }
102
103 @Override
104 public void setListener(BrowserView.Listener listener) {
105 this.listener = listener;
106 }
107
108 @Override
109 public void setWorkbenchView(WorkbenchView workbench) {
110 if (this.workbench == null) {
111 workbenchWapper.addComponent(workbench.asVaadinComponent(), 0);
112 } else {
113 workbenchWapper.replaceComponent(this.workbench.asVaadinComponent(), workbench.asVaadinComponent());
114 }
115 workbenchWapper.setExpandRatio(workbench.asVaadinComponent(), 1);
116
117 View statusBarView = workbench.getStatusBarView();
118 if (statusBarView != null) {
119 addComponent(statusBarView.asVaadinComponent());
120 setExpandRatio(statusBarView.asVaadinComponent(), 0);
121 }
122 this.workbench = workbench;
123 }
124
125
126
127
128 protected void createActionPopup() {
129 actionPopup = new ActionPopup(this, false);
130 actionPopup.setAsContextMenuOf(this);
131 }
132
133 @Override
134 public ActionPopup getActionPopup() {
135 return actionPopup;
136 }
137
138 @Override
139 public MenuItem addPopupItem(String label, Resource iconFontResource) {
140 return actionPopup.addItem(label, iconFontResource, item -> {});
141 }
142 }