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